Commit 0bf9def
authored
fix: Fix three bugs in query decorrelation (apache#21208)
## Which issue does this PR close?
- Closes apache#21205.
- Closes apache#21206.
- Closes apache#20315.
## Rationale for this change
This PR fixes three separate bugs in query decorrelation:
1. When removing duplicate filters as part of pulling up `IN`
subqueries, an operator precedence error meant that we would consider
two filters to be duplicates even if they involved different operators
(e.g., `=` and `>`).
2. When generating the `CASE` used to implement "count bug" handling, we
referenced the subquery output column without qualifying it by the
subquery alias. This could result in name-collisions with unrelated
identifiers in the parent query.
3. After generating the `CASE` used for "count bug" handling, we rewrote
the parent query to replace references to the subquery output column
with the generated `CASE` expression. This rewrite only matched on
unqualified column name only, which meant that unrelated parent query
identifiers that happened to share the same column name as subquery
aggregate aliases could been rewritten by mistake.
The first and third issues could result in incorrect query results; the
second would only cause spurious errors, as far as I can see.
## What changes are included in this PR?
* Fix all three bugs
* Add SLT tests
* Add a `debug_assert!` to document/check that
`remove_duplicated_filter` is called with a commutative operator
## Are these changes tested?
Yes.
## Are there any user-facing changes?
No, except in the sense that they fix user-visible bugs.1 parent 2d9e268 commit 0bf9def
File tree
3 files changed
+108
-25
lines changed- datafusion
- optimizer/src
- sqllogictest/test_files
3 files changed
+108
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
179 | 181 | | |
180 | 182 | | |
181 | 183 | | |
182 | | - | |
| 184 | + | |
183 | 185 | | |
184 | 186 | | |
185 | 187 | | |
| |||
460 | 462 | | |
461 | 463 | | |
462 | 464 | | |
463 | | - | |
464 | | - | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
465 | 480 | | |
466 | 481 | | |
467 | 482 | | |
468 | 483 | | |
469 | 484 | | |
470 | 485 | | |
471 | | - | |
| 486 | + | |
472 | 487 | | |
473 | 488 | | |
474 | | - | |
475 | | - | |
476 | | - | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
477 | 493 | | |
478 | 494 | | |
479 | 495 | | |
480 | 496 | | |
481 | | - | |
| 497 | + | |
482 | 498 | | |
483 | 499 | | |
484 | 500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
| 114 | + | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
| 179 | + | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
304 | | - | |
| 304 | + | |
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
361 | 368 | | |
362 | 369 | | |
363 | 370 | | |
364 | 371 | | |
365 | 372 | | |
366 | | - | |
367 | | - | |
368 | | - | |
| 373 | + | |
369 | 374 | | |
370 | 375 | | |
371 | 376 | | |
372 | 377 | | |
373 | 378 | | |
374 | 379 | | |
375 | 380 | | |
376 | | - | |
377 | | - | |
378 | | - | |
| 381 | + | |
379 | 382 | | |
380 | 383 | | |
381 | 384 | | |
382 | 385 | | |
383 | 386 | | |
384 | | - | |
385 | | - | |
386 | | - | |
| 387 | + | |
387 | 388 | | |
388 | 389 | | |
389 | | - | |
390 | | - | |
391 | | - | |
| 390 | + | |
392 | 391 | | |
393 | 392 | | |
394 | 393 | | |
395 | 394 | | |
396 | 395 | | |
397 | 396 | | |
398 | | - | |
| 397 | + | |
399 | 398 | | |
400 | 399 | | |
401 | 400 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1671 | 1671 | | |
1672 | 1672 | | |
1673 | 1673 | | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
0 commit comments