Repository navigation
Commit 9eeb66f
fix: do not drop GROUP BY keys using nullable UNIQUE constraints (#26220)
## Which issue does this PR close?
- Closes #23819.
## Rationale for this change
A nullable UNIQUE column permits multiple NULL rows, so it cannot safely
determine other grouping columns. Dropping those columns can merge
distinct
groups and return incorrect results.
## What changes are included in this PR?
- Only rewrite GROUP BY expressions using dependencies valid across
NULLs.
- Apply the same check to DISTINCT elimination to preserve correct
results.
- Add regression tests and an upgrade guide note.
## What is the testing strategy for this PR?
SLT and plan-builder tests cover nullable and composite UNIQUE keys,
DISTINCT after GROUP BY, and valid PRIMARY KEY / NOT NULL UNIQUE cases.
The DISTINCT regressions fail without the fix.
## Are there any user-facing changes?
Yes: incorrect results are fixed
---------
Co-authored-by: Andrew Lamb <[email protected]>1 parent 6e69fe9 commit 9eeb66f
6 files changed
Lines changed: 307 additions & 79 deletions
File tree
- datafusion
- common/src
- expr/src/logical_plan
- optimizer/src
- sqllogictest/test_files
- docs/source/library-user-guide/upgrading
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
475 | | - | |
476 | | - | |
477 | | - | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
478 | 483 | | |
479 | 484 | | |
480 | 485 | | |
| |||
500 | 505 | | |
501 | 506 | | |
502 | 507 | | |
503 | | - | |
504 | | - | |
| 508 | + | |
| 509 | + | |
505 | 510 | | |
506 | 511 | | |
507 | 512 | | |
| |||
572 | 577 | | |
573 | 578 | | |
574 | 579 | | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
575 | 586 | | |
576 | 587 | | |
577 | 588 | | |
| |||
582 | 593 | | |
583 | 594 | | |
584 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
585 | 606 | | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
| 607 | + | |
592 | 608 | | |
593 | 609 | | |
594 | 610 | | |
595 | | - | |
| 611 | + | |
| 612 | + | |
596 | 613 | | |
597 | 614 | | |
598 | 615 | | |
599 | | - | |
| 616 | + | |
600 | 617 | | |
601 | 618 | | |
602 | 619 | | |
| |||
623 | 640 | | |
624 | 641 | | |
625 | 642 | | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
633 | 650 | | |
634 | 651 | | |
| 652 | + | |
635 | 653 | | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | 654 | | |
641 | | - | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
642 | 658 | | |
643 | 659 | | |
644 | 660 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3138 | 3138 | | |
3139 | 3139 | | |
3140 | 3140 | | |
| 3141 | + | |
| 3142 | + | |
| 3143 | + | |
| 3144 | + | |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
| 3175 | + | |
| 3176 | + | |
| 3177 | + | |
| 3178 | + | |
| 3179 | + | |
| 3180 | + | |
| 3181 | + | |
| 3182 | + | |
| 3183 | + | |
| 3184 | + | |
| 3185 | + | |
| 3186 | + | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
| 3195 | + | |
| 3196 | + | |
| 3197 | + | |
3141 | 3198 | | |
3142 | 3199 | | |
3143 | 3200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
106 | 108 | | |
| 109 | + | |
107 | 110 | | |
108 | 111 | | |
109 | 112 | | |
| |||
0 commit comments