diff --git a/.unreleased/pr_7080 b/.unreleased/pr_7080 new file mode 100644 index 00000000000..40ed3e0b7e6 --- /dev/null +++ b/.unreleased/pr_7080 @@ -0,0 +1 @@ +Fixes: #7080 Fix `corresponding equivalence member not found` error diff --git a/tsl/src/nodes/decompress_chunk/decompress_chunk.c b/tsl/src/nodes/decompress_chunk/decompress_chunk.c index 4edda1e0dfe..0ae2f2948af 100644 --- a/tsl/src/nodes/decompress_chunk/decompress_chunk.c +++ b/tsl/src/nodes/decompress_chunk/decompress_chunk.c @@ -170,11 +170,8 @@ build_compressed_scan_pathkeys(SortInfo *sort_info, PlannerInfo *root, List *chu * seen from the start, so that we arrive at the proper counts of seen * segmentby columns in the end. */ - Bitmapset *segmentby_columns = bms_copy(info->chunk_const_segmentby); ListCell *lc; - for (lc = list_head(chunk_pathkeys); - lc != NULL && bms_num_members(segmentby_columns) < info->num_segmentby_columns; - lc = lnext(chunk_pathkeys, lc)) + for (lc = list_head(chunk_pathkeys); lc; lc = lnext(chunk_pathkeys, lc)) { PathKey *pk = lfirst(lc); EquivalenceMember *compressed_em = NULL; @@ -195,21 +192,11 @@ build_compressed_scan_pathkeys(SortInfo *sort_info, PlannerInfo *root, List *chu * already refers a compressed column, it is a bug. See * build_sortinfo(). */ - Ensure(compressed_em, "corresponding equivalence member not found"); + if (!compressed_em) + break; required_compressed_pathkeys = lappend(required_compressed_pathkeys, pk); - - segmentby_columns = - bms_add_member(segmentby_columns, castNode(Var, compressed_em->em_expr)->varattno); } - - /* - * Either we sort by all segmentby columns, or by subset of them and - * nothing else. We verified this condition in build_sortinfo(), so only - * asserting here. - */ - Assert(bms_num_members(segmentby_columns) == info->num_segmentby_columns || - list_length(required_compressed_pathkeys) == list_length(chunk_pathkeys)); } /* diff --git a/tsl/test/expected/transparent_decompression-14.out b/tsl/test/expected/transparent_decompression-14.out index 78e1a02b51f..fb82ee68884 100644 --- a/tsl/test/expected/transparent_decompression-14.out +++ b/tsl/test/expected/transparent_decompression-14.out @@ -9594,3 +9594,31 @@ SELECT count(*) from motion_table; (1 row) --END of test for page settings +CREATE TABLE repro(time timestamptz NOT NULL, device_id text, room_id text NOT NULL, score_type int NOT NULL, algorithm_version text NOT NULL, adjusted_score float NOT NULL); +SELECT create_hypertable('repro','time'); + create_hypertable +--------------------- + (17,public,repro,t) +(1 row) + +ALTER TABLE repro SET ( + timescaledb.compress, + timescaledb.compress_segmentby = 'device_id, room_id, score_type, algorithm_version', + timescaledb.compress_orderby='"time" DESC' +); +SELECT _timescaledb_functions.create_chunk('repro','{"time": [1717632000000000,1718236800000000]}'); + create_chunk +------------------------------------------------------------------------------------------------------------- + (1441,17,_timescaledb_internal,_hyper_17_1441_chunk,r,"{""time"": [1717632000000000, 1718236800000000]}",t) +(1 row) + +select compress_chunk(show_chunks('repro')); + compress_chunk +-------------------------------------------- + _timescaledb_internal._hyper_17_1441_chunk +(1 row) + +select from repro where room_id = 'foo' order by device_id, algorithm_version, score_type, time desc; +-- +(0 rows) + diff --git a/tsl/test/expected/transparent_decompression-15.out b/tsl/test/expected/transparent_decompression-15.out index 48ef73df8ec..1faf9a8e4ac 100644 --- a/tsl/test/expected/transparent_decompression-15.out +++ b/tsl/test/expected/transparent_decompression-15.out @@ -9595,3 +9595,31 @@ SELECT count(*) from motion_table; (1 row) --END of test for page settings +CREATE TABLE repro(time timestamptz NOT NULL, device_id text, room_id text NOT NULL, score_type int NOT NULL, algorithm_version text NOT NULL, adjusted_score float NOT NULL); +SELECT create_hypertable('repro','time'); + create_hypertable +--------------------- + (17,public,repro,t) +(1 row) + +ALTER TABLE repro SET ( + timescaledb.compress, + timescaledb.compress_segmentby = 'device_id, room_id, score_type, algorithm_version', + timescaledb.compress_orderby='"time" DESC' +); +SELECT _timescaledb_functions.create_chunk('repro','{"time": [1717632000000000,1718236800000000]}'); + create_chunk +------------------------------------------------------------------------------------------------------------- + (1441,17,_timescaledb_internal,_hyper_17_1441_chunk,r,"{""time"": [1717632000000000, 1718236800000000]}",t) +(1 row) + +select compress_chunk(show_chunks('repro')); + compress_chunk +-------------------------------------------- + _timescaledb_internal._hyper_17_1441_chunk +(1 row) + +select from repro where room_id = 'foo' order by device_id, algorithm_version, score_type, time desc; +-- +(0 rows) + diff --git a/tsl/test/expected/transparent_decompression-16.out b/tsl/test/expected/transparent_decompression-16.out index d6d583e1634..43ff472fca1 100644 --- a/tsl/test/expected/transparent_decompression-16.out +++ b/tsl/test/expected/transparent_decompression-16.out @@ -9595,3 +9595,31 @@ SELECT count(*) from motion_table; (1 row) --END of test for page settings +CREATE TABLE repro(time timestamptz NOT NULL, device_id text, room_id text NOT NULL, score_type int NOT NULL, algorithm_version text NOT NULL, adjusted_score float NOT NULL); +SELECT create_hypertable('repro','time'); + create_hypertable +--------------------- + (17,public,repro,t) +(1 row) + +ALTER TABLE repro SET ( + timescaledb.compress, + timescaledb.compress_segmentby = 'device_id, room_id, score_type, algorithm_version', + timescaledb.compress_orderby='"time" DESC' +); +SELECT _timescaledb_functions.create_chunk('repro','{"time": [1717632000000000,1718236800000000]}'); + create_chunk +------------------------------------------------------------------------------------------------------------- + (1441,17,_timescaledb_internal,_hyper_17_1441_chunk,r,"{""time"": [1717632000000000, 1718236800000000]}",t) +(1 row) + +select compress_chunk(show_chunks('repro')); + compress_chunk +-------------------------------------------- + _timescaledb_internal._hyper_17_1441_chunk +(1 row) + +select from repro where room_id = 'foo' order by device_id, algorithm_version, score_type, time desc; +-- +(0 rows) + diff --git a/tsl/test/sql/transparent_decompression.sql.in b/tsl/test/sql/transparent_decompression.sql.in index 78200a4fd9c..c93378cc9fd 100644 --- a/tsl/test/sql/transparent_decompression.sql.in +++ b/tsl/test/sql/transparent_decompression.sql.in @@ -310,3 +310,19 @@ FROM ( SELECT chunk_schema || '.' || chunk_name as chunk_table SELECT count(*) from motion_table; --END of test for page settings + + +CREATE TABLE repro(time timestamptz NOT NULL, device_id text, room_id text NOT NULL, score_type int NOT NULL, algorithm_version text NOT NULL, adjusted_score float NOT NULL); +SELECT create_hypertable('repro','time'); + +ALTER TABLE repro SET ( + timescaledb.compress, + timescaledb.compress_segmentby = 'device_id, room_id, score_type, algorithm_version', + timescaledb.compress_orderby='"time" DESC' +); + +SELECT _timescaledb_functions.create_chunk('repro','{"time": [1717632000000000,1718236800000000]}'); + +select compress_chunk(show_chunks('repro')); +select from repro where room_id = 'foo' order by device_id, algorithm_version, score_type, time desc; +