Commit 82af167
Optimize null-aware anti join to skip CollectLeft when keys are non-nullable
When all join keys are non-nullable on both sides, we don't need null-aware
semantics because NULLs cannot exist in the data. This allows the query to use
regular Partitioned mode instead of the more expensive CollectLeft mode.
Implementation:
- Added join_keys_may_be_null() helper function that checks schema nullability
- Modified null_aware flag logic to only enable when:
1. It's a NOT IN subquery (not NOT EXISTS)
2. AND at least one join key column is nullable
Benefits:
- Queries with NOT NULL constraints can use Partitioned mode (better parallelism)
- Avoids unnecessary CollectLeft overhead when null-aware semantics aren't needed
- Regular anti join is cheaper than null-aware (no atomic flag synchronization)
Example: SELECT * FROM t1 WHERE id NOT IN (SELECT id FROM t2)
- If t1.id and t2.id are NOT NULL: uses regular anti join with Partitioned mode
- If either is nullable: uses null-aware anti join with CollectLeft mode
Addresses review comment on join_selection.rs L251 by detecting nullability
earlier in the optimizer rather than in the physical optimizer.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>1 parent 5f9249b commit 82af167
1 file changed
+40
-3
lines changedLines changed: 40 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
313 | 346 | | |
314 | 347 | | |
315 | 348 | | |
| |||
422 | 455 | | |
423 | 456 | | |
424 | 457 | | |
425 | | - | |
426 | | - | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
427 | 464 | | |
428 | 465 | | |
429 | 466 | | |
| |||
0 commit comments