Skip to content

Read hypertable max time value with an ordered scan - #10379

Merged
svenklemm merged 1 commit into
mainfrom
sven/cagg_max
Aug 3, 2026
Merged

Read hypertable max time value with an ordered scan#10379
svenklemm merged 1 commit into
mainfrom
sven/cagg_max

Conversation

@svenklemm

@svenklemm svenklemm commented Jul 31, 2026

Copy link
Copy Markdown
Member

The max value of a hypertable's open dimension was read with a max()
aggregate. For UUID time columns the aggregate argument is an expression
that extracts the timestamp from the UUID. Because the argument is an
expression and not a plain column, the planner cannot rewrite the
aggregate into a min/max aggregate, so it reads every row instead.

Also lock down search_path for the SPI execution and fix a sql
injection vulnerability in the UUID path.

@svenklemm svenklemm changed the title sven/cagg max Read hypertable max time value with an ordered scan Jul 31, 2026
@github-actions
github-actions Bot requested review from akuzm and antekresic July 31, 2026 21:21
@github-actions

Copy link
Copy Markdown

@akuzm, @antekresic: please review this pull request.

Powered by pull-review

@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 Jul 31, 2026
@svenklemm svenklemm added this to the v2.29.1 milestone Jul 31, 2026
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/hypertable.c 83.33% 0 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@akuzm akuzm left a comment

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.

I think this change is good by itself, because the plan for min/max is going to be like this in any case, only here we skip an extra rewrite that would be done in build_minmax_path. But does this mean that sort pushdown doesn't work for this extract function? We're going to run into other performance problems then, and it makes sense to double-check this.

@svenklemm

Copy link
Copy Markdown
Member Author

I think this change is good by itself, because the plan for min/max is going to be like this in any case, only here we skip an extra rewrite that would be done in build_minmax_path. But does this mean that sort pushdown doesn't work for this extract function? We're going to run into other performance problems then, and it makes sense to double-check this.

For ordering you dont need the extract function. Dont think we optimize extract function by itself atm. But outside scope of this PR

The max value of a hypertable's open dimension was read with a max()
aggregate. For UUID time columns the aggregate argument is an expression
that extracts the timestamp from the UUID. Because the argument is an
expression and not a plain column, the planner cannot rewrite the
aggregate into a min/max aggregate, so it reads every row instead.

Also lock down search_path for the SPI execution and fix a sql
injection vulnerability in the UUID path.
@svenklemm
svenklemm merged commit 800fa71 into main Aug 3, 2026
59 of 62 checks passed
@svenklemm
svenklemm deleted the sven/cagg_max branch August 3, 2026 12:42
@surister surister mentioned this pull request Aug 4, 2026
surister pushed a commit that referenced this pull request Aug 4, 2026
# TimescaleDB Changelog

**Please note: When updating your database, you should connect using
`psql` with the `-X` flag to prevent any `.psqlrc` commands from
accidentally triggering the load of a previous TimescaleDB version.**

## 2.29.1 (2026-08-04)

This release contains performance improvements and bug fixes since the
2.29.0 release and fixes for security vulnerabilities (#10360, #10379,
#10386). You can check the [security
advisory](https://github.com/timescale/timescaledb/security/advisories/GHSA-hcfx-29v5-2rcw)
for more information on the vulnerability and the platforms that are
affected. We recommend that you upgrade at the next available
opportunity.

**Bugfixes**
* [#10327](#10327)
Assertion failure in `add_dimension()` when the hypertable argument is
`NULL`
* [#10339](#10339) Fix
crash when deleting from a compressed continuous aggregate source
* [#10340](#10340) Validate
`max_batches` in `compact_chunk()`
* [#10352](#10352) Reset
inherited column and constraint flags on chunks during `attach_chunk()`
* [#10360](#10360) Fix
decompressor crashes with malformed compressed data
* [#10369](#10369) Fix typo
in error message about `MERGE` support on compressed hypertables
* [#10379](#10379) Read
hypertable max time value with an ordered scan
* [#10386](#10386) Add
missing permission checks to internal chunk functions

**Thanks**
* @JoongHyuk-Shin for reporting and fixing `NULL` handling in
`add_dimension()`
* @igor2x for reporting a typo in a `MERGE` support error message
* @mdisec for reporting issues with compressed data validation during
decompression
@timescale-automation timescale-automation added the released-2.29.1 Released in 2.29.1 label Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants