Skip to content

fix: default to ASCENDING when sort direction is omitted in SET SORTED BY (#1205)#1227

Merged
pdet merged 1 commit into
duckdb:v1.5-variegatafrom
mohsinsurani:fix-sorted-by-default-direction
Jun 9, 2026
Merged

fix: default to ASCENDING when sort direction is omitted in SET SORTED BY (#1205)#1227
pdet merged 1 commit into
duckdb:v1.5-variegatafrom
mohsinsurani:fix-sorted-by-default-direction

Conversation

@mohsinsurani

Copy link
Copy Markdown

Closes #1205.

This PR fixes an issue where ALTER TABLE ... SET SORTED BY (col) preserved DuckDB's ORDER_DEFAULT sort direction in DuckLake's transaction-local sort metadata. That default could later be interpreted as descending during sorted inserts, instead of following the expected default behavior of ascending order.

Changes

  • Normalize omitted sort direction to ASCENDING in src/storage/ducklake_table_entry.cpp.
  • Preserve explicit DESCENDING behavior unchanged.
  • Add a regression test at test/sql/sorted_table/insert_sorted_default_direction.test.

Testing

  • Verified locally that insert_sorted_default_direction.test fails on HEAD before the patch.
  • Verified locally that insert_sorted_default_direction.test passes after the patch.
  • Verified locally that insert_sorted_basic.test still passes.

Note to Maintainers

I attempted broader debug-suite testing locally, but full execution was blocked by an existing ASAN stack-overflow failure in parser/init paths on main. The focused regression test and a related sorted insert test are green locally, and I’m relying on CI for the full verification matrix.

@Alex-Monahan

Copy link
Copy Markdown
Contributor

Howdy and thank you for your help!
Would you be able to target the v1.5 variegata branch instead of main? We like having bug fixes on that branch and new features on main.

Much appreciated!

@mohsinsurani mohsinsurani force-pushed the fix-sorted-by-default-direction branch from 15d0280 to ec19db0 Compare June 8, 2026 10:29
@mohsinsurani

Copy link
Copy Markdown
Author

Done, I rebased the branch onto v1.5-variegata and force-pushed the updated PR branch. I also reran the focused regression test and insert_sorted_basic.test locally against the v1.5 base; both pass.

@mohsinsurani mohsinsurani changed the base branch from main to v1.5-variegata June 8, 2026 10:41
@pdet

pdet commented Jun 9, 2026

Copy link
Copy Markdown
Member

Thanks!

@pdet pdet merged commit 1fa7804 into duckdb:v1.5-variegata Jun 9, 2026
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.

Sorted tables without sort direction lead to wrong order

3 participants