From 6fc3a9bc84f9a4fac9beb5de3dd785d9496814b7 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 00000000000..f331b36a67d --- /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 e833ff4cc54..6d6c0542d51 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 997303f91ce..55c6553baad 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 97398607c86..2c037f209c2 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;