timescale / timescaledb

An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.
https://www.timescale.com/
Other
16.83k stars 852 forks source link

[Bug]: segfault when configuring orderby on hypertable with closed primary dimension #6983

Closed JamesGuthrie closed 1 month ago

JamesGuthrie commented 1 month ago

What type of bug is this?

Crash

What subsystems and features are affected?

Compression

What happened?

segfault when configuring orderby on hypertable with closed primary dimension

TimescaleDB version affected

2.15.1

PostgreSQL version used

16.3

What operating system did you use?

Docker for Mac

What installation method did you use?

Docker

What platform did you run on?

Other

Relevant log output and stack trace

#0  add_time_to_order_by_if_not_included (obs=..., segmentby=0x0, ht=ht@entry=0xaaaae507ec08)
    at /build/timescaledb/tsl/src/compression/create.c:490
#1  0x0000ffff26b7ce94 in compression_settings_update (with_clause_options=0xaaaae5029840, settings=0xaaaae50f22e0, ht=0xaaaae507ec08)
    at /build/timescaledb/tsl/src/compression/create.c:1158
#2  tsl_process_compress_table (cmd=<optimized out>, ht=0xaaaae507ec08, with_clause_options=0xaaaae5029840)
    at /build/timescaledb/tsl/src/compression/create.c:811
#3  0x0000ffff26ce0a40 in process_altertable_set_options (ht=0xaaaae5201ee8, cmd=<optimized out>) at /build/timescaledb/src/process_utility.c:4017
#4  process_altertable_start_table (args=0xffffd09f08a8) at /build/timescaledb/src/process_utility.c:3448
#5  process_altertable_start (args=0xffffd09f08a8) at /build/timescaledb/src/process_utility.c:3642
#6  0x0000ffff26cdc6ec in process_ddl_command_start (args=0xffffd09f08a8) at /build/timescaledb/src/process_utility.c:4232
#7  timescaledb_ddl_command_start (pstmt=0xaaaae50b47b0, query_string=<optimized out>, readonly_tree=<optimized out>,
    context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=<optimized out>, dest=0xaaaad63f1f88 <donothingDR.lto_priv.0>,
    completion_tag=0xffffd09f0d20) at /build/timescaledb/src/process_utility.c:4460
#8  0x0000aaaad5f5bd5c in ProcessUtility (qc=<optimized out>, dest=<optimized out>, queryEnv=<optimized out>, params=<optimized out>,
    context=PROCESS_UTILITY_TOPLEVEL, readOnlyTree=<optimized out>, queryString=<optimized out>, pstmt=<optimized out>)
    at tcop/./build/../src/backend/tcop/utility.c:526
#9  PortalRunUtility (portal=portal@entry=0xaaaae4dbd150, pstmt=pstmt@entry=0xaaaae50b47b0, isTopLevel=isTopLevel@entry=true,
    setHoldSnapshot=setHoldSnapshot@entry=false, dest=dest@entry=0xaaaad63f1f88 <donothingDR.lto_priv.0>, qc=qc@entry=0xffffd09f0d20)
    at tcop/./build/../src/backend/tcop/pquery.c:1158
#10 0x0000aaaad5f5bee8 in PortalRunMulti (portal=portal@entry=0xaaaae4dbd150, isTopLevel=isTopLevel@entry=true,
    setHoldSnapshot=setHoldSnapshot@entry=false, dest=0xaaaad63f1f88 <donothingDR.lto_priv.0>, dest@entry=0xaaaae4d35600,
    altdest=0xaaaad63f1f88 <donothingDR.lto_priv.0>, altdest@entry=0xaaaae4d35600, qc=qc@entry=0xffffd09f0d20)
    at tcop/./build/../src/backend/tcop/pquery.c:1315
#11 0x0000aaaad5f5c538 in PortalRun (portal=portal@entry=0xaaaae4dbd150, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true,
    run_once=<optimized out>, dest=dest@entry=0xaaaae4d35600, altdest=altdest@entry=0xaaaae4d35600, qc=qc@entry=0xffffd09f0d20)
    at tcop/./build/../src/backend/tcop/pquery.c:791
#12 0x0000aaaad5f5e414 in exec_execute_message (max_rows=9223372036854775807, portal_name=0xaaaae4d35170 "")
    at tcop/./build/../src/backend/tcop/postgres.c:2229
#13 PostgresMain (dbname=<optimized out>, username=<optimized out>) at tcop/./build/../src/backend/tcop/postgres.c:4721
#14 0x0000aaaad5ebf478 in BackendRun (port=0xaaaae4d6d200, port=0xaaaae4d6d200) at postmaster/./build/../src/backend/postmaster/postmaster.c:4464
#15 BackendStartup (port=0xaaaae4d6d200) at postmaster/./build/../src/backend/postmaster/postmaster.c:4192
#16 ServerLoop () at postmaster/./build/../src/backend/postmaster/postmaster.c:1782
#17 0x0000aaaad5eb52d8 in PostmasterMain (argc=<optimized out>, argv=<optimized out>)
    at postmaster/./build/../src/backend/postmaster/postmaster.c:1466
#18 0x0000aaaad5b5d6d8 in main (argc=1, argv=0xaaaae4c9bba0) at main/./build/../src/backend/main/main.c:198

How can we reproduce the bug?

CREATE TABLE test_hash_order_by(id bigint, value float8);
SELECT create_hypertable('test_hash_order_by', by_hash('id', 8));
ALTER TABLE test_hash_order_by SET (timescaledb.compress = true, timescaledb.compress_orderby = 'value');