Skip to content

Skip columnar index scan when grouping by an expression - #9828

Merged
svenklemm merged 1 commit into
mainfrom
sven/cis_expr
May 18, 2026
Merged

Skip columnar index scan when grouping by an expression#9828
svenklemm merged 1 commit into
mainfrom
sven/cis_expr

Conversation

@svenklemm

@svenklemm svenklemm commented May 15, 2026

Copy link
Copy Markdown
Member

The rewrite that swaps ColumnarScan for ColumnarIndexScan only emits
bare metadata columns. When the group-by column reaches the aggregate
through a cast or other wrapper, the rewrite drops the wrapper, leaving
the aggregate's hash and equality functions bound to the wrapper's
type and the actual data of a different type. This produced a crash
for queries like GROUP BY (segmentby_col)::text on a compressed chunk.

Bail out of the rewrite when any group-by column is not a bare column
in the child output.

@svenklemm
svenklemm requested a review from a team May 15, 2026 20:12
@github-actions

Copy link
Copy Markdown

@antekresic, @natalya-aksman: please review this pull request.

Powered by pull-review

@svenklemm svenklemm changed the title sven/cis expr Skip columnar index scan when grouping by an expression May 15, 2026
@svenklemm svenklemm added this to the 2.27.1 milestone May 15, 2026
@svenklemm
svenklemm force-pushed the sven/cis_expr branch 2 times, most recently from cf0652a to f1cf2aa Compare May 15, 2026 20:14
@codecov

codecov Bot commented May 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@svenklemm
svenklemm force-pushed the sven/cis_expr branch 2 times, most recently from 368b086 to aa8e3b5 Compare May 15, 2026 20:28

/*
* Every group-by column must reach the Agg as a bare Var. A wrapper such
* as GROUP BY (col)::text would leave the Agg's grpOperators bound to the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the reason that we don't support this at plan time is that we don't support this at execution time? Some technicality with type mismatch in aggregation node would also break, but it's not the reason, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i think we can support this, but this can currently crash so for 2.27.1 its best to disable

The rewrite that swaps ColumnarScan for ColumnarIndexScan only emits
bare metadata columns. When the group-by column reaches the aggregate
through a cast or other wrapper, the rewrite drops the wrapper, leaving
the aggregate's hash and equality functions bound to the wrapper's
type and the actual data of a different type. This produced a crash
for queries like GROUP BY (segmentby_col)::text on a compressed chunk.

Bail out of the rewrite when any group-by column is not a bare column
in the child output.
@svenklemm
svenklemm enabled auto-merge (rebase) May 18, 2026 12:02
@svenklemm svenklemm added the force-auto-backport Automatically backport this PR or fix of this issue, even if it's not marked as "bug" label May 18, 2026
@svenklemm
svenklemm merged commit 73c18ed into main May 18, 2026
58 of 59 checks passed
@svenklemm
svenklemm deleted the sven/cis_expr branch May 18, 2026 12:18
@surister surister mentioned this pull request May 19, 2026
surister pushed a commit that referenced this pull request May 19, 2026
# TimescaleDB Changelog

**Please note: When updating your database, you should connect using
This page lists all the latest features and updates to TimescaleDB. When
you use psql to update your database, use the -X flag and prevent any
.psqlrc
commands from accidentally triggering the load of a previous DB
version.**

## 2.27.1 (2026-05-19)

This release contains performance improvements and bug fixes since the
2.27.0 release. We recommend that you upgrade at the next available
opportunity.

**Bugfixes**
* [#9795](#9795) Delete
orphaned `compression_settings` before migrating catalog table
* [#9799](#9799) Fix
`job_errors` view leaking failed jobs to non-owners
* [#9800](#9800) Check
hypertable ownership before recompression
* [#9801](#9801) Fix
information leak in `policy_reorder_remove`
* [#9824](#9824) Adding
migration scripts for composite bloom filters
* [#9828](#9828) Skip
columnar index scan when grouping by an expression
* [#9830](#9830) Skip
`ColumnarIndexScan` for GROUPING SETS / ROLLUP / CUBE

**Thanks**
* @homanp for reporting an information leak with the job_errors view
@timescale-automation timescale-automation added the released-2.27.1 Released in 2.27.1 label May 19, 2026
@timescale-automation timescale-automation added the released-2.28.0 Released in 2.28.0 label Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported-2.27.x force-auto-backport Automatically backport this PR or fix of this issue, even if it's not marked as "bug" released-2.27.1 Released in 2.27.1 released-2.28.0 Released in 2.28.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants