Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inaccurate memory tracking in IndexJoin/IndexHashJoin #34417

Closed
Tracked by #33877
wshwsh12 opened this issue May 6, 2022 · 0 comments · Fixed by #34418
Closed
Tracked by #33877

Fix inaccurate memory tracking in IndexJoin/IndexHashJoin #34417

wshwsh12 opened this issue May 6, 2022 · 0 comments · Fixed by #34418
Assignees
Labels
affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 component/executor severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@wshwsh12
Copy link
Contributor

wshwsh12 commented May 6, 2022

Running the query q3,q7,q8 of workload tpch-50g, TiDB will tracked memory usgae more than actual memory usage.

For example, q8:
Plan:

+---------------------------------------------------------------+-------------+----------+-----------+---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------+---------+
| id                                                            | estRows     | actRows  | task      | access object                                           | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | operator info                                                                                                                                                                                                                                                                                                      | memory                  | disk    |
+---------------------------------------------------------------+-------------+----------+-----------+---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------+---------+
| Sort_30                                                       | 724.73      | 2        | root      |                                                         | time:33s, loops:2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | Column#62                                                                                                                                                                                                                                                                                                          | 3.56 KB(Total: 5.93 GB) | 0 Bytes |
| └─Projection_32                                               | 724.73      | 2        | root      |                                                         | time:33s, loops:3, Concurrency:OFF                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Column#62, div(Column#64, Column#65)->Column#66                                                                                                                                                                                                                                                                    | 3.18 KB                 | N/A     |
|   └─HashAgg_33                                                | 724.73      | 2        | root      |                                                         | time:33s, loops:3, partial_worker:{wall_time:32.964323903s, concurrency:5, task_num:121, tot_wait:2m44.77989667s, tot_exec:40.431978ms, tot_time:2m44.820423367s, max:32.964285388s, p95:32.964285388s}, final_worker:{wall_time:32.964357362s, concurrency:5, task_num:10, tot_wait:2m44.821470135s, tot_exec:132.889µs, tot_time:2m44.821611492s, max:32.964335448s, p95:32.964335448s}                                                                                                                                                                                        | group by:Column#78, funcs:sum(Column#75)->Column#64, funcs:sum(Column#76)->Column#65, funcs:firstrow(Column#77)->Column#62                                                                                                                                                                                         | 1.16 MB                 | N/A     |
|     └─Projection_122                                          | 66604.30    | 120978   | root      |                                                         | time:33s, loops:122, Concurrency:5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | case(eq(test.nation.n_name, INDIA), mul(test.lineitem.l_extendedprice, minus(1, test.lineitem.l_discount)), 0)->Column#75, mul(test.lineitem.l_extendedprice, minus(1, test.lineitem.l_discount))->Column#76, extract(YEAR, test.orders.o_orderdate)->Column#77, extract(YEAR, test.orders.o_orderdate)->Column#78 | 1.14 MB                 | N/A     |
|       └─Projection_34                                         | 66604.30    | 120978   | root      |                                                         | time:33s, loops:122, Concurrency:5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | test.lineitem.l_extendedprice, test.lineitem.l_discount, test.orders.o_orderdate, test.nation.n_name                                                                                                                                                                                                               | 1.17 MB                 | N/A     |
|         └─HashJoin_44                                         | 66604.30    | 120978   | root      |                                                         | time:33s, loops:122, build_hash_table:{total:4.16ms, fetch:4.14ms, build:24.5µs}, probe:{concurrency:5, total:2m44.8s, max:33s, probe:148.7ms, fetch:2m44.7s}                                                                                                                                                                                                                                                                                                                                                                                                                    | inner join, equal:[eq(test.supplier.s_nationkey, test.nation.n_nationkey)]                                                                                                                                                                                                                                         | 25.6 KB                 | 0 Bytes |
|           ├─TableReader_120(Build)                            | 25.00       | 25       | root      |                                                         | time:4.05ms, loops:2, cop_task: {num: 1, max: 4.97ms, proc_keys: 25, rpc_num: 1, rpc_time: 4.96ms, copr_cache: disabled}                                                                                                                                                                                                                                                                                                                                                                                                                                                         | data:TableFullScan_119                                                                                                                                                                                                                                                                                             | 796 Bytes               | N/A     |
|           │ └─TableFullScan_119                               | 25.00       | 25       | cop[tikv] | table:n2                                                | tikv_task:{time:0s, loops:1}, scan_detail: {total_process_keys: 25, total_process_keys_size: 3109, total_keys: 26, rocksdb: {delete_skipped_count: 0, key_skipped_count: 25, block: {cache_hit_count: 9, read_count: 0, read_byte: 0 Bytes}}}                                                                                                                                                                                                                                                                                                                                    | keep order:false                                                                                                                                                                                                                                                                                                   | N/A                     | N/A     |
|           └─IndexHashJoin_52(Probe)                           | 66604.30    | 120978   | root      |                                                         | time:33s, loops:122, inner:{total:2.42s, concurrency:5, task:13, construct:186ms, fetch:2.04s, build:26.3ms, join:193.5ms}                                                                                                                                                                                                                                                                                                                                                                                                                                                       | inner join, inner:TableReader_47, outer key:test.lineitem.l_suppkey, inner key:test.supplier.s_suppkey, equal cond:eq(test.lineitem.l_suppkey, test.supplier.s_suppkey)                                                                                                                                            | 23.9 MB                 | N/A     |
|             ├─IndexJoin_63(Build)                             | 66421.00    | 120978   | root      |                                                         | time:32.8s, loops:124, inner:{total:1m19.7s, concurrency:5, task:719, construct:26.7s, fetch:52.9s, build:65.8ms}, probe:4.88s                                                                                                                                                                                                                                                                                                                                                                                                                                                   | inner join, inner:TableReader_59, outer key:test.lineitem.l_partkey, inner key:test.part.p_partkey, equal cond:eq(test.lineitem.l_partkey, test.part.p_partkey)                                                                                                                                                    | 3.33 GB                 | N/A     |
|             │ ├─IndexHashJoin_76(Build)                       | 115892.25   | 18204710 | root      |                                                         | time:28.6s, loops:17782, inner:{total:2m35.7s, concurrency:5, task:186, construct:5.44s, fetch:2m4.9s, build:1.27s, join:25.3s}                                                                                                                                                                                                                                                                                                                                                                                                                                                  | inner join, inner:IndexLookUp_73, outer key:test.orders.o_orderkey, inner key:test.lineitem.l_orderkey, equal cond:eq(test.orders.o_orderkey, test.lineitem.l_orderkey)                                                                                                                                            | 2.31 GB                 | N/A     |
|             │ │ ├─HashJoin_86(Build)                          | 28550.75    | 4552322  | root      |                                                         | time:3.71s, loops:4451, build_hash_table:{total:1.18s, fetch:440.7ms, build:734.8ms}, probe:{concurrency:5, total:2m34.9s, max:31s, probe:2m27.7s, fetch:7.17s}                                                                                                                                                                                                                                                                                                                                                                                                                  | inner join, equal:[eq(test.customer.c_custkey, test.orders.o_custkey)]                                                                                                                                                                                                                                             | 82.3 MB                 | 0 Bytes |
|             │ │ │ ├─HashJoin_88(Build)                        | 1875.00     | 1499409  | root      |                                                         | time:461.3ms, loops:1468, build_hash_table:{total:1.06ms, fetch:1.05ms, build:7.86µs}, probe:{concurrency:5, total:5.87s, max:1.17s, probe:3.64s, fetch:2.23s}                                                                                                                                                                                                                                                                                                                                                                                                                   | inner join, equal:[eq(test.nation.n_nationkey, test.customer.c_nationkey)]                                              |             │ │ │ │ │   └─TableFullScan_102                   | 25.00       | 25       | cop[tikv] | table:n1                                                | tikv_task:{time:0s, loops:1}, scan_detail: {total_process_keys: 25, total_process_keys_size: 3109, total_keys: 26, rocksdb: {delete_skipped_count: 0, key_skipped_count: 25, block: {cache_hit_count: 9, read_count: 0, read_byte: 0 Bytes}}}                                                                                                                                                                                                                                                                                                                                    | keep order:false                                                                                                                                                                                                                                                                                                   | N/A                     | N/A     |
|             │ │ │ │ └─TableReader_108(Probe)                  | 7500000.00  | 7500000  | root      |                                                         | time:449.1ms, loops:7332, cop_task: {num: 16, max: 547.7ms, min: 1.46ms, avg: 456.9ms, p95: 547.7ms, max_proc_keys: 515357, p95_proc_keys: 515357, tot_proc: 6.78s, tot_wait: 16ms, rpc_num: 16, rpc_time: 7.31s, copr_cache: disabled}                                                                                                                                                                                                                                                                                                                                          | data:TableFullScan_107                                                                                                                                                                                                                                                                                             | 102.3 MB                | N/A     |
|             │ │ │ │   └─TableFullScan_107                     | 7500000.00  | 7500000  | cop[tikv] | table:customer                                          | tikv_task:{proc max:506ms, min:0s, p80:447ms, p95:506ms, iters:7393, tasks:16}, scan_detail: {total_process_keys: 7500000, total_process_keys_size: 1526085547, total_keys: 7500016, rocksdb: {delete_skipped_count: 0, key_skipped_count: 7500000, block: {cache_hit_count: 25052, read_count: 0, read_byte: 0 Bytes}}}                                                                                                                                                                                                                                                         | keep order:false                                                                                                                                                                                                                                                                                                   | N/A                     | N/A     |
|             │ │ │ └─TableReader_111(Probe)                    | 22591411.16 | 22789750 | root      |                                                         | time:1.12s, loops:22183, cop_task: {num: 108, max: 926.4ms, min: 119.2ms, avg: 720.7ms, p95: 804.8ms, max_proc_keys: 700329, p95_proc_keys: 700213, tot_proc: 1m16.4s, tot_wait: 85ms, rpc_num: 108, rpc_time: 1m17.8s, copr_cache: disabled}                                                                                                                                                                                                                                                                                                                                    | data:Selection_110                                                                                                                                                                                                                                                                                                 | 73.3 MB                 | N/A     |
|             │ │ │   └─Selection_110                           | 22591411.16 | 22789750 | cop[tikv] |                                                         | tikv_task:{proc max:878ms, min:114ms, p80:731ms, p95:770ms, iters:73727, tasks:108}, scan_detail: {total_process_keys: 75000000, total_process_keys_size: 11391895327, total_keys: 75000108, rocksdb: {delete_skipped_count: 0, key_skipped_count: 75000000, block: {cache_hit_count: 190260, read_count: 0, read_byte: 0 Bytes}}}                                                                                                                                                                                                                                               | ge(test.orders.o_orderdate, 1995-01-01 00:00:00.000000), le(test.orders.o_orderdate, 1996-12-31 00:00:00.000000)                                                                                                                                                                                                   | N/A                     | N/A     |
|             │ │ │     └─TableFullScan_109                     | 75000000.00 | 75000000 | cop[tikv] | table:orders                                            | tikv_task:{proc max:833ms, min:105ms, p80:674ms, p95:721ms, iters:73727, tasks:108}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | keep order:false                                                                                                                                                                                                                                                                                                   | N/A                     | N/A     |
|             │ │ └─IndexLookUp_73(Probe)                       | 4.06        | 18204710 | root      |                                                         | time:2m0.4s, loops:18054, index_task: {total_time: 1m19.8s, fetch_handle: 1m19.7s, build: 2.63ms, wait: 22.6ms}, table_task: {total_time: 2m51.3s, num: 1623, concurrency: 930}                                                                                                                                                                                                                                                                                                                                                                                                  |                                                                                                                                                                                                                                                                                                                    | 525.4 KB                | N/A     |
|             │ │   ├─IndexRangeScan_71(Build)                  | 4.06        | 18204710 | cop[tikv] | table:lineitem, index:PRIMARY(L_ORDERKEY, L_LINENUMBER) | time:1m18.1s, loops:18535, cop_task: {num: 734, max: 703.5ms, min: 879.1µs, avg: 233.6ms, p95: 521.5ms, max_proc_keys: 59090, p95_proc_keys: 57692, tot_proc: 2m44.9s, tot_wait: 324ms, rpc_num: 734, rpc_time: 2m51.5s, copr_cache: disabled}, tikv_task:{proc max:680ms, min:0s, p80:342ms, p95:505ms, iters:21070, tasks:734}, scan_detail: {total_process_keys: 18204710, total_process_keys_size: 964849630, total_keys: 22757057, rocksdb: {delete_skipped_count: 0, key_skipped_count: 18204710, block: {cache_hit_count: 45513550, read_count: 0, read_byte: 0 Bytes}}}  | range: decided by [eq(test.lineitem.l_orderkey, test.orders.o_orderkey)], keep order:false                                                                                                                                                                                                                         | N/A                     | N/A     |
|             │ │   └─TableRowIDScan_72(Probe)                  | 4.06        | 18204710 | cop[tikv] | table:lineitem                                          | time:2m42s, loops:20707, cop_task: {num: 2678, max: 277.6ms, min: 674.8µs, avg: 75.5ms, p95: 201.8ms, max_proc_keys: 21009, p95_proc_keys: 20454, tot_proc: 3m11s, tot_wait: 482ms, rpc_num: 2678, rpc_time: 3m22.2s, copr_cache: disabled}, tikv_task:{proc max:262ms, min:0s, p80:119ms, p95:187ms, iters:30026, tasks:2678}, scan_detail: {total_process_keys: 18204710, total_process_keys_size: 3616275028, total_keys: 21906854, rocksdb: {delete_skipped_count: 0, key_skipped_count: 17629593, block: {cache_hit_count: 40673134, read_count: 0, read_byte: 0 Bytes}}}   | keep order:false                                                                                                                                                                                                                                                                                                   | N/A                     | N/A     |
|             │ └─TableReader_59(Probe)                         | 0.01        | 120828   | root      |                                                         | time:38.5s, loops:1438, cop_task: {num: 11504, max: 89.7ms, min: 1.13ms, avg: 38.7ms, p95: 57.6ms, max_proc_keys: 1808, p95_proc_keys: 1721, tot_proc: 6m42.4s, tot_wait: 995ms, rpc_num: 11504, rpc_time: 7m24.5s, copr_cache: disabled}                                                                                                                                                                                                                                                                                                                                        | data:Selection_58                                                                                                                                                                                                                                                                                                  | N/A                     | N/A     |
|             │   └─Selection_58                                | 0.01        | 120828   | cop[tikv] |                                                         | tikv_task:{proc max:72ms, min:0s, p80:43ms, p95:53ms, iters:67890, tasks:11504}, scan_detail: {total_process_keys: 18181458, total_process_keys_size: 2971288036, total_keys: 18227694, rocksdb: {delete_skipped_count: 0, key_skipped_count: 92575, block: {cache_hit_count: 103117704, read_count: 0, read_byte: 0 Bytes}}}                                                                                                                                                                                                                                                    | eq(test.part.p_type, "SMALL PLATED COPPER")                                                                                                                                                                                                                                                                        | N/A                     | N/A     |
|             │     └─TableRangeScan_57                         | 1.00        | 18181458 | cop[tikv] | table:part                                              | tikv_task:{proc max:71ms, min:0s, p80:43ms, p95:53ms, iters:67890, tasks:11504}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | range: decided by [test.lineitem.l_partkey], keep order:false                                                                                                                                                                                                                                                      | N/A                     | N/A     |
|             └─TableReader_47(Probe)                           | 1.00        | 114313   | root      |                                                         | time:1.96s, loops:132, cop_task: {num: 13, max: 424.9ms, min: 1.8ms, avg: 147.7ms, p95: 424.9ms, max_proc_keys: 23918, p95_proc_keys: 23918, tot_proc: 1.8s, tot_wait: 2ms, rpc_num: 13, rpc_time: 1.92s, copr_cache: disabled}                                                                                                                                                                                                                                                                                                                                                  | data:TableRangeScan_46                                                                                                                                                                                                                                                                                             | N/A                     | N/A     |
|               └─TableRangeScan_46                             | 1.00        | 114313   | cop[tikv] | table:supplier                                          | tikv_task:{proc max:397ms, min:0s, p80:344ms, p95:397ms, iters:166, tasks:13}, scan_detail: {total_process_keys: 114313, total_process_keys_size: 20736867, total_keys: 118536, rocksdb: {delete_skipped_count: 0, key_skipped_count: 8630, block: {cache_hit_count: 591619, read_count: 0, read_byte: 0 Bytes}}}                                                                                                                                                                                                                                                                | range: decided by [test.lineitem.l_suppkey], keep order:false                                                                                                                                                                                                                                                      | N/A                     | N/A     |
+---------------------------------------------------------------+-------------+----------+-----------+---------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------+---------+

Grafana: (Running the sql 5 times)
image

We can see the memory usage of IndexJoin/IndexHashJoin is more than 2GB, but the actual memory usage is low.

@wshwsh12 wshwsh12 added type/bug The issue is confirmed as a bug. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 component/executor labels May 6, 2022
@wshwsh12 wshwsh12 self-assigned this May 6, 2022
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. labels May 7, 2022
@aytrack aytrack added the sig/execution SIG execution label May 9, 2022
@wshwsh12 wshwsh12 removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. labels May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 component/executor severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants