Repository navigation
Commit 50d6e4a
perf: merge the two UNKNOWN joins of a residual
The fallback for an `IN` whose join keeps a residual filter built three
mark joins. The first says whether the value matched. The other two, both
without a join predicate, say whether the subquery gives a NULL and
whether it gives any row at all, and the caller combined them as
`has_null OR (value IS NULL AND non_empty)`.
One join answers both. Its filter keeps a subquery row when the subquery
value is NULL, or when the outer value is NULL and the row is in scope at
all. For a value that is not NULL the mark reads `has_null`. For a value
that is NULL it reads `non_empty`, which is the weaker fact that case
needs and which `has_null` implies. `IS NULL` is two-valued on both
sides, so neither test adds an UNKNOWN of its own.
`build_join` gains the extra predicate, and `mark_join_with_alias` lets
the caller own the alias so that it can name the aliased subquery column.
No result changes: only `EXPLAIN` expectations move, and the `CASE` loses
its disjunction. A differential fuzz of 560 correlated `IN` and `NOT IN`
queries against DuckDB 1.5.2 finds no mismatch, and the same fuzz finds
98 on the merge base.
Co-Authored-By: Claude Opus 5 <[email protected]>IN into one1 parent bb043f1 commit 50d6e4a
3 files changed
Lines changed: 109 additions & 91 deletions
File tree
- datafusion
- optimizer/src
- sqllogictest/test_files
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
300 | 304 | | |
301 | 305 | | |
302 | | - | |
| 306 | + | |
303 | 307 | | |
304 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
305 | 316 | | |
306 | 317 | | |
307 | 318 | | |
308 | 319 | | |
309 | | - | |
310 | 320 | | |
311 | 321 | | |
312 | 322 | | |
| |||
421 | 431 | | |
422 | 432 | | |
423 | 433 | | |
| 434 | + | |
424 | 435 | | |
425 | 436 | | |
426 | 437 | | |
| |||
450 | 461 | | |
451 | 462 | | |
452 | 463 | | |
| 464 | + | |
| 465 | + | |
453 | 466 | | |
454 | | - | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
455 | 478 | | |
456 | 479 | | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
466 | 493 | | |
467 | 494 | | |
468 | 495 | | |
| |||
642 | 669 | | |
643 | 670 | | |
644 | 671 | | |
| 672 | + | |
645 | 673 | | |
646 | 674 | | |
647 | 675 | | |
| |||
754 | 782 | | |
755 | 783 | | |
756 | 784 | | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
757 | 793 | | |
758 | 794 | | |
759 | 795 | | |
| |||
1638 | 1674 | | |
1639 | 1675 | | |
1640 | 1676 | | |
1641 | | - | |
1642 | | - | |
1643 | | - | |
1644 | | - | |
1645 | | - | |
1646 | | - | |
1647 | | - | |
1648 | | - | |
1649 | | - | |
1650 | | - | |
1651 | | - | |
1652 | | - | |
1653 | | - | |
1654 | | - | |
1655 | | - | |
1656 | | - | |
1657 | | - | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
1658 | 1688 | | |
1659 | 1689 | | |
1660 | 1690 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1989 | 1989 | | |
1990 | 1990 | | |
1991 | 1991 | | |
1992 | | - | |
1993 | | - | |
1994 | | - | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
1995 | 1995 | | |
1996 | 1996 | | |
1997 | 1997 | | |
1998 | 1998 | | |
1999 | 1999 | | |
2000 | | - | |
2001 | | - | |
2002 | | - | |
2003 | | - | |
2004 | | - | |
2005 | | - | |
2006 | | - | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
2007 | 2003 | | |
2008 | 2004 | | |
2009 | 2005 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
157 | 152 | | |
158 | | - | |
159 | | - | |
| 153 | + | |
| 154 | + | |
160 | 155 | | |
161 | | - | |
162 | | - | |
| 156 | + | |
| 157 | + | |
163 | 158 | | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
| 159 | + | |
168 | 160 | | |
169 | 161 | | |
170 | 162 | | |
| |||
453 | 445 | | |
454 | 446 | | |
455 | 447 | | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
460 | 452 | | |
461 | 453 | | |
462 | 454 | | |
463 | 455 | | |
464 | 456 | | |
465 | | - | |
466 | | - | |
467 | | - | |
| 457 | + | |
| 458 | + | |
468 | 459 | | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
480 | 472 | | |
481 | 473 | | |
482 | 474 | | |
| |||
0 commit comments