Commit ec110ce
authored
## Which issue does this PR close?
- Closes #24355.
## Rationale for this change
With `pushdown_filters = true` + dynamic filter pushdown (on by
default), a query `SELECT b FROM t WHERE <predicate on a> ORDER BY b
LIMIT k` can silently return **wrong results** — rows satisfying the
predicate are dropped and replaced by later ones, no error.
Root cause (thanks to @adriangb's report + fixture in #24355): the push
decoder carries one flat `RowSelection` over the concatenation of the
*remaining* row groups. At a row-group boundary the runtime pruner drops
row groups the dynamic predicate proves unwinnable and rebuilds the
decoder:
```rust
decoder.into_builder()?.with_row_groups(new_indices).build()
```
`with_row_groups(new_indices)` removes row groups **without slicing the
carried `RowSelection` to match**, so the selectors intended for a
dropped RG are applied to the next surviving one. In the fixture,
page-index pruning leaves RG 1 with `skip 50, select 50`; after the TopK
threshold prunes RG 1 and RG 2, the survivor RG 3 is decoded under RG
1's selection and its first 50 rows (`b = 0..49`, the correct answer)
are wrongly skipped.
This is a second, independent instance of the drift family in
#24352/#24354; it is **not** fixed by #24354.
## What changes are included in this PR?
- `opener/mod.rs`: **decline to build the runtime `RowGroupPruner` when
a page-index `RowSelection` is present.** With no pruner there is no
boundary rebuild, so the carried selection is never applied to the wrong
row groups. This mirrors `PreparedAccessPlan::reorder_by_statistics`,
which already bails when a row selection is present (`"Skipping RG
reorder: row_selection present"`) because remapping the selection is too
complex.
This is the minimal, DataFusion-side stop-the-bleeding fix. The proper
fix is upstream in arrow-rs: apache/arrow-rs#10624 proposes letting the
push decoder carry **row-group-local** `RowSelection`s
(`with_row_group_selections`) that are preserved across rebuilds, so
dropping a row group keeps every survivor's selection aligned by
construction — no global-selection slicing to get wrong, and no parallel
`rg_plan` to drift (the #24352 path). DataFusion tracks that migration
in #24358; this guard is removed once it lands.
## Are these changes tested?
- Adds an slt regression test in `dynamic_row_group_pruning.slt` (the
reporter's fixture via `generate_series` + `COPY`). It **fails on
`main`** (returns `50..54` instead of `0..4`) and passes with this
change.
- Updates the existing rust integration test that previously asserted
the runtime pruner **coexists** with a page-index selection
(`dynamic_rg_pruning_coexists_with_page_index_row_selection`,
`row_groups_pruned_dynamic_filter >= 1`). Since this PR intentionally
disables the pruner in that case, it is renamed to
`dynamic_rg_pruning_disabled_when_page_index_row_selection_present` and
now asserts `row_groups_pruned_dynamic_filter == 0` while results stay
correct and page-index pruning still runs. (That old test passed only
because its scenario happened not to expose the bug — the misapplied
selection fell outside the top-k.)
- The other dynamic-prune tests are unaffected — they have no row
selection, so the pruner is created as before.
## Are there any user-facing changes?
Fixes silently-wrong results. Runtime row-group pruning is skipped for
scans that also have a page-index row selection (correctness over a
pruning optimization); this is undone once #24358 lands.
cc @alamb @adriangb @hhhizzz
1 parent 1b67f2e commit ec110ce
3 files changed
Lines changed: 176 additions & 47 deletions
File tree
- datafusion
- core/tests/parquet
- datasource-parquet/src/opener
- sqllogictest/test_files
Lines changed: 45 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
297 | 299 | | |
298 | 300 | | |
299 | 301 | | |
300 | | - | |
301 | | - | |
302 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
303 | 314 | | |
304 | 315 | | |
305 | 316 | | |
| |||
309 | 320 | | |
310 | 321 | | |
311 | 322 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
321 | 329 | | |
322 | | - | |
| 330 | + | |
323 | 331 | | |
324 | 332 | | |
325 | 333 | | |
| |||
348 | 356 | | |
349 | 357 | | |
350 | 358 | | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
357 | 362 | | |
358 | 363 | | |
359 | 364 | | |
| |||
362 | 367 | | |
363 | 368 | | |
364 | 369 | | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
365 | 374 | | |
366 | 375 | | |
367 | 376 | | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
372 | 382 | | |
373 | 383 | | |
374 | 384 | | |
| |||
647 | 657 | | |
648 | 658 | | |
649 | 659 | | |
650 | | - | |
651 | | - | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
652 | 669 | | |
653 | 670 | | |
654 | | - | |
655 | | - | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
656 | 674 | | |
657 | 675 | | |
658 | 676 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1435 | 1435 | | |
1436 | 1436 | | |
1437 | 1437 | | |
1438 | | - | |
| 1438 | + | |
1439 | 1439 | | |
1440 | 1440 | | |
1441 | 1441 | | |
| |||
1464 | 1464 | | |
1465 | 1465 | | |
1466 | 1466 | | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
1467 | 1479 | | |
1468 | 1480 | | |
1469 | 1481 | | |
| |||
1482 | 1494 | | |
1483 | 1495 | | |
1484 | 1496 | | |
1485 | | - | |
| 1497 | + | |
1486 | 1498 | | |
1487 | 1499 | | |
1488 | 1500 | | |
| |||
1504 | 1516 | | |
1505 | 1517 | | |
1506 | 1518 | | |
1507 | | - | |
1508 | | - | |
1509 | | - | |
1510 | | - | |
1511 | | - | |
1512 | | - | |
1513 | | - | |
1514 | | - | |
1515 | | - | |
1516 | | - | |
1517 | | - | |
1518 | | - | |
1519 | | - | |
1520 | | - | |
1521 | | - | |
1522 | | - | |
1523 | | - | |
1524 | | - | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
1525 | 1543 | | |
1526 | 1544 | | |
1527 | 1545 | | |
| |||
Lines changed: 93 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
0 commit comments