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, planner, util: optimize query statements summary table by conditional pushdown #27563

Merged
merged 26 commits into from
Sep 28, 2021

Conversation

TszKitLo40
Copy link
Contributor

@TszKitLo40 TszKitLo40 commented Aug 25, 2021

Signed-off-by: Zijie Lu [email protected]

What problem does this PR solve?

Issue Number: close #26379

Bench:
Generate 3000 statements to filling statemens summary , and each SQL length is 10240 byte.

  1. Use loadgen to generated load:
    bin/loadgen payload gen-stmt --stmt-cnt 3000 --query-len 10240 --host 172.16.5.40 --port 4019 --concurrency 10
    The generated SQL is look like this:
    select * from t_gen_stmt_1 where a = 1 or b = 1 or c = 1 union all select * from t_gen_stmt_2 where a = 2 or b = 2 or c = 2 union all ... ... ...

  2. Wait generated statements(SQL) fill in the statemens summary.

  3. Bench the SQL: select * from information_schema.cluster_statements_summary where digest = 'xxx';

Bellow is the bench result compare with the master:

Master This PR
Query duration 2.96s 0.01s

Problem Summary:

What is changed and how it works?

What's Changed:
optimize query statements summary table by avoid decode plan by conditional pushdown
How it Works:
By using conditional pushdown, filter the digest in logical optimization phase.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None.

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Aug 25, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • crazycs520
  • djshow832

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 25, 2021
@TszKitLo40 TszKitLo40 marked this pull request as draft August 25, 2021 02:48
@ti-chi-bot ti-chi-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 25, 2021
@github-actions github-actions bot added the sig/execution SIG execution label Aug 25, 2021
Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

Got panic when i query following query:

select digest from `STATEMENTS_SUMMARY` where digest='';

@TszKitLo40 TszKitLo40 force-pushed the issue26379 branch 2 times, most recently from 1f2d42b to 5421e9d Compare August 26, 2021 08:11
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 26, 2021
…void decode plan by conditional pushdown

Signed-off-by: Zijie Lu <[email protected]>
@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 31, 2021
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 31, 2021
@crazycs520
Copy link
Contributor

/rebuild

Signed-off-by: Zijie Lu <[email protected]>
Signed-off-by: Zijie Lu <[email protected]>
Signed-off-by: Zijie Lu <[email protected]>
@TszKitLo40 TszKitLo40 marked this pull request as ready for review September 7, 2021 06:46
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 7, 2021
@crazycs520
Copy link
Contributor

/run-all-tests

@crazycs520
Copy link
Contributor

@djshow832 @jyz0309 PTAL

@crazycs520
Copy link
Contributor

@qw4990 @djshow832 PTAL

Copy link
Contributor

@djshow832 djshow832 left a comment

Choose a reason for hiding this comment

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

Please modify the PR title: it doesn't avoid decoding plans.

planner/core/memtable_predicate_extractor.go Show resolved Hide resolved
planner/core/rule_column_pruning.go Show resolved Hide resolved
util/stmtsummary/reader.go Show resolved Hide resolved
Comment on lines 1956 to 1957
// Test explain
tk.MustQuery("explain select digest from information_schema.statements_summary where digest is null").Check(testkit.Rows(`Selection_5 8000.00 root isnull(Column#5)`, `└─MemTableScan_6 10000.00 root table:STATEMENTS_SUMMARY `))
Copy link
Contributor

Choose a reason for hiding this comment

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

You can add following test in executor/explainfor_test.go.

func (s *testSuite) TestExplainStatementsSummary(c *C) {
	tk := testkit.NewTestKitWithInit(c, s.store)
	tk.MustQuery("desc select * from information_schema.statements_summary").Check(testkit.Rows(
		`MemTableScan_4 10000.00 root table:STATEMENTS_SUMMARY `))
	tk.MustQuery("desc select * from information_schema.statements_summary where digest is null").Check(testutil.RowsWithSep("|",
		`Selection_5|8000.00|root| isnull(Column#5)`, `└─MemTableScan_6|10000.00|root|table:STATEMENTS_SUMMARY|`))
	tk.MustQuery("desc select * from information_schema.statements_summary where digest = 'abcdefg'").Check(testutil.RowsWithSep(" ",
		`MemTableScan_5 10000.00 root table:STATEMENTS_SUMMARY digests: ["abcdefg"]`))
	tk.MustQuery("desc select * from information_schema.statements_summary where digest in ('a','b','c')").Check(testutil.RowsWithSep(" ",
		`MemTableScan_5 10000.00 root table:STATEMENTS_SUMMARY digests: ["a","b","c"]`))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@TszKitLo40 TszKitLo40 changed the title executor, planner, util: optimize query statements summary table by avoid decode plan by conditional pushdown executor, planner, util: optimize query statements summary table by conditional pushdown Sep 27, 2021
@TszKitLo40
Copy link
Contributor Author

/run-all-tests

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 27, 2021
@crazycs520
Copy link
Contributor

@djshow832 PTAL

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 28, 2021
@djshow832
Copy link
Contributor

Please resolve conflicts @TszKitLo40

@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 28, 2021
@crazycs520
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: aec6347

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Sep 28, 2021
@ti-chi-bot ti-chi-bot merged commit fd73942 into pingcap:master Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. sig/execution SIG execution size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

optimize query statements summary table by avoid decode plan by conditional pushdown
4 participants