Commit e8990c4
authored
perf: replace SMJ's join_filter_not_matched_map HashMap with Vec<FilterState> (#21517)
## Which issue does this PR close?
Partially addresses #20910, might be the last one for now.
## Rationale for this change
In full outer joins with filters, `BufferedBatch` tracks which buffered
rows had all filter evaluations fail using a `HashMap<u64, bool>`. This
map is read and written per-row in a hot loop during
`freeze_streamed_matched`. The HashMap pays ~40-60 bytes per entry
(8-byte u64 key + 1-byte bool value + hash table overhead), hashes every
key twice per iteration (once for `get`, once for `insert`), and
scatters entries across heap allocations with poor cache locality.
## What changes are included in this PR?
Replaces `HashMap<u64, bool>` with `Vec<FilterState>` indexed by
absolute row position within the batch. `FilterState` is a `#[repr(u8)]`
enum with three variants (`Unvisited`, `AllFailed`, `SomePassed`), so
the Vec is 1 byte per row — allocated once, direct-indexed, no hashing.
At the default batch size of 8192 rows the Vec is 8 KB (fits in L1
cache). Even at large batch sizes (32K+), 32 KB is still within L1 on
most machines, while the HashMap at 32K entries would consume ~1-2 MB of
scattered heap memory.
Three states are needed because a simple `Vec<bool>` cannot distinguish
"never matched" (handled separately by `null_joined`) from "matched but
all filters failed" (must be emitted as null-joined). The enum variant
names are self-documenting, unlike `Option<bool>` where
`None`/`Some(true)`/`Some(false)` would be opaque.
## Are these changes tested?
Existing tests.
## Are there any user-facing changes?
No.1 parent 8939726 commit e8990c4
File tree
1 file changed
+45
-20
lines changed- datafusion/physical-plan/src/joins/sort_merge_join
1 file changed
+45
-20
lines changedLines changed: 45 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
205 | 223 | | |
206 | 224 | | |
207 | 225 | | |
| |||
217 | 235 | | |
218 | 236 | | |
219 | 237 | | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
225 | 241 | | |
226 | 242 | | |
227 | 243 | | |
| |||
258 | 274 | | |
259 | 275 | | |
260 | 276 | | |
261 | | - | |
| 277 | + | |
262 | 278 | | |
263 | 279 | | |
264 | 280 | | |
| |||
1250 | 1266 | | |
1251 | 1267 | | |
1252 | 1268 | | |
1253 | | - | |
1254 | | - | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
1255 | 1272 | | |
1256 | | - | |
| 1273 | + | |
1257 | 1274 | | |
1258 | | - | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
1259 | 1279 | | |
1260 | 1280 | | |
1261 | 1281 | | |
| |||
1270 | 1290 | | |
1271 | 1291 | | |
1272 | 1292 | | |
1273 | | - | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
1274 | 1296 | | |
1275 | 1297 | | |
1276 | 1298 | | |
| |||
1443 | 1465 | | |
1444 | 1466 | | |
1445 | 1467 | | |
1446 | | - | |
1447 | | - | |
1448 | | - | |
1449 | | - | |
1450 | | - | |
1451 | | - | |
1452 | | - | |
1453 | | - | |
1454 | | - | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
1455 | 1480 | | |
1456 | 1481 | | |
1457 | 1482 | | |
| |||
0 commit comments