Skip to content

Fix sort optimization on PostgreSQL 19 - #10262

Merged
svenklemm merged 1 commit into
mainfrom
sven/pg19_sort_pathkeys
Jul 15, 2026
Merged

Fix sort optimization on PostgreSQL 19#10262
svenklemm merged 1 commit into
mainfrom
sven/pg19_sort_pathkeys

Conversation

@svenklemm

@svenklemm svenklemm commented Jul 15, 2026

Copy link
Copy Markdown
Member

The sort optimization lets an index provide the order requested by an
ORDER BY on time_bucket, avoiding a separate sort. It works by swapping
the query pathkeys for a simplified form while it builds index paths.

PostgreSQL 19 stopped looking at the query pathkeys when it decides which
index orderings are useful and looks at the sort pathkeys instead, so the
swap had no effect and no ordered index path was built. Swap the sort
pathkeys as well while building the paths.

Upstream changes:
Make truncate_useless_pathkeys() consider WindowFuncs.
postgres/postgres@a5a68dd6d51

Disable-check: force-changelog-file

@github-actions

Copy link
Copy Markdown

@melihmutlu, @kpan2034: please review this pull request.

Powered by pull-review

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 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.

Looking at the commit, I see it added check for windows_pathkeys as well, let's replace them too.

The sort optimization lets an index provide the order requested by an
ORDER BY on time_bucket, avoiding a separate sort. It works by swapping
the query pathkeys for a simplified form while it builds index paths.

PostgreSQL 19 stopped looking at the query pathkeys when it decides which
index orderings are useful and looks at the sort pathkeys instead, so the
swap had no effect and no ordered index path was built. Swap the sort
pathkeys as well while building the paths.

Upstream changes:
Make truncate_useless_pathkeys() consider WindowFuncs.
postgres/postgres@a5a68dd6d51
@svenklemm
svenklemm force-pushed the sven/pg19_sort_pathkeys branch from 5e1271d to 882c559 Compare July 15, 2026 09:03
@svenklemm
svenklemm merged commit 2a4e57e into main Jul 15, 2026
64 of 65 checks passed
@svenklemm
svenklemm deleted the sven/pg19_sort_pathkeys branch July 15, 2026 09:24
@timescale-automation timescale-automation added the released-2.29.0 Released in 2.29.0 label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released-2.29.0 Released in 2.29.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants