Skip to content

TimescaleDB: load straight into the columnstore with direct compress, on by default - #303

Closed
philkra wants to merge 1 commit into
timescaledb-columnstorefrom
timescaledb-direct-compress
Closed

philkra wants to merge 1 commit into
timescaledb-columnstorefrom
timescaledb-direct-compress

Conversation

@philkra

@philkra philkra commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Stacked on #298: the diff here is only the change on top of it, and it should merge after #298. It replaces #298's post-load conversion with direct compress, so the columnstore is the default layout for the TimescaleDB target.

What changes

One CREATE TABLE per hypertable. Tables are created with CREATE TABLE ... WITH (tsdb.hypertable, tsdb.partition_column = 'time', tsdb.chunk_interval, tsdb.create_default_indexes = false, ...) instead of create_hypertable.

Direct compress instead of a post-load conversion. With the columnstore on, the table also gets tsdb.segmentby, tsdb.orderby and tsdb.direct_compress, so COPY and INSERT write compressed batches during the timed load. Nothing runs after the load, so the DBCreatorPostLoad hook from #298 is removed and load/ and pkg/targets/creator.go are back to what's on master.

Defaults

flag default
--use-columnstore true turns the columnstore on; ignored with --use-hypertable=false
--columnstore-direct-compress true (new) write compressed batches during the load; needs TimescaleDB >= 2.29
--columnstore-segmentby tags_id
--columnstore-orderby time DESC
--columnstore-sparse-index empty (new) tsdb.sparse_index; empty lets TimescaleDB choose

Other changes:

  • Rowstore hypertables (--use-columnstore=false) pass tsdb.columnstore = false, because CREATE TABLE ... WITH turns the columnstore on by default.
  • --columnstore-direct-compress=false enables the columnstore but leaves chunks uncompressed until TimescaleDB's columnstore policy converts them.
  • --partitions uses add_dimension(by_hash(...)).
  • --replication-factor >= 1 fails before loading, because multi-node was removed in 2.14.
  • The TimescaleDB version is checked before any table is created: 2.29 for direct compress, 2.20 otherwise. The error says which flag to turn off.
  • scripts/load/load_timescaledb.sh gains USE_COLUMNSTORE and COLUMNSTORE_DIRECT_COMPRESS env vars.

Behaviour change

  • A default run now needs TimescaleDB >= 2.29. On older versions, pass --columnstore-direct-compress=false (needs 2.20+) or --use-columnstore=false. Master doesn't load on 2.14 or later at all.
  • Default results are not comparable with earlier TSBS TimescaleDB numbers, because the default layout is now compressed.
  • Config files without the new keys get the new defaults.

Benchmark

cpu-only, scale 200, 3 days (5.18M rows), 8 load workers, default batch size of 10,000. Each config ran twice; the table shows the better pass. VACUUM ANALYZE and CHECKPOINT ran after each load. Each query type is 100 queries on 4 workers, median latency. Local Docker on an 11-core Mac, TimescaleDB 2.32.0 / PG 17.11. Master fails on 2.32, so it ran on 2.13.1 / PG 16.1 ¹.

master · rowstore ¹ #298 · rowstore #298 · columnstore this PR · rowstore this PR · default this PR · + firstlast ²
ingest, timed 8.6 s 7.9 s 13.1 s 8.0 s 6.0 s 6.6 s
ingest incl. conversion 8.8 s 8.1 s 18.0 s 8.2 s 6.3 s 6.7 s
size 1025 MB 1038 MB 47 MB 1030 MB 150 MB 178 MB
cpu-max-all-8 22.1 ms 22.0 7.0 24.0 5.9 6.1
double-groupby-5 142.1 149.4 95.7 143.8 84.6 86.3
groupby-orderby-limit 1.2 2.4 6.2 1.3 17.8 19.2
high-cpu-1 5.1 6.1 1.6 4.9 1.5 1.4
high-cpu-all 90.9 91.8 59.9 92.5 57.8 64.9
lastpoint 1.2 1.3 3.8 1.3 4.8 1.3
single-groupby-1-1-1 1.2 1.2 0.8 1.3 0.8 0.9
single-groupby-5-1-12 6.1 5.9 2.0 5.9 2.2 2.3
single-groupby-5-8-1 2.9 2.8 33.1 2.8 1.3 1.4

¹ TimescaleDB 2.13.1 / PG 16.1. ² --columnstore-sparse-index with firstlast on time, all 10 metrics and additional_tags.

The two passes differed by up to 25%, so treat differences under about 20% as noise.

  • Ingest: direct compress is the fastest config, about 2.9× faster end to end than converting after the load.
  • Queries: most query types are 1.5–3.5× faster than the rowstore.
  • Storage: 150 MB here against 47 MB for the post-load conversion. Direct compress builds batches from each COPY: a 10,000-row batch over 200 hosts gives about 50 rows per segment. --batch-size=200000 brought it to 57 MB in a separate run, at slower ingest (18 s). The compaction policy TimescaleDB creates didn't merge the small batches.
  • groupby-orderby-limit is slower on the columnstore: the newest rows have to be found across 200 segments.
  • Sparse indexes: firstlast on every column brings lastpoint back to rowstore speed by answering from batch metadata (Metadata Only: true), for about 19% more storage. minmax(usage_user) prunes 87% of batches in high-cpu-all but only gains about 10%. Without a segmentby, bloom(tags_id) can't replace it, because every batch contains all hosts.

Notes for reviewers

  • The TimescaleDB docs call direct compress a tech preview.
  • The docs say firstlast sparse indexes aren't configurable, but 2.32 accepts them on any column.
  • go test for pkg/targets/timescaledb doesn't build under Go 1.26 because of an existing vet error at file_data_source.go:60, which is also on master. The tests pass with -vet=off.

Testing

  • Unit tests cover the generated CREATE TABLE for each mode, the flag defaults (read through viper as tsbs_load does), validation and the version requirement.
  • End to end against TimescaleDB 2.32:
    • the default loads into compressed chunks with segmentby tags_id
    • --columnstore-direct-compress=false leaves chunks uncompressed under a columnstore policy
    • --use-columnstore=false gives a rowstore hypertable
    • --use-hypertable=false gives a plain table
    • --partitions creates two dimensions
    • --columnstore-sparse-index is applied
    • iot gets both hypertables compressed
    • --replication-factor=1 fails early
    • tsbs_load load timescaledb with an unmodified sample config gets the new defaults
  • Against 2.13.1, both version errors show up as expected.

🤖 Generated with Claude Code

Create each hypertable with a single CREATE TABLE ... WITH (tsdb.hypertable,
...) statement and, by default, enable the columnstore with
tsdb.direct_compress, so COPY and INSERT write compressed batches during the
timed load. This replaces the post-load conversion, so the DBCreatorPostLoad
hook and the loader changes that called it are removed again.

- --use-columnstore now defaults to true; it is ignored for plain tables
  (--use-hypertable=false) instead of being an error
- new --columnstore-direct-compress (default true, needs TimescaleDB >= 2.29);
  with false, chunks are left to the columnstore policy
- new --columnstore-sparse-index to set tsdb.sparse_index
- rowstore hypertables pass tsdb.columnstore = false, since CREATE TABLE ...
  WITH enables the columnstore by default
- --partitions uses add_dimension(by_hash(...))
- --replication-factor >= 1 fails early: multi-node was removed in 2.14
- the TimescaleDB version is checked before any table is created

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@philkra
philkra changed the base branch from master to timescaledb-columnstore November 12, 2026 16:15
@philkra

philkra commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Discussed internally that the approach does not suit the broader set of scenarios we want to cover

@philkra philkra closed this Nov 13, 2026
@philkra
philkra deleted the timescaledb-direct-compress branch November 13, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant