Skip to content

feat(query): optimize sort merging with adaptive loser trees - #20218

Draft
forsaken628 wants to merge 2 commits into
databendlabs:mainfrom
forsaken628:sort-cur
Draft

feat(query): optimize sort merging with adaptive loser trees#20218
forsaken628 wants to merge 2 commits into
databendlabs:mainfrom
forsaken628:sort-cur

Conversation

@forsaken628

@forsaken628 forsaken628 commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

  • Keep borrowed row items cached in Cursor and owned by merger-side row storage, avoiding repeated row lookup in comparison paths.
  • Rework the existing heap and loser-tree merge implementations behind a common SortAlgorithm interface.
  • Optimize loser-tree build, replay, winner replacement, and cursor update paths.
  • Propagate only the Rows type through core sort, collect, and spill processors, while keeping runtime dispatch outside monomorphized hot loops.
  • Reuse the core Cursor in the Top-N path and extend sync, async, limit, move-safety, and fuzz coverage.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions Bot added the pr-feature this PR introduces a new feature to the codebase label Jul 28, 2026
@forsaken628 forsaken628 added the ci-benchmark Benchmark: run all test label Jul 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Docker Image for PR

  • tag: pr-20218-3e8f6f8-1785309663

note: this image tag is only available for internal use.

@forsaken628 forsaken628 added ci-benchmark-local Benchmark: run only local test and removed ci-benchmark Benchmark: run all test labels Jul 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Docker Image for PR

  • tag: pr-20218-00ce458-1785381958

note: this image tag is only available for internal use.

@github-actions

Copy link
Copy Markdown
Contributor

@forsaken628 forsaken628 added ci-benchmark-cloud Benchmark: run only cloud tests for tpch/hits and removed ci-benchmark-local Benchmark: run only local test labels Jul 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Docker Image for PR

  • tag: pr-20218-00ce458-1785398178

note: this image tag is only available for internal use.

@github-actions

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-benchmark-cloud Benchmark: run only cloud tests for tpch/hits pr-feature this PR introduces a new feature to the codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant