#10414·timescaledb

[Bug]: Segfault on DELETE, SELECT, and INSERT ON CONFLICT against a columnstore chunk converted with `timescaledb.sparse_index = ''`

Author: abbudaoCreated Aug 6, 2026Updated Sep 29, 2026
Labelsbugv2.29.1

What type of bug is this?

Crash

What subsystems and features are affected?

Compression

What happened?

Setting timescaledb.sparse_index = '' on a hypertable and then converting a chunk to columnstore produces a chunk whose sparse index configuration contains a degenerate descriptor. Three kinds of statement against that chunk then crash the backend with SIGSEGV, taking the whole instance down:

  • DELETE/UPDATE with at least one equality predicate;
  • SELECT with equality predicates on two or more columns;
  • INSERT ... ON CONFLICT when the table has a unique index.

The crash affects 2.27.0 through 2.29.1 (bisected on official images, details below). The malformed configuration itself has been accepted and stored since the option was introduced in 2.22.0, so it can sit latent until an upgrade crosses 2.27.0.

The empty string is the documented way to disable sparse indexes, and both ALTER TABLE and convert_to_columnstore() accept it without error or warning. Statements outside the three classes above work normally — unqualified DELETE FROM t, SELECT with fewer than two equality predicates, plain INSERT — which makes the problem easy to miss until a routine query pattern hits it.

After conversion, timescaledb_information.chunk_columnstore_settings reports an entry with no type and no column:

json
[
  {"source": "config"},
  {"type": "minmax",    "column": "day", "source": "orderby"},
  {"type": "firstlast", "column": "day", "source": "orderby"}
]

Expected behaviour: with sparse_index = '', the chunk converts with no configured sparse indexes (keeping only those derived from orderby), and DML against it works normally.

Root cause analysis

I'm not familiar with the codebase and it's been a decade since I last coded C, so treat the code-path attribution as a hypothesis.

The crashes, the version boundary, and the DELETE backtrace are verified — I got them testing with live data — but the SELECT and upsert call sites are inferred from source. Line numbers refer to tag 2.29.1; the relevant code looks unchanged on current main.

The {"source": "config"} entry appears intentional: parse_sparse_index_config_list() (src/with_clause/alter_table_with_clause.c) explicitly emits [{"source":"config"}] for empty input, apparently as a sentinel distinguishing "user explicitly disabled sparse indexes" from "no configuration, derive defaults". The crash is in code that consumes it:

  1. ts_resolve_columns_to_attnos_from_parsed_settings() (src/ts_catalog/compression_settings.c) resolves each parsed object's column list to a Bitmapset. For the sentinel (no columns) the result is the empty set, which PostgreSQL represents as a NULL pointer, lappend()ed into the returned list.
  2. Every consumer skips the sentinel safely inside its loop (no "type" key → continue), but they all free the list with ts_bmslist_free(), implemented as list_free_deep() (src/bmslist_utils.c:100) — which calls pfree() on every element unconditionally → pfree(NULL) → SIGSEGV.

I found three call sites with this pattern, matching the three crashing statement classes:

Crash Call site (2.29.1) Evidence Introduced with
UPDATE/DELETE w/ equality predicate process_predicates(), tsl/src/compression/compression_dml.c:2437 backtrace #9399 (2.27.0)
INSERT ... ON CONFLICT w/ unique index init_upsert_bloom_state(), tsl/src/compression/compression_dml.c:315 source reading #9374 (2.27.0)
SELECT w/ ≥2 equality predicates pushdown_composite_blooms(), tsl/src/nodes/columnar_scan/qual_pushdown.c:1270,1358 source reading verified on 2.29.1; onset not bisected separately

A single-point fix would cover all three: make ts_bmslist_free() NULL-tolerant (NULL-safe bms_free() per element plus list_free(), instead of list_free_deep()), since PostgreSQL represents the empty Bitmapset as NULL. Whether that's the right layer — and whether the sentinel should be materialized into per-chunk settings and displayed by chunk_columnstore_settings at all — is a design call I can't make from outside.

tsl/test/sql/compress_sparse_config.sql already covers storing and compressing with the empty config; as far as I can tell, no test runs DML or equality-predicate SELECTs against such a chunk, which is where the crashes occur.

Affected versions (bisected on official images)

Method: every release tag from 2.21.4 to 2.29.1, on official timescale/timescaledb:<version>-pg17 images, fresh container per trial, two trials per version (all consistent), extversion verified inside each container.

Versions Outcome
2.21.4 sparse_index not recognised by ALTER TABLE (option added in 2.22.0; earlier releases not tested)
2.22.0 – 2.26.4 malformed {"source": "config"} entry stored; DELETE succeeds
2.27.0 – 2.29.1 malformed entry stored; DELETE segfaults

The boundary was re-confirmed on pg18 images (2.26.4 fine, 2.27.0 crashes), so the regression is on the TimescaleDB side. This is consistent with the DML bloom-filter pass (#9399) shipping in 2.27.0, which is where the backtrace lands. No version that recognises the option rejects the empty string, so the correct behaviour was never observed. The bisect classifies the DELETE path; the SELECT and upsert crashes were verified on 2.29.1 but not bisected separately (the upsert pass also shipped in 2.27.0 with #9374).

Severity note

The crash is reachable by any role able to ALTER a hypertable it owns, and once the malformed configuration exists, by any role with mere SELECT privilege, since the SELECT crash happens at planning time. It takes down the entire instance, not just the offending session. On CloudNativePG, which sets restart_after_crash = off, the postmaster shuts down completely and stays down until the operator restarts it; in our case crash recovery then replayed for 450 s on a 5 TB database.

Workaround

  • Avoid timescaledb.sparse_index = '' until fixed. There appears to be no other way to fully disable sparse indexes: RESET reverts to the derived defaults rather than clearing them, so a hypertable with a unique index will always receive PK-derived bloom filters.
  • GUCs are only a partial mitigation, because each crashing pass is guarded by a different one: timescaledb.enable_dml_bloom_filter = off disables the UPDATE/DELETE pass (verified on 2.29.1); timescaledb.enable_composite_bloom_indexes = off (or timescaledb.enable_sparse_index_bloom = off) appears to guard the SELECT pass, and timescaledb.enable_dml_decompression_tuple_filtering = off the upsert pass (both from source, not verified). Removing the malformed configuration is the only mitigation I'm confident is complete.
  • To repair an affected chunk just set a valid sparse_index and reconvert it:
sql
CALL convert_to_rowstore('<chunk>');
ALTER TABLE <hypertable> SET (timescaledb.sparse_index = '<valid spec>');
-- or: ALTER TABLE <hypertable> RESET (timescaledb.sparse_index);
CALL convert_to_columnstore('<chunk>');

TimescaleDB version affected

2.29.1

PostgreSQL version used

18.4 (Debian 18.4-1.pgdg13+1)

What operating system did you use?

Debian Trixie, x86_64

What installation method did you use?

Docker

What platform did you run on?

Amazon Web Services (AWS)

Relevant log output and stack trace

Production log, scrubbed (self-built image, PG 18.4, CloudNativePG):

client backend (PID 204) was terminated by signal 11: Segmentation fault
DETAIL:  Failed process was running: DELETE FROM public.scrubbed_table_name
         WHERE id = 1234 AND day = '2015-05-04';
LOG:  terminating any other active server processes
FATAL:  the database system is in recovery mode
LOG:  shutting down because "restart_after_crash" is off
LOG:  database system is shut down

Backtrace from a Debug build of tag 2.29.1 against PostgreSQL 17.10, gdb attached to the backend running the minimal repro below. PostgreSQL frames come from stripped PGDG binaries, so frame-1 has no symbol — from reading the source I believe it is list_free_deep, reached via ts_bmslist_free() at the frame-2 line. The register dump shows rdi = 0x0, i.e. pfree(NULL):

Program received signal SIGSEGV, Segmentation fault.
#0  pfree ()
#1  0x000055fdd2aaedb2 in ?? ()
#2  process_predicates (...) at tsl/src/compression/compression_dml.c:2437
#3  decompress_batches_for_update_delete (...) at tsl/src/compression/compression_dml.c:860
#4  decompress_chunk_plan_walker (...) at tsl/src/compression/compression_dml.c:1822
#5  decompress_target_segments (...) at tsl/src/compression/compression_dml.c:1712
#6  modify_hypertable_exec (...) at src/nodes/modify_hypertable.c:298
#7  standard_ExecutorRun ()

Full bt full output with locals and the register dump available on request, along with per-trial PostgreSQL logs and the container harness from the bisect.

How can we reproduce the bug?

Deterministic on every trial. A single date column and 10 rows suffice — no primary key, no unique index, no segmentby:

sql
CREATE TABLE t (day date NOT NULL);
SELECT create_hypertable('t', 'day', chunk_time_interval => interval '30 days');
INSERT INTO t SELECT '2025-01-01'::date + i FROM generate_series(0, 9) i;
 
ALTER TABLE t SET (
    timescaledb.enable_columnstore,
    timescaledb.orderby      = 'day DESC',  -- required: sparse_index cannot be set without orderby
    timescaledb.sparse_index = ''           -- accepted without error
);
 
SELECT show_chunks('t') AS c LIMIT 1 \gset
CALL convert_to_columnstore(:'c');
 
-- Malformed descriptor, first entry has no "type"/"column":
SELECT index FROM timescaledb_information.chunk_columnstore_settings;
 
-- Crashes the backend with SIGSEGV:
DELETE FROM t WHERE day = '2025-01-05';

Reproduction notes

  • This was minimized from a production-derived table (25 columns, 4-column PK, hash space dimension, 31 GB chunk); none of that shape is necessary. The two well-formed entries in the malformed config come from orderby, not from PK-derived defaults.
  • Each crashing pass has its own trigger. DELETE/UPDATE needs one equality predicate (unqualified DELETE FROM t completes normally). SELECT needs equality predicates on two or more columns: on an id int, day date variant (still no PK), SELECT * FROM t WHERE id = 1 AND day = '2025-01-05' segfaults at planning time. The upsert pass needs a unique index: with PRIMARY KEY (id, day), INSERT INTO t VALUES (1, '2025-01-05', 42) ON CONFLICT (id, day) DO NOTHING segfaults.
  • With sparse_index unset or RESET, the derived defaults are used and everything works. Explicit sparse_index = 'bloom(...)' also works. Only the empty string produces the degenerate entry.