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

*: add stats version in slow_query and slow log. #10082

Merged
merged 24 commits into from
Apr 15, 2019

Conversation

crazycs520
Copy link
Contributor

@crazycs520 crazycs520 commented Apr 9, 2019

What problem does this PR solve?

  1. Add Stats to slow log. Stats print out format is tableName:StatsVersion.
# Time: 2019-04-09-13:53:37.043173 +0800
# Txn_start_ts: 407578664500723713
# User: root@::1
# Conn_ID: 1
# Query_time: 0.001032843
# Request_count: 2 Total_keys: 8 Process_keys: 5
# DB: test
# Index_ids: [1]
# Is_internal: false
# Digest: adf2bf4c2ef7681db7ed1d3562640468b1dc2f73c1848b1566a653becbfa2434
# Stats: t2:407578618099925000,t1:407578618126139396
select t1.a,t1.b from t1 join t2 on t1.a!=t2.b;
  1. Add Stats to slow_query.
mysql root@localhost:INFORMATION_SCHEMA> select `Query`,stats from `SLOW_QUERY` where stats != "" and `Is_internal` = false;
+-------------------------------------------------------------+---------------------------------------------+
| Query                                                       | stats                                       |
+-------------------------------------------------------------+---------------------------------------------+
| select t1.a,t1.b from t1 join t2 on t1.a!=t2.b;             | t2:407578618099925000,t1:407578618126139396 |
| select t1.a,t1.b from t1 join t2 on t1.a!=t2.b;             | t2:407578618099925000,t1:407578618126139396 |
| SELECT CONCAT("'", user, "'@'",host,"'") FROM mysql.user;   | user:0                                      |
| SELECT name from mysql.help_topic WHERE name like "SHOW %"; | help_topic:0                                |
| SELECT CONCAT("'", user, "'@'",host,"'") FROM mysql.user;   | user:0                                      |
| SELECT name from mysql.help_topic WHERE name like "SHOW %"; | help_topic:0                                |
+-------------------------------------------------------------+---------------------------------------------+
6 rows in set

What is changed and how it works?

Add StatsVersion to StatsInfo and remove UsePseudoStats field, then if StatsVersion == 0, means use pseudo stats.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

Related changes

@crazycs520 crazycs520 requested a review from zz-jason April 9, 2019 06:15
@crazycs520
Copy link
Contributor Author

@zz-jason , @lamxTyler PTAL

Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

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

LGTM

@alivxxx alivxxx added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 9, 2019
if a.Plan == nil {
return nil
}
physicalPlan, ok := a.Plan.(plannercore.PhysicalPlan)
Copy link
Member

Choose a reason for hiding this comment

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

Some other plan, for example Insert/Update, they are not PhysicalPlan but can have StatsInfo as well. For example, insert into .. select ..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

em... any advice for this?

Copy link
Member

Choose a reason for hiding this comment

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

how about specially handle these plans?

sessionctx/variable/session.go Outdated Show resolved Hide resolved
planner/property/stats_info.go Outdated Show resolved Hide resolved
sessionctx/variable/session.go Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Apr 10, 2019

Codecov Report

Merging #10082 into master will increase coverage by 0.0197%.
The diff coverage is 100%.

@@               Coverage Diff                @@
##             master     #10082        +/-   ##
================================================
+ Coverage   77.9619%   77.9816%   +0.0197%     
================================================
  Files           405        405                
  Lines         82244      82304        +60     
================================================
+ Hits          64119      64182        +63     
  Misses        13392      13392                
+ Partials       4733       4730         -3

zz-jason
zz-jason previously approved these changes Apr 10, 2019
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

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

1 similar comment
@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

1 similar comment
@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-sqllogic-test-2

@crazycs520
Copy link
Contributor Author

/run-unit-test

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-code_coverage

@crazycs520
Copy link
Contributor Author

/run-mybatis-test

@crazycs520
Copy link
Contributor Author

/run-all-tests

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

@crazycs520 crazycs520 merged commit 7666f68 into pingcap:master Apr 15, 2019
@crazycs520 crazycs520 deleted the slow-log-stats-version branch April 15, 2019 10:04
crazycs520 added a commit to crazycs520/tidb that referenced this pull request Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/server status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants