Skip to content
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

reorder_chunk does not do correct attribute mapping between chunk and hypertable #3651

Closed
svenklemm opened this issue Oct 5, 2021 · 0 comments · Fixed by #3654
Closed

reorder_chunk does not do correct attribute mapping between chunk and hypertable #3651

svenklemm opened this issue Oct 5, 2021 · 0 comments · Fixed by #3654
Assignees

Comments

@svenklemm
Copy link
Member

Reorder fails to convert column references in the used index from the hypertable to the chunk attributes leading to wrong results or spurious errors when the index references columns with different attnum between chunk and hypertable.

To reproduce:

dev=# create table o(c1 timestamptz,c2 text, c3 text);
CREATE TABLE
Time: 17.549 ms
dev=# select create_hypertable('o','c1');
NOTICE:  00000: adding not-null constraint to column "c1"
DETAIL:  Time dimensions cannot have NULL values.
LOCATION:  dimension_add_not_null_on_column, dimension.c:1055
 create_hypertable
-------------------
 (7,public,o,t)
(1 row)
Time: 31.077 ms
dev=# alter table o drop column c2;
ALTER TABLE
Time: 19.402 ms
dev=# alter table o add column c4 text;
ALTER TABLE
Time: 7.055 ms
dev=# create unique index on o(c1,c4);
CREATE INDEX
Time: 18.790 ms
dev=# insert into o select '2000-01-01','foo','foo';
INSERT 0 1
Time: 53.000 ms
dev=# insert into o select '2000-01-01','foo','bar';
INSERT 0 1
Time: 8.321 ms

dev=# select reorder_chunk('_timescaledb_internal._hyper_7_2580_chunk','o_c1_c4_idx');
ERROR:  23505: could not create unique index "pg_temp_5257022__hyper_7_2580_chunk_o_c1_c4_idx"
DETAIL:  Key (c1, c3)=(2000-01-01 00:00:00+01, foo) is duplicated.
SCHEMA NAME:  _timescaledb_internal
TABLE NAME:  pg_temp_5257022
CONSTRAINT NAME:  pg_temp_5257022__hyper_7_2580_chunk_o_c1_c4_idx
LOCATION:  comparetup_index_btree, tuplesort.c:4219
Time: 38.982 ms
@svenklemm svenklemm self-assigned this Oct 5, 2021
@svenklemm svenklemm added 1.X bug and removed 1.X labels Oct 5, 2021
svenklemm added a commit to svenklemm/timescaledb that referenced this issue Oct 6, 2021
When we clone an index from a chunk we must not do attnum mapping if the
supplied index template is not on the hypertable. Ideally we would check
for the template being on the chunk but we cannot do that since when we
rebuild a chunk the new chunk has a different id.

Fixes timescale#3651
svenklemm added a commit to svenklemm/timescaledb that referenced this issue Oct 6, 2021
When we clone an index from a chunk we must not do attnum mapping if the
supplied index template is not on the hypertable. Ideally we would check
for the template being on the chunk but we cannot do that since when we
rebuild a chunk the new chunk has a different id.

Fixes timescale#3651
svenklemm added a commit to svenklemm/timescaledb that referenced this issue Oct 6, 2021
When we clone an index from a chunk we must not do attnum mapping if the
supplied index template is not on the hypertable. Ideally we would check
for the template being on the chunk but we cannot do that since when we
rebuild a chunk the new chunk has a different id.

Fixes timescale#3651
svenklemm added a commit that referenced this issue Oct 6, 2021
When we clone an index from a chunk we must not do attnum mapping if the
supplied index template is not on the hypertable. Ideally we would check
for the template being on the chunk but we cannot do that since when we
rebuild a chunk the new chunk has a different id.

Fixes #3651
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants