Commit 1875365
## Which issue does this PR close?
Cherry-pick of #22493 onto `branch-54`.
## Rationale for this change
`branch-54` includes #21956 (`feat: globally reorder files and row
groups by statistics for TopK queries`), which introduced a regression:
for plain-column, multi-file scans where the on-disk file order does not
match the declared sort order, `SortExec` was no longer eliminated even
when stats-based reorder produced non-overlapping file groups whose
declared ordering re-validated.
#22493 restores the pre-#21956 sort-elimination behaviour by
re-validating `output_ordering` after `rebuild_with_source` reorders
files, and (per @adriangb's correctness follow-up) restoring the
original hint-free `file_source` on the Inexact→Exact upgrade so
leftover `reverse_row_groups` / `sort_order_for_reorder` hints don't
mis-order row groups within a single file once the `SortExec` safety net
is gone.
## What changes are included in this PR?
Straight cherry-pick of merge commit `94c58d086`. Includes:
- `FileScanConfig::try_pushdown_sort` Inexact arm: re-validate, upgrade
to Exact (with file_source restore), guard with NULL safety +
early-return
- `rebuild_with_source`: `match (all_non_overlapping, is_exact)`
decision table for keep_ordering
- SLT updates restoring `SortExec` elimination expectations + Tests
5b/5c/8b for the NULL-safety and same-min row-group edge cases
## Are these changes tested?
Cherry-picked cleanly (auto-merge in `sort_pushdown.rs`).
`cargo build -p datafusion-datasource` — passes.
`cargo test -p datafusion-sqllogictest --test sqllogictests --
sort_pushdown` — passes.
## Are there any user-facing changes?
Same as #22493: plain-column wrong-order-files cases regain SortExec
elimination when files happen to be non-overlapping by statistics. No
new API.
Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a4a0804 commit 1875365
3 files changed
Lines changed: 343 additions & 49 deletions
File tree
- datafusion
- datasource/src/file_scan_config
- sqllogictest/test_files
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
937 | 937 | | |
938 | 938 | | |
939 | 939 | | |
940 | | - | |
941 | | - | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
942 | 947 | | |
943 | 948 | | |
944 | | - | |
| 949 | + | |
945 | 950 | | |
946 | 951 | | |
947 | | - | |
| 952 | + | |
948 | 953 | | |
949 | 954 | | |
950 | 955 | | |
| |||
973 | 978 | | |
974 | 979 | | |
975 | 980 | | |
976 | | - | |
977 | | - | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
978 | 1017 | | |
979 | 1018 | | |
980 | 1019 | | |
| |||
Lines changed: 69 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
161 | 181 | | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
166 | 211 | | |
167 | 212 | | |
168 | 213 | | |
| |||
0 commit comments