-
Notifications
You must be signed in to change notification settings - Fork 896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent range overlap for chunks using constraint #6828
base: main
Are you sure you want to change the base?
Conversation
@@ -126,6 +126,7 @@ CREATE TABLE _timescaledb_catalog.dimension_slice ( | |||
-- table constraints | |||
CONSTRAINT dimension_slice_pkey PRIMARY KEY (id), | |||
CONSTRAINT dimension_slice_dimension_id_range_start_range_end_key UNIQUE (dimension_id, range_start, range_end), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably, this unique constraint could be dropped, its index though is still useful, and the UNIQUE
isn't wrong, so we should just let it be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the unique is at least misleading so we should drop it, but we need to keep the index as that is used internally
sql/pre_install/tables.sql
Outdated
@@ -126,6 +126,7 @@ CREATE TABLE _timescaledb_catalog.dimension_slice ( | |||
-- table constraints | |||
CONSTRAINT dimension_slice_pkey PRIMARY KEY (id), | |||
CONSTRAINT dimension_slice_dimension_id_range_start_range_end_key UNIQUE (dimension_id, range_start, range_end), | |||
CONSTRAINT dimension_slice_dimension_id_exclude EXCLUDE USING gist(int4range(dimension_id, dimension_id, '[]') WITH =, int8range(range_start, range_end, '[)') WITH &&), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example usage here:
https://www.postgresql.org/docs/current/btree-gist.html#BTREE-GIST-EXAMPLE-USAGE
Using int4range(dimension_id, dimension_id, '[]')
to not create a dependency on the btree_gist
extension. This works just as well, with the downside of some more storage space required.
1c0f84e
to
415c14a
Compare
This exclusion constraint prevents a single (time) value to exist in multiple dimension slices. We use `int4range(dimension_id, dimension_id, '[]')` as opposed to a direct compariso of `dimension_id` to not create a depenbency on `btree_gist`.
415c14a
to
face45d
Compare
Unfortunately it will not work because we use low level functions to update catalog tables and we only check for nulls, so no other constraints will be enforced when updating tsdb catalog tables. |
ADD CONSTRAINT dimension_slice_dimension_id_exclude | ||
EXCLUDE USING gist( | ||
int4range(dimension_id, dimension_id, '[]') WITH =, | ||
int8range(range_start, range_end, '[]') WITH && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int8range(range_start, range_end, '[]') WITH && | |
int8range(range_start, range_end, '[)') WITH && |
range_end should be exclusive
@@ -126,6 +126,7 @@ CREATE TABLE _timescaledb_catalog.dimension_slice ( | |||
-- table constraints | |||
CONSTRAINT dimension_slice_pkey PRIMARY KEY (id), | |||
CONSTRAINT dimension_slice_dimension_id_range_start_range_end_key UNIQUE (dimension_id, range_start, range_end), | |||
CONSTRAINT dimension_slice_dimension_id_exclude EXCLUDE USING gist(int4range(dimension_id, dimension_id, '[]') WITH =, int8range(range_start, range_end, '[]') WITH &&), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONSTRAINT dimension_slice_dimension_id_exclude EXCLUDE USING gist(int4range(dimension_id, dimension_id, '[]') WITH =, int8range(range_start, range_end, '[]') WITH &&), | |
CONSTRAINT dimension_slice_dimension_id_exclude EXCLUDE USING gist(int4range(dimension_id, dimension_id, '[]') WITH =, int8range(range_start, range_end, '[)') WITH &&), |
range_end should be exclusive
Constraints enforced by indexes will work |
This exclusion constraint prevents a single (time) value to exist in multiple dimension slices.