From e66a40038e3c84fb1a68da67ad71caf75c64a027 Mon Sep 17 00:00:00 2001 From: Bharathy Date: Sat, 2 Sep 2023 09:24:31 +0530 Subject: [PATCH] Fix server crash on UPDATE of compressed chunk UPDATE query with system attributes in WHERE clause causes server to crash. This patch fixes this issue by checking for system attributes and handle cases only for segmentby attributes in fill_predicate_context(). Fixes #6024 --- .unreleased/bugfix_6024 | 3 +++ tsl/src/compression/compression.c | 6 ++++++ .../expected/compression_update_delete.out | 21 +++++++++++++++++++ tsl/test/sql/compression_update_delete.sql | 11 ++++++++++ 4 files changed, 41 insertions(+) create mode 100644 .unreleased/bugfix_6024 diff --git a/.unreleased/bugfix_6024 b/.unreleased/bugfix_6024 new file mode 100644 index 000000000..f331b36a6 --- /dev/null +++ b/.unreleased/bugfix_6024 @@ -0,0 +1,3 @@ +Fixes: #6035 UPDATE on compressed chunk crashes server + +Thanks: @alexanderlaw for reporting this issue on server crash diff --git a/tsl/src/compression/compression.c b/tsl/src/compression/compression.c index e833ff4cc..6d6c0542d 100644 --- a/tsl/src/compression/compression.c +++ b/tsl/src/compression/compression.c @@ -2766,6 +2766,9 @@ fill_predicate_context(Chunk *ch, List *predicates, List **filters, List **index else continue; + /* ignore system-defined attributes */ + if (var->varattno <= 0) + continue; column_name = get_attname(ch->table_id, var->varattno, false); FormData_hypertable_compression *fd = ts_hypertable_compression_get_by_pkey(ch->fd.hypertable_id, column_name); @@ -2847,6 +2850,9 @@ fill_predicate_context(Chunk *ch, List *predicates, List **filters, List **index if (IsA(ntest->arg, Var)) { var = (Var *) ntest->arg; + /* ignore system-defined attributes */ + if (var->varattno <= 0) + continue; column_name = get_attname(ch->table_id, var->varattno, false); FormData_hypertable_compression *fd = ts_hypertable_compression_get_by_pkey(ch->fd.hypertable_id, column_name); diff --git a/tsl/test/expected/compression_update_delete.out b/tsl/test/expected/compression_update_delete.out index 997303f91..55c6553ba 100644 --- a/tsl/test/expected/compression_update_delete.out +++ b/tsl/test/expected/compression_update_delete.out @@ -2534,3 +2534,24 @@ LOG: statement: ROLLBACK; RESET client_min_messages; LOG: statement: RESET client_min_messages; DROP TABLE tab1; +--issue: #6024 +CREATE TABLE t(a integer, b integer); +SELECT create_hypertable('t', 'a', chunk_time_interval=> 10); +NOTICE: adding not-null constraint to column "a" + create_hypertable +------------------- + (3,public,t,t) +(1 row) + +INSERT INTO t values(1, 2); +ALTER TABLE t SET (timescaledb.compress); +SELECT compress_chunk(show_chunks('t')); + compress_chunk +---------------------------------------- + _timescaledb_internal._hyper_3_3_chunk +(1 row) + +-- should not crash +UPDATE t SET b = 2 WHERE tableoid = 0; +UPDATE t SET b = 2 WHERE tableoid is null; +DROP TABLE t; diff --git a/tsl/test/sql/compression_update_delete.sql b/tsl/test/sql/compression_update_delete.sql index 97398607c..2c037f209 100644 --- a/tsl/test/sql/compression_update_delete.sql +++ b/tsl/test/sql/compression_update_delete.sql @@ -1301,3 +1301,14 @@ ROLLBACK; RESET client_min_messages; DROP TABLE tab1; + +--issue: #6024 +CREATE TABLE t(a integer, b integer); +SELECT create_hypertable('t', 'a', chunk_time_interval=> 10); +INSERT INTO t values(1, 2); +ALTER TABLE t SET (timescaledb.compress); +SELECT compress_chunk(show_chunks('t')); +-- should not crash +UPDATE t SET b = 2 WHERE tableoid = 0; +UPDATE t SET b = 2 WHERE tableoid is null; +DROP TABLE t;