Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong order by result #16422

Merged
merged 15 commits into from
Sep 18, 2024
Merged

fix: wrong order by result #16422

merged 15 commits into from
Sep 18, 2024

Conversation

xudong963
Copy link
Member

@xudong963 xudong963 commented Sep 9, 2024

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

Summary

The root cause of wrong order by result is the invalid binding sequence of order by and select

  1. bind select, as known as bind_projection first, then bind order by.
  2. remove unnecessary code when binding order by
  3. add a rule: RulePushDownSortEvalScalar to push down sort under eval sort in lazy materialization scene
  4. enhance EliminateEvalScalar, delete unnecessary eval scalar
  5. add an extra matcher for PushDownSortScan to make sort push down scan if the SQL pattern is sort->eval scalar -> scan.
  6. fix related tests

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

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Sep 9, 2024
@xudong963 xudong963 marked this pull request as draft September 9, 2024 09:34
@dosubot dosubot bot added A-planner Area: planner/optimizer C-bug Category: something isn't working labels Sep 9, 2024
@xudong963 xudong963 changed the title Fix: wrong order by result fix: wrong order by result Sep 9, 2024
@datafuselabs datafuselabs deleted a comment from github-actions bot Sep 9, 2024
@github-actions github-actions bot added the pr-bugfix this PR patches a bug in codebase label Sep 9, 2024
@xudong963 xudong963 force-pushed the fix_order_by branch 7 times, most recently from 0d938ce to e0f9dcb Compare September 14, 2024 04:29
@xudong963 xudong963 marked this pull request as ready for review September 14, 2024 09:11
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. A-query Area: databend query and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Sep 14, 2024
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 18, 2024
@sundy-li sundy-li added this pull request to the merge queue Sep 18, 2024
Merged via the queue into datafuselabs:main with commit cbbd4e3 Sep 18, 2024
78 checks passed
@xudong963 xudong963 deleted the fix_order_by branch September 20, 2024 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-planner Area: planner/optimizer A-query Area: databend query C-bug Category: something isn't working lgtm This PR has been approved by a maintainer pr-bugfix this PR patches a bug in codebase size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

bug: Incorrect sql logic test case in subquery.test
2 participants