Commit 468b690
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.
-->
This PR optimizes the `array_distinct` function by batching value
conversions and utilizing a `HashSet` for deduplication.
It is a follow-up to #20243.
## What changes are included in this PR?
This PR optimizes `array_distinct` by:
1. Converting all values to rows in a single batch rather than
individually.
2. Using a HashSet to deduplicate values for each list.
### Benchmark
```
group main optimized
----- ---- ---------
array_distinct/high_duplicate/10 2.66 855.1±28.18µs ? ?/sec 1.00 321.9±8.70µs ? ?/sec
array_distinct/high_duplicate/100 2.21 6.4±0.13ms ? ?/sec 1.00 2.9±0.09ms ? ?/sec
array_distinct/high_duplicate/50 2.14 3.2±0.05ms ? ?/sec 1.00 1478.3±41.90µs ? ?/sec
array_distinct/low_duplicate/10 2.73 1017.3±44.67µs ? ?/sec 1.00 372.5±17.33µs ? ?/sec
array_distinct/low_duplicate/100 1.32 4.4±0.13ms ? ?/sec 1.00 3.3±0.15ms ? ?/sec
array_distinct/low_duplicate/50 1.55 2.6±0.06ms ? ?/sec 1.00 1689.0±94.15µs ? ?/sec
```
<!--
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?
<!--
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)?
-->
Yes, unit tests exist and pass.
## Are there any user-facing changes?
Yes, there is a slight change in the output order. This new behavior is
consistent with `array_union` and `array_intersect`, where the output
order is more intuitive as it preserves the original order of elements
in the array.
<!--
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.
-->
---------
Co-authored-by: lyne7-sc <lilinfeng0310@gmail.com>array_distinct with batched row conversion (#20364)1 parent ea51d90 commit 468b690
File tree
3 files changed
+139
-34
lines changed- datafusion
- functions-nested
- benches
- src
- sqllogictest/test_files
3 files changed
+139
-34
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
100 | 143 | | |
101 | 144 | | |
102 | 145 | | |
| |||
164 | 207 | | |
165 | 208 | | |
166 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
167 | 258 | | |
168 | 259 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
38 | | - | |
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
| |||
264 | 262 | | |
265 | 263 | | |
266 | 264 | | |
267 | | - | |
| 265 | + | |
268 | 266 | | |
269 | 267 | | |
270 | 268 | | |
| |||
278 | 276 | | |
279 | 277 | | |
280 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
281 | 285 | | |
282 | 286 | | |
283 | 287 | | |
| |||
527 | 531 | | |
528 | 532 | | |
529 | 533 | | |
| 534 | + | |
530 | 535 | | |
531 | | - | |
| 536 | + | |
532 | 537 | | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
540 | 549 | | |
541 | 550 | | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
552 | 563 | | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
| 564 | + | |
| 565 | + | |
558 | 566 | | |
559 | | - | |
560 | | - | |
561 | | - | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
562 | 576 | | |
563 | 577 | | |
564 | | - | |
565 | | - | |
| 578 | + | |
| 579 | + | |
566 | 580 | | |
567 | 581 | | |
568 | 582 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6832 | 6832 | | |
6833 | 6833 | | |
6834 | 6834 | | |
6835 | | - | |
| 6835 | + | |
6836 | 6836 | | |
6837 | 6837 | | |
6838 | 6838 | | |
| |||
6864 | 6864 | | |
6865 | 6865 | | |
6866 | 6866 | | |
6867 | | - | |
| 6867 | + | |
6868 | 6868 | | |
6869 | 6869 | | |
6870 | 6870 | | |
| |||
0 commit comments