Repository navigation
Use SQL null semantics for DuckDB IN and NOT IN pushdown - #10054
Conversation
Merging this PR will improve performance by 13.19%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | WallTime | threshold_neon[64] |
5.2 µs | 4.6 µs | +13.78% |
| ⚡ | WallTime | threshold_neon[8] |
3.6 µs | 3.1 µs | +13.13% |
| ⚡ | WallTime | filter_neon[64] |
3.2 µs | 2.8 µs | +12.68% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing rk/duckdb-list-contains (c97dc82) with develop (c128e99)
2aaa1b6 to
1b63fd8
Compare
7f7f687 to
29fa2b0
Compare
1b63fd8 to
3151b45
Compare
29fa2b0 to
adc15ee
Compare
adc15ee to
2535299
Compare
3151b45 to
b6ffdda
Compare
2535299 to
cafd7d2
Compare
ed99a18 to
0e3443a
Compare
04bd414 to
459162a
Compare
2242462 to
828a8f7
Compare
c0e6065 to
843d57c
Compare
828a8f7 to
3dd8f74
Compare
843d57c to
e4b6598
Compare
3dd8f74 to
2a51612
Compare
2a977a1 to
5b12a0f
Compare
446956a to
6801f5b
Compare
757e4da to
461e8a7
Compare
856b420 to
2bda1b5
Compare
Convert both IN table filters and bound membership expressions through in_list, so a null set element leaves nonmatches unknown. Decline nonconstant lists instead of promising conversion and failing later. Add scan-result and EXPLAIN regressions for nullable sets, views, large constant lists, and fallback for nonconstant list elements. Signed-off-by: Robert Kruszewski <[email protected]>
Signed-off-by: Robert Kruszewski <[email protected]>
Signed-off-by: Robert Kruszewski <[email protected]>
DuckDB IN and NOT IN filters now convert to in_list, which shows opts=sql_null_semantics in EXPLAIN. Update the expected TPC-H, TPC-DS and ClickBench plans to match. The membership pushdown test searched EXPLAIN for "list_contains", but the scan shows "vortex.list.contains". Search for "sql_null_semantics" instead, because the EXPLAIN box does not split it across lines. Signed-off-by: Robert Kruszewski <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
461e8a7 to
c31d440
Compare
Before, any IN whose children could push was accepted, and conversion failed when a list value was not a constant. The previous fix only accepted constant lists, which pushed less than before. Accept the same IN expressions as before and convert all of them. Constant values go into one in_list. Each nonconstant value becomes an equality with the element, joined with Kleene OR, which keeps the SQL null semantics of IN and NOT IN. Remove a stale TODO on the IN table filter. Signed-off-by: Robert Kruszewski <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Revert the OR-of-equalities lowering for nonconstant IN values. in_list already gives SQL semantics for constant lists, and DuckDB keeps IN expressions with nonconstant values. Signed-off-by: Robert Kruszewski <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bring back the conversion of IN values that are not constants to equalities joined with OR, and explain it. All constants still go into one in_list with SQL null semantics. Kleene OR keeps the SQL result of IN and NOT IN when values are null. Signed-off-by: Robert Kruszewski <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Robert Kruszewski <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Robert Kruszewski <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
| let dtype = scalars[0].dtype().clone(); | ||
| let list_scalar = Scalar::list(Arc::new(dtype), scalars, Nullability::Nullable); | ||
| list_contains(lit(list_scalar), col.clone()) | ||
| let list_scalar = Scalar::list(Arc::new(dtype), scalars, Nullability::NonNullable); | ||
| in_list(col.clone(), lit(list_scalar)) |
DuckDB's in_clause optimizer rewrites IN lists with nonconstant values to equalities, so the OR lowering only ran with that optimizer disabled. Remove it and keep IN pushdown for constant lists, which in_list converts with SQL null semantics. DuckDB keeps other IN lists. Signed-off-by: Robert Kruszewski <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Robert Kruszewski <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
DuckDB membership pushdown used Vortex's default null rules, which can make a nonmatch in
NOT IN (1, NULL)true. Use SQL null semantics so that result remains unknown and the row is excluded.