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

executor: show operators' memory consumption in results of EXPLAIN ANALYZE #11334

Merged
merged 13 commits into from
Jul 24, 2019

Conversation

qw4990
Copy link
Contributor

@qw4990 qw4990 commented Jul 19, 2019

What problem does this PR solve?

Add a new column named memory in the results of EXPLAIN ANALYZE to display memory consumption of operators.

After this PR, you can see:

mysql> explain analyze select * from t order by v limit 5;
+----------------------+-------+------+------------------------------------------------------------+----------------------------------+-----------+
| id                   | count | task | operator info                                              | execution info                   | memory    |
+----------------------+-------+------+------------------------------------------------------------+----------------------------------+-----------+
| TopN_9               | 5.00  | root | test.t.v:asc, offset:0, count:5                            | time:0s, loops:0, rows:0         | 800 Bytes |
| └─TableReader_17     | 5.00  | root | data:TableScan_16                                          | time:261.366µs, loops:2, rows:5  | 131 Bytes |
|   └─TableScan_16     | 5.00  | cop  | table:t, range:[-inf,+inf], keep order:false, stats:pseudo | time:136.023µs, loops:6, rows:5  | N/A         |
+----------------------+-------+------+------------------------------------------------------------+----------------------------------+-----------+

mysql> explain analyze select /*+ TIDB_HJ(t1, t2) */ t1.k from t t1, t t2 where t1.v = t2.v+1;
+--------------------------+-------+------+----------------------------------------------------------------------------+----------------------------------+---------------+
| id                       | count | task | operator info                                                              | execution info                   | memory        |
+--------------------------+-------+------+----------------------------------------------------------------------------+----------------------------------+---------------+
| Projection_8             | 6.25  | root | test.t1.k                                                                  | time:0s, loops:0, rows:0         | N/A             |
| └─HashLeftJoin_9         | 6.25  | root | inner join, inner:Projection_14, equal:[eq(test.t1.v, plus(test.t2.v, 1))] | time:280.29µs, loops:1, rows:0   | 8.61328125 KB |
|   ├─TableReader_13       | 5.00  | root | data:TableScan_12                                                          | time:171.233µs, loops:2, rows:5  | 131 Bytes     |
|   │ └─TableScan_12       | 5.00  | cop  | table:t1, range:[-inf,+inf], keep order:false, stats:pseudo                | time:117.687µs, loops:6, rows:5  | N/A             |
|   └─Projection_14        | 5.00  | root | test.t2.v, plus(test.t2.v, 1)                                              | time:0s, loops:0, rows:0         | N/A             |
|     └─TableReader_16     | 5.00  | root | data:TableScan_15                                                          | time:149.443µs, loops:2, rows:5  | 121 Bytes     |
|       └─TableScan_15     | 5.00  | cop  | table:t2, range:[-inf,+inf], keep order:false, stats:pseudo                | time:92.487µs, loops:6, rows:5   | N/A             |
+--------------------------+-------+------+----------------------------------------------------------------------------+----------------------------------+---------------+

Pipeliner operators like Selection or Projection have no memory consumption.
Cop-tasks' memory consumption will be added by another PR.

What is changed and how it works?

Main changes:

  1. Don't detach trackers when closing executor otherwise we can't get their memory consumption Information and all trackers will be cleaned by ResetContextOfStmt when the next query comes;
  2. Add a new column named memory in results of EXPLAIN ANALYZE;
  3. Rename some trackers' labels;

Check List

Tests

  • Unit test

@codecov
Copy link

codecov bot commented Jul 19, 2019

Codecov Report

Merging #11334 into master will increase coverage by 0.0279%.
The diff coverage is 100%.

@@               Coverage Diff                @@
##             master     #11334        +/-   ##
================================================
+ Coverage   81.3024%   81.3303%   +0.0279%     
================================================
  Files           423        423                
  Lines         90616      90591        -25     
================================================
+ Hits          73673      73678         +5     
+ Misses        11619      11596        -23     
+ Partials       5324       5317         -7

executor/distsql.go Show resolved Hide resolved
executor/table_reader.go Show resolved Hide resolved
planner/core/common_plans.go Outdated Show resolved Hide resolved
@qw4990 qw4990 requested review from lysu and wshwsh12 July 22, 2019 02:28
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 23, 2019
@@ -415,14 +417,16 @@ func (e *IndexLookUpExecutor) startIndexWorker(ctx context.Context, kvRanges []k
e.dagPB.CollectExecutionSummaries = &collExec
}

tracker := memory.NewTracker(stringutil.StringerStr("InnerWorker"), e.ctx.GetSessionVars().MemQuotaIndexLookupReader)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ InnerWorker/ IndexWorker ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@@ -486,7 +488,8 @@ func (e *IndexLookUpExecutor) startTableWorker(ctx context.Context, workCh <-cha
keepOrder: e.keepOrder,
handleIdx: e.handleIdx,
isCheckOp: e.isCheckOp,
memTracker: memory.NewTracker(tableWorkerLabel, -1),
memTracker: memory.NewTracker(stringutil.StringerStr(fmt.Sprintf("worker_%v", i)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ worker/ TableWorker ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@@ -486,7 +488,8 @@ func (e *IndexLookUpExecutor) startTableWorker(ctx context.Context, workCh <-cha
keepOrder: e.keepOrder,
handleIdx: e.handleIdx,
isCheckOp: e.isCheckOp,
memTracker: memory.NewTracker(tableWorkerLabel, -1),
memTracker: memory.NewTracker(stringutil.StringerStr(fmt.Sprintf("worker_%v", i)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better not alloc this for normal execution

stringutil.MemoizeStr(func() string { return "worker_" + strconv.Itoa(i) })

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the other stringutil.StringerStr(xx) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that seems cannot be avoided :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other stringutil.StringerStr(xx) has no sprintf, so it's OK? 🤔

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@qw4990
Copy link
Contributor Author

qw4990 commented Jul 24, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Jul 24, 2019

cherry pick to release-2.1 failed

sre-bot pushed a commit that referenced this pull request Jul 25, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Apr 7, 2020

It seems that, not for sure, we failed to cherry-pick this commit to release-2.1. Please comment '/run-cherry-picker' to try to trigger the cherry-picker if we did fail to cherry-pick this commit before. @qw4990 PTAL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants