Skip to content

Skip columnar index scan for GROUPING SETS / ROLLUP / CUBE - #9830

Merged
svenklemm merged 2 commits into
mainfrom
sven/cis_grouping_sets
May 18, 2026
Merged

Skip columnar index scan for GROUPING SETS / ROLLUP / CUBE#9830
svenklemm merged 2 commits into
mainfrom
sven/cis_grouping_sets

Conversation

@svenklemm

@svenklemm svenklemm commented May 16, 2026

Copy link
Copy Markdown
Member

The Agg rewrite in columnar index scan only updates the main Agg's
targetlist and grpColIdx. Plans built for GROUPING SETS, ROLLUP and
CUBE attach a chain of additional Aggs that share the same input, so
those Aggs would keep pointing at the pre-rewrite column layout. Bail
out before rewriting when the Agg has a non-empty grouping sets list
or chain.

Disable-check: commit-count

@svenklemm
svenklemm requested a review from a team May 16, 2026 11:31
@github-actions
github-actions Bot requested a review from pnthao May 16, 2026 11:32
@github-actions

Copy link
Copy Markdown

@pnthao, @Poroma-Banerjee: please review this pull request.

Powered by pull-review

@github-actions
github-actions Bot requested a review from Poroma-Banerjee May 16, 2026 11:32
@svenklemm svenklemm added this to the 2.27.1 milestone May 16, 2026
@svenklemm
svenklemm force-pushed the sven/cis_grouping_sets branch from 2d18b61 to 1dc630f Compare May 16, 2026 11:33
@codecov

codecov Bot commented May 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rc/nodes/columnar_index_scan/columnar_index_scan.c 50.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@svenklemm
svenklemm force-pushed the sven/cis_grouping_sets branch from 1a6716b to 06d10ed Compare May 16, 2026 15:12
@svenklemm
svenklemm requested a review from antekresic May 18, 2026 07:06
Comment thread tsl/src/nodes/columnar_index_scan/columnar_index_scan.c
@svenklemm
svenklemm force-pushed the sven/cis_grouping_sets branch from 06d10ed to 9a2056d Compare May 18, 2026 12:06
@svenklemm
svenklemm enabled auto-merge (rebase) May 18, 2026 12:08
@svenklemm
svenklemm force-pushed the sven/cis_grouping_sets branch from 9a2056d to a582c40 Compare May 18, 2026 12:11
svenklemm added 2 commits May 18, 2026 14:19
The Agg rewrite in columnar index scan only updates the main Agg's
targetlist and grpColIdx. Plans built for GROUPING SETS, ROLLUP and
CUBE attach a chain of additional Aggs that share the same input, so
those Aggs would keep pointing at the pre-rewrite column layout. Bail
out before rewriting when the Agg has a non-empty grouping sets list
or chain.
Cover query shapes that were missing from the test suite:
- DISTINCT on a segmentby column (Agg without Aggrefs)
- count(*) without GROUP BY
- aggregate only in HAVING (not in SELECT)
- GROUP BY ordinal position
- GROUP BY () empty grouping
- aggregate wrapped in COALESCE
- aggregate above a JOIN
- ordered-set aggregate (percentile_cont)
- bool_and / bool_or
- partition-wise aggregate
- Aggref inside a SubLink in the outer tlist (inner aggregate belongs
  to a separate Agg and must not be touched by the outer rewrite)
- HAVING with non-pushable expression on grouping columns (qual stays
  with the Agg instead of being pushed to the scan)
- same Aggref node referenced from multiple tlist positions
- GROUP BY column not in SELECT (appears only as resjunk in Agg tlist)
- WHERE mixing segmentby and non-segmentby columns
- HAVING NOT (Aggref ...) and HAVING Aggref IS NULL (mutator must
  recurse through BoolExpr and NullTest)
- GROUP BY with explicit collation (grouping expression is a
  CollateExpr, not a bare Var)
- self-join on the same hypertable (Agg sits over a Join, not over
  a ColumnarScan)
@svenklemm
svenklemm force-pushed the sven/cis_grouping_sets branch from a582c40 to 4f836d4 Compare May 18, 2026 12:19
@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 cdef866 into main May 18, 2026
68 of 74 checks passed
@svenklemm
svenklemm deleted the sven/cis_grouping_sets branch May 18, 2026 15:30
@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.

4 participants