Repository navigation
Commit ff677c4
authored
fix: Fix peak memory display in
## 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.
-->
See reproducer in `datafusion-cli`:
```sh
yongting@Yongtings-MacBook-Pro-2 ~/C/d/datafusion (hj-mem-fix *)> datafusion-cli
DataFusion CLI v54.0.0
> set datafusion.explain.analyze_categories = 'bytes';
0 row(s) fetched.
Elapsed 0.001 seconds.
> explain analyze
select *
from generate_series(100000000) as t1(v1)
join generate_series(100000000) as t2(v1)
on t1.v1=t2.v1;
+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
| plan_type | plan |
+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
| Plan with Metrics | HashJoinExec: mode=Partitioned, join_type=Inner, on=[(v1@0, v1@0)], metrics=[output_bytes=1526.7 MB, build_mem_used=2.80 B] |
| | RepartitionExec: partitioning=Hash([v1@0], 14), input_partitions=1, maintains_sort_order=true, metrics=[output_bytes=763.4 MB, spilled_bytes=0.0 B] |
| | ProjectionExec: expr=[value@0 as v1], metrics=[output_bytes=763.0 MB] |
| | LazyMemoryExec: partitions=1, batch_generators=[generate_series: start=0, end=100000000, batch_size=8192], metrics=[output_bytes=763.0 MB] |
| | RepartitionExec: partitioning=Hash([v1@0], 14), input_partitions=1, maintains_sort_order=true, metrics=[output_bytes=763.4 MB, spilled_bytes=0.0 B] |
| | ProjectionExec: expr=[value@0 as v1], metrics=[output_bytes=763.0 MB] |
| | LazyMemoryExec: partitions=1, batch_generators=[generate_series: start=0, end=100000000, batch_size=8192], metrics=[output_bytes=763.0 MB] |
| | |
+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row(s) fetched.
Elapsed 1.040 seconds.
```
See `HashJoinExec: ... build_mem_used=2.80 B`, it actually means 2.8
billion bytes, but it looks quite misleading. This PR fixes it:
```sh
+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
| plan_type | plan |
+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------+
| Plan with Metrics | HashJoinExec: mode=Partitioned, join_type=Inner, on=[(v1@0, v1@0)], metrics=[output_bytes=1526.7 MB, build_mem_used=2.6 GB]
```
The reason is those metrics are tracking peak memory usage for a
operator in the query lifecycle, so it's using `Gauge` metrics type, but
how to choose display format become tricky (bytes or count?)
This PR adds a new `Metric` type, that wraps the existing `Gauge`, and
use it to represent 'gauge for memory bytes', this fixes the bytes
display issue.
## What changes are included in this PR?
<!--
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.
-->
1. Introduce `MetricValue::PeakMemoryUsage` to address the above issue
2. Use this metric type for applicable metrics
3. Add slts for testing.
## 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
4. 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?
<!--
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.
-->EXPLAIN ANALYZE for multiple operators (#23140)1 parent 32e27ac commit ff677c4
12 files changed
Lines changed: 330 additions & 14 deletions
File tree
- datafusion
- ffi/src/physical_expr
- physical-expr-common/src/metrics
- physical-plan/src
- aggregates
- joins
- sort_merge_join
- sqllogictest/test_files
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
131 | 134 | | |
132 | 135 | | |
133 | 136 | | |
| |||
170 | 173 | | |
171 | 174 | | |
172 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
173 | 180 | | |
174 | 181 | | |
175 | 182 | | |
| |||
425 | 432 | | |
426 | 433 | | |
427 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
428 | 439 | | |
429 | 440 | | |
430 | 441 | | |
| |||
481 | 492 | | |
482 | 493 | | |
483 | 494 | | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
484 | 499 | | |
485 | 500 | | |
486 | 501 | | |
| |||
624 | 639 | | |
625 | 640 | | |
626 | 641 | | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
627 | 649 | | |
628 | 650 | | |
629 | 651 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
252 | 269 | | |
253 | 270 | | |
254 | 271 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| 312 | + | |
312 | 313 | | |
313 | 314 | | |
314 | 315 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
672 | 672 | | |
673 | 673 | | |
674 | 674 | | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
675 | 682 | | |
676 | 683 | | |
677 | 684 | | |
| |||
744 | 751 | | |
745 | 752 | | |
746 | 753 | | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
747 | 761 | | |
748 | 762 | | |
749 | 763 | | |
| |||
810 | 824 | | |
811 | 825 | | |
812 | 826 | | |
813 | | - | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
814 | 830 | | |
815 | 831 | | |
816 | 832 | | |
| |||
833 | 849 | | |
834 | 850 | | |
835 | 851 | | |
836 | | - | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
837 | 855 | | |
838 | 856 | | |
839 | 857 | | |
| |||
875 | 893 | | |
876 | 894 | | |
877 | 895 | | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
878 | 900 | | |
879 | 901 | | |
880 | 902 | | |
| |||
933 | 955 | | |
934 | 956 | | |
935 | 957 | | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
936 | 964 | | |
937 | 965 | | |
938 | 966 | | |
| |||
1029 | 1057 | | |
1030 | 1058 | | |
1031 | 1059 | | |
| 1060 | + | |
1032 | 1061 | | |
1033 | 1062 | | |
1034 | 1063 | | |
| |||
1064 | 1093 | | |
1065 | 1094 | | |
1066 | 1095 | | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
1067 | 1100 | | |
1068 | 1101 | | |
1069 | 1102 | | |
| |||
1525 | 1558 | | |
1526 | 1559 | | |
1527 | 1560 | | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
1528 | 1573 | | |
1529 | 1574 | | |
1530 | 1575 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
527 | 527 | | |
528 | 528 | | |
529 | 529 | | |
530 | | - | |
531 | | - | |
| 530 | + | |
532 | 531 | | |
533 | 532 | | |
534 | 533 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
198 | | - | |
| 197 | + | |
199 | 198 | | |
200 | 199 | | |
201 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
775 | 775 | | |
776 | 776 | | |
777 | 777 | | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
778 | 781 | | |
779 | 782 | | |
780 | 783 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
363 | | - | |
| 363 | + | |
| 364 | + | |
364 | 365 | | |
365 | 366 | | |
366 | 367 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
| 49 | + | |
| 50 | + | |
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1798 | 1798 | | |
1799 | 1799 | | |
1800 | 1800 | | |
1801 | | - | |
1802 | | - | |
1803 | | - | |
| 1801 | + | |
| 1802 | + | |
1804 | 1803 | | |
1805 | 1804 | | |
1806 | 1805 | | |
| |||
0 commit comments