databendlabs / databend

๐——๐—ฎ๐˜๐—ฎ, ๐—”๐—ป๐—ฎ๐—น๐˜†๐˜๐—ถ๐—ฐ๐˜€ & ๐—”๐—œ. Modern alternative to Snowflake. Cost-effective and simple for massive-scale analytics. https://databend.com
https://docs.databend.com
Other
7.85k stars 750 forks source link

fix: wrong order by result #16422

Closed xudong963 closed 1 month ago

xudong963 commented 2 months ago

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

Type of change


This change isโ€‚Reviewable