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

Fix compressed DML with constraints of form value OP column #6869

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .unreleased/pr_6869
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes: #6869 Fix compressed DML with constraints of form value OP column
9 changes: 8 additions & 1 deletion tsl/src/compression/compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,7 @@
case T_OpExpr:
{
OpExpr *opexpr = (OpExpr *) node;
Oid opno = opexpr->opno;
RegProcedure opcode = opexpr->opfuncid;
Oid collation = opexpr->inputcollid;
Expr *leftop, *rightop;
Expand All @@ -2575,6 +2576,12 @@
{
var = (Var *) rightop;
arg_value = (Const *) leftop;
opno = get_commutator(opno);
if (!OidIsValid(opno))
continue;

Check warning on line 2581 in tsl/src/compression/compression.c

View check run for this annotation

Codecov / codecov/patch

tsl/src/compression/compression.c#L2581

Added line #L2581 was not covered by tests
opcode = get_opcode(opno);
if (!OidIsValid(opcode))
continue;

Check warning on line 2584 in tsl/src/compression/compression.c

View check run for this annotation

Codecov / codecov/patch

tsl/src/compression/compression.c#L2584

Added line #L2584 was not covered by tests
}
else
continue;
Expand All @@ -2584,7 +2591,7 @@
continue;
column_name = get_attname(ch->table_id, var->varattno, false);
TypeCacheEntry *tce = lookup_type_cache(var->vartype, TYPECACHE_BTREE_OPFAMILY);
int op_strategy = get_op_opfamily_strategy(opexpr->opno, tce->btree_opf);
int op_strategy = get_op_opfamily_strategy(opno, tce->btree_opf);
if (ts_array_is_member(settings->fd.segmentby, column_name))
{
switch (op_strategy)
Expand Down
103 changes: 103 additions & 0 deletions tsl/test/expected/compression_update_delete.out
Original file line number Diff line number Diff line change
Expand Up @@ -2944,3 +2944,106 @@ EXPLAIN (analyze, timing off, costs off, summary off) DELETE FROM test_meta_filt
Rows Removed by Filter: 10
(8 rows)

-- test commutator handling in compressed dml constraints
CREATE TABLE test_commutator(time timestamptz NOT NULL, device text);
SELECT table_name FROM create_hypertable('test_commutator', 'time');
table_name
-----------------
test_commutator
(1 row)

INSERT INTO test_commutator SELECT '2020-01-01', 'a';
INSERT INTO test_commutator SELECT '2020-01-01', 'b';
INSERT INTO test_commutator SELECT '2020-01-01', 'c';
ALTER TABLE test_commutator SET (timescaledb.compress, timescaledb.compress_segmentby='device');
NOTICE: default order by for hypertable "test_commutator" is set to ""time" DESC"
SELECT compress_chunk(show_chunks('test_commutator'));
compress_chunk
------------------------------------------
_timescaledb_internal._hyper_39_79_chunk
(1 row)

BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'a' = device; ROLLBACK;
QUERY PLAN
--------------------------------------------------------------------------------------
Custom Scan (HypertableModify) (actual rows=0 loops=1)
Batches decompressed: 1
Tuples decompressed: 1
-> Delete on test_commutator (actual rows=0 loops=1)
Delete on _hyper_39_79_chunk test_commutator_1
-> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=1 loops=1)
Filter: ('a'::text = device)
(7 rows)

BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE device < 'c' ; ROLLBACK;
QUERY PLAN
--------------------------------------------------------------------------------------
Custom Scan (HypertableModify) (actual rows=0 loops=1)
Batches decompressed: 2
Tuples decompressed: 2
-> Delete on test_commutator (actual rows=0 loops=1)
Delete on _hyper_39_79_chunk test_commutator_1
-> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=2 loops=1)
Filter: (device < 'c'::text)
(7 rows)

BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'c' > device; ROLLBACK;
QUERY PLAN
--------------------------------------------------------------------------------------
Custom Scan (HypertableModify) (actual rows=0 loops=1)
Batches decompressed: 2
Tuples decompressed: 2
-> Delete on test_commutator (actual rows=0 loops=1)
Delete on _hyper_39_79_chunk test_commutator_1
-> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=2 loops=1)
Filter: ('c'::text > device)
(7 rows)

BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'c' >= device; ROLLBACK;
QUERY PLAN
--------------------------------------------------------------------------------------
Custom Scan (HypertableModify) (actual rows=0 loops=1)
Batches decompressed: 3
Tuples decompressed: 3
-> Delete on test_commutator (actual rows=0 loops=1)
Delete on _hyper_39_79_chunk test_commutator_1
-> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=3 loops=1)
Filter: ('c'::text >= device)
(7 rows)

BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE device > 'b'; ROLLBACK;
QUERY PLAN
--------------------------------------------------------------------------------------
Custom Scan (HypertableModify) (actual rows=0 loops=1)
Batches decompressed: 1
Tuples decompressed: 1
-> Delete on test_commutator (actual rows=0 loops=1)
Delete on _hyper_39_79_chunk test_commutator_1
-> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=1 loops=1)
Filter: (device > 'b'::text)
(7 rows)

BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'b' < device; ROLLBACK;
QUERY PLAN
--------------------------------------------------------------------------------------
Custom Scan (HypertableModify) (actual rows=0 loops=1)
Batches decompressed: 1
Tuples decompressed: 1
-> Delete on test_commutator (actual rows=0 loops=1)
Delete on _hyper_39_79_chunk test_commutator_1
-> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=1 loops=1)
Filter: ('b'::text < device)
(7 rows)

BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'b' <= device; ROLLBACK;
QUERY PLAN
--------------------------------------------------------------------------------------
Custom Scan (HypertableModify) (actual rows=0 loops=1)
Batches decompressed: 2
Tuples decompressed: 2
-> Delete on test_commutator (actual rows=0 loops=1)
Delete on _hyper_39_79_chunk test_commutator_1
-> Seq Scan on _hyper_39_79_chunk test_commutator_1 (actual rows=2 loops=1)
Filter: ('b'::text <= device)
(7 rows)

18 changes: 18 additions & 0 deletions tsl/test/sql/compression_update_delete.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1493,3 +1493,21 @@ SELECT compress_chunk(show_chunks('test_meta_filters'));

EXPLAIN (analyze, timing off, costs off, summary off) DELETE FROM test_meta_filters WHERE device = 'd1' AND metric = 'm1' AND v1 < 100;

-- test commutator handling in compressed dml constraints
CREATE TABLE test_commutator(time timestamptz NOT NULL, device text);
SELECT table_name FROM create_hypertable('test_commutator', 'time');
INSERT INTO test_commutator SELECT '2020-01-01', 'a';
INSERT INTO test_commutator SELECT '2020-01-01', 'b';
INSERT INTO test_commutator SELECT '2020-01-01', 'c';

ALTER TABLE test_commutator SET (timescaledb.compress, timescaledb.compress_segmentby='device');
SELECT compress_chunk(show_chunks('test_commutator'));

BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'a' = device; ROLLBACK;
BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE device < 'c' ; ROLLBACK;
BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'c' > device; ROLLBACK;
BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'c' >= device; ROLLBACK;
BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE device > 'b'; ROLLBACK;
BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'b' < device; ROLLBACK;
BEGIN; EXPLAIN (costs off, timing off, summary off, analyze) DELETE FROM test_commutator WHERE 'b' <= device; ROLLBACK;