Skip to content

Instantly share code, notes, and snippets.

@bra-fsn

bra-fsn/crdb.sql Secret

Created January 16, 2020 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bra-fsn/a505149994cb13e868aadd28b9593741 to your computer and use it in GitHub Desktop.
Save bra-fsn/a505149994cb13e868aadd28b9593741 to your computer and use it in GitHub Desktop.
crdb excessive IO CTE
CREATE TABLE objects (
store INT8 NOT NULL,
id BYTES NOT NULL,
size INT8 NOT NULL,
flags VARBIT NULL,
atime INT8 NOT NULL DEFAULT CAST(now():::TIMESTAMPTZ AS INT8),
chunks JSONB NULL,
CONSTRAINT "primary" PRIMARY KEY (store ASC, id ASC),
INDEX ix_objects_atime (atime ASC),
INVERTED INDEX ix_objects_chunks (chunks),
FAMILY "primary" (store, id, size, flags, atime, chunks)
)
CREATE TABLE object_locations (
store INT8 NOT NULL,
id BYTES NOT NULL,
disk INT8 NOT NULL,
start INT8 NOT NULL,
"end" INT8 NOT NULL,
cksum BYTES NULL,
CONSTRAINT "primary" PRIMARY KEY (store ASC, id ASC, disk ASC),
CONSTRAINT fk_store_ref_objects FOREIGN KEY (store, id) REFERENCES objects(store, id) ON DELETE CASCADE,
INDEX ixold (disk ASC, "end" DESC),
FAMILY "primary" (store, id, disk, start, "end", cksum)
) INTERLEAVE IN PARENT objects (store, id)
CREATE TABLE bucket_objects (
store INT8 NOT NULL,
oid BYTES NOT NULL,
bucket INT8 NOT NULL,
id VARCHAR NOT NULL,
http_headers JSONB NULL,
ipacl JSONB NULL,
max_downloads INT8 NULL,
counter INT8 NOT NULL DEFAULT 0:::INT8,
atime INT8 NOT NULL DEFAULT CAST(now():::TIMESTAMPTZ AS INT8),
CONSTRAINT "primary" PRIMARY KEY (store ASC, oid ASC, bucket ASC, id ASC),
CONSTRAINT fk_store_ref_objects FOREIGN KEY (store, oid) REFERENCES objects(store, id),
UNIQUE INDEX ixnbi (bucket ASC, id ASC),
FAMILY "primary" (store, oid, bucket, id, http_headers, ipacl, max_downloads, counter, atime)
) INTERLEAVE IN PARENT objects (store, oid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment