Commit 5c2ee36
authored
perf: optimize
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Closes #.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
The previous implementation of `HashTableLookupExpr::evaluate` relied on
per-row calls to `get_matched_indices`, which incurred unnecessary
performance overhead:
1. **Memory Overhead**: Each per-row call triggered small `Vec`
allocations and potential resizes, leading to pressure on the memory
allocator.
2. **Redundant Computation**: `get_matched_indices` traverses the entire
hash chain to find all matches, which is unnecessary when we only need
to verify the existence of a key.
### Performance Results (TPC-H)
The following TPC-H results were obtained with
**`DATAFUSION_EXECUTION_PARQUET_PUSHDOWN_FILTERS=true`:**
```
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query ┃ baseline@9a9ff ┃ optimized ┃ Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1 │ 679.51 ms │ 728.06 ms │ 1.07x slower │
│ QQuery 2 │ 388.33 ms │ 384.11 ms │ no change │
│ QQuery 3 │ 864.38 ms │ 856.27 ms │ no change │
│ QQuery 4 │ 458.46 ms │ 468.26 ms │ no change │
│ QQuery 5 │ 1614.26 ms │ 1525.65 ms │ +1.06x faster │
│ QQuery 6 │ 611.20 ms │ 610.06 ms │ no change │
│ QQuery 7 │ 950.39 ms │ 940.13 ms │ no change │
│ QQuery 8 │ 1214.86 ms │ 1218.21 ms │ no change │
│ QQuery 9 │ 2657.61 ms │ 2482.09 ms │ +1.07x faster │
│ QQuery 10 │ 1050.70 ms │ 1001.96 ms │ no change │
│ QQuery 11 │ 383.92 ms │ 347.27 ms │ +1.11x faster │
│ QQuery 12 │ 963.14 ms │ 920.78 ms │ no change │
│ QQuery 13 │ 473.68 ms │ 480.97 ms │ no change │
│ QQuery 14 │ 363.36 ms │ 345.27 ms │ no change │
│ QQuery 15 │ 960.56 ms │ 955.05 ms │ no change │
│ QQuery 16 │ 281.95 ms │ 267.34 ms │ +1.05x faster │
│ QQuery 17 │ 5306.43 ms │ 4983.21 ms │ +1.06x faster │
│ QQuery 18 │ 3415.11 ms │ 3016.52 ms │ +1.13x faster │
│ QQuery 19 │ 761.67 ms │ 759.49 ms │ no change │
│ QQuery 20 │ 650.20 ms │ 642.40 ms │ no change │
│ QQuery 21 │ 3111.85 ms │ 2833.05 ms │ +1.10x faster │
│ QQuery 22 │ 141.75 ms │ 143.06 ms │ no change │
└──────────────┴────────────────┴────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary ┃ ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (baseline@9a9ff) │ 27303.30ms │
│ Total Time (optimized) │ 25909.21ms │
│ Average Time (baseline@9a9ff) │ 1241.06ms │
│ Average Time (optimized) │ 1177.69ms │
│ Queries Faster │ 7 │
│ Queries Slower │ 1 │
│ Queries with No Change │ 14 │
│ Queries with Failure │ 0 │
└───────────────────────────────┴────────────┘
```
Note that Q1 does not involve `HashJoin`.
#### Note on Configuration
Benchmarks were conducted with
`DATAFUSION_EXECUTION_PARQUET_PUSHDOWN_FILTERS=true` because
`HashTableLookupExpr::evaluate` is **NOT** invoked under default
settings.
I manually added `dbg!(&num_rows)` at [L335 in
`partitioned_hash_eval.rs`](https://github.com/apache/datafusion/blob/9a9ff8d6162b7391736b0b7c82c00cb35b0652a1/datafusion/physical-plan/src/joins/hash_join/partitioned_hash_eval.rs#L335)
and confirmed that the logic path is only triggered when this flag is
enabled. Under default settings, `HashTableLookupExpr::evaluate` is not
called; . I am uncertain if this current behavior is intentional.
## What changes are included in this PR?
- Added `JoinHashMapType::contain_hashes`: A new trait method that
processes
a batch of hashes and updates a bitmask for existing keys.
- Refactored `HashTableLookupExpr::evaluate`: Switched from per-row
lookups to
the new batch API.
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
## Are these changes tested?
Yes
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
## Are there any user-facing changes?
NO
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->HashTableLookupExpr::evaluate (#19602)1 parent adf00a6 commit 5c2ee36
File tree
5 files changed
+128
-113
lines changed- datafusion
- physical-plan/src/joins
- hash_join
- proto/tests/cases
5 files changed
+128
-113
lines changedLines changed: 71 additions & 102 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
26 | 25 | | |
27 | | - | |
| 26 | + | |
28 | 27 | | |
29 | | - | |
| 28 | + | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 184 | + | |
188 | 185 | | |
189 | 186 | | |
190 | 187 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
| 188 | + | |
196 | 189 | | |
197 | 190 | | |
198 | 191 | | |
| |||
217 | 210 | | |
218 | 211 | | |
219 | 212 | | |
220 | | - | |
221 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
222 | 217 | | |
223 | 218 | | |
224 | 219 | | |
| |||
229 | 224 | | |
230 | 225 | | |
231 | 226 | | |
232 | | - | |
| 227 | + | |
| 228 | + | |
233 | 229 | | |
234 | 230 | | |
235 | 231 | | |
236 | 232 | | |
237 | 233 | | |
238 | 234 | | |
239 | 235 | | |
240 | | - | |
| 236 | + | |
| 237 | + | |
241 | 238 | | |
242 | 239 | | |
243 | 240 | | |
244 | 241 | | |
245 | | - | |
| 242 | + | |
| 243 | + | |
246 | 244 | | |
247 | 245 | | |
248 | 246 | | |
| |||
251 | 249 | | |
252 | 250 | | |
253 | 251 | | |
254 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
255 | 260 | | |
256 | 261 | | |
257 | 262 | | |
258 | 263 | | |
259 | 264 | | |
260 | | - | |
| 265 | + | |
261 | 266 | | |
| 267 | + | |
262 | 268 | | |
263 | 269 | | |
264 | 270 | | |
| |||
279 | 285 | | |
280 | 286 | | |
281 | 287 | | |
282 | | - | |
| 288 | + | |
283 | 289 | | |
| 290 | + | |
284 | 291 | | |
285 | 292 | | |
286 | 293 | | |
| |||
299 | 306 | | |
300 | 307 | | |
301 | 308 | | |
302 | | - | |
| 309 | + | |
303 | 310 | | |
304 | 311 | | |
305 | 312 | | |
306 | 313 | | |
307 | 314 | | |
308 | 315 | | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | 316 | | |
316 | | - | |
| 317 | + | |
| 318 | + | |
317 | 319 | | |
318 | 320 | | |
319 | 321 | | |
| |||
327 | 329 | | |
328 | 330 | | |
329 | 331 | | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
356 | 335 | | |
357 | | - | |
358 | | - | |
359 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
360 | 340 | | |
361 | 341 | | |
362 | 342 | | |
363 | 343 | | |
364 | 344 | | |
365 | 345 | | |
366 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
367 | 358 | | |
368 | 359 | | |
369 | 360 | | |
| |||
482 | 473 | | |
483 | 474 | | |
484 | 475 | | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | 476 | | |
491 | 477 | | |
492 | 478 | | |
493 | 479 | | |
494 | | - | |
| 480 | + | |
| 481 | + | |
495 | 482 | | |
496 | 483 | | |
497 | 484 | | |
498 | 485 | | |
499 | 486 | | |
500 | | - | |
| 487 | + | |
| 488 | + | |
501 | 489 | | |
502 | 490 | | |
503 | 491 | | |
| |||
506 | 494 | | |
507 | 495 | | |
508 | 496 | | |
509 | | - | |
| 497 | + | |
510 | 498 | | |
511 | 499 | | |
512 | 500 | | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | 501 | | |
526 | 502 | | |
527 | 503 | | |
528 | 504 | | |
529 | | - | |
| 505 | + | |
| 506 | + | |
530 | 507 | | |
531 | 508 | | |
532 | 509 | | |
533 | 510 | | |
534 | 511 | | |
535 | | - | |
| 512 | + | |
| 513 | + | |
536 | 514 | | |
537 | 515 | | |
538 | 516 | | |
| |||
543 | 521 | | |
544 | 522 | | |
545 | 523 | | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | 524 | | |
552 | 525 | | |
553 | 526 | | |
554 | 527 | | |
555 | | - | |
| 528 | + | |
| 529 | + | |
556 | 530 | | |
557 | 531 | | |
558 | 532 | | |
559 | 533 | | |
560 | 534 | | |
561 | | - | |
| 535 | + | |
| 536 | + | |
562 | 537 | | |
563 | 538 | | |
564 | 539 | | |
| |||
569 | 544 | | |
570 | 545 | | |
571 | 546 | | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | 547 | | |
578 | 548 | | |
579 | 549 | | |
| |||
582 | 552 | | |
583 | 553 | | |
584 | 554 | | |
585 | | - | |
| 555 | + | |
| 556 | + | |
586 | 557 | | |
587 | 558 | | |
588 | 559 | | |
589 | 560 | | |
590 | 561 | | |
591 | | - | |
| 562 | + | |
| 563 | + | |
592 | 564 | | |
593 | 565 | | |
594 | 566 | | |
| |||
600 | 572 | | |
601 | 573 | | |
602 | 574 | | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | 575 | | |
609 | 576 | | |
610 | 577 | | |
611 | 578 | | |
612 | | - | |
| 579 | + | |
| 580 | + | |
613 | 581 | | |
614 | 582 | | |
615 | 583 | | |
616 | 584 | | |
617 | 585 | | |
618 | | - | |
| 586 | + | |
| 587 | + | |
619 | 588 | | |
620 | 589 | | |
621 | 590 | | |
| |||
Lines changed: 1 addition & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | 135 | | |
141 | 136 | | |
142 | 137 | | |
| |||
0 commit comments