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: union scan refactor, introduce the the mem rows iterator #44874

Merged
merged 9 commits into from
Jun 27, 2023

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented Jun 21, 2023

What problem does this PR solve?

Issue Number: ref #43249

Problem Summary:

This is the optimization of the UnionScan, part1

What is changed and how it works?

In the old code, all the mem buff rows are drained in the unionscan.Open() stage.
The commit try to introduce a memRowsIter data struct, the memRowsIter is built at the Open stage, but it does not fetch data in some cases(Now just handle the table reader and !desc).
Instead, the memRowsIter provide the Next() method for the caller to call it at the Next() stage.

Check List

Tests

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

Change the test case to 'select * from t limit 1'

git diff
diff --git a/executor/union_scan_test.go b/executor/union_scan_test.go
index ecc3e0b6bb..ca4c297a78 100644
--- a/executor/union_scan_test.go
+++ b/executor/union_scan_test.go
@@ -567,7 +567,7 @@ c6 datetime);`)
        b.ReportAllocs()
        b.ResetTimer()
        for i := 0; i < b.N; i++ {
-               tk.MustQuery("select * from t_us where c1 = '12345'").Check(testkit.Rows())
+               tk.MustQuery("select c1 from t_us limit 1").Check(testkit.Rows("54321"))
        }
        b.StopTimer()
 }

go test -run XXX -tags intest -bench BenchmarkUnionScan -cpuprofile cpu1.out -benchtime 45s -benchmem
Before:
12007           4545021 ns/op         2875056 B/op      41671 allocs/op
After:
15372           3704359 ns/op          326602 B/op      10063 allocs/op

And flamegraph before vs after:

image
image

  • 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

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 21, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 21, 2023
@tiancaiamao tiancaiamao marked this pull request as ready for review June 21, 2023 08:22
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 21, 2023
@hawkingrei
Copy link
Member

/test tiprow_fast_test

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 22, 2023

@hawkingrei: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test build
  • /test canary-scan-security
  • /test check-dev
  • /test check-dev2
  • /test mysql-test
  • /test pingcap/tidb/canary_ghpr_unit_test
  • /test pull-integration-br-test
  • /test pull-integration-mysql-test
  • /test unit-test

Use /test all to run the following jobs that were automatically triggered:

  • pingcap/tidb/ghpr_build
  • pingcap/tidb/ghpr_check
  • pingcap/tidb/ghpr_check2
  • pingcap/tidb/ghpr_mysql_test
  • pingcap/tidb/ghpr_unit_test

In response to this:

/test tiprow_fast_test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tiancaiamao
Copy link
Contributor Author

/retest

@tiprow
Copy link

tiprow bot commented Jun 26, 2023

@tiancaiamao: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tiancaiamao
Copy link
Contributor Author

/retest

@tiprow
Copy link

tiprow bot commented Jun 26, 2023

@tiancaiamao: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tiancaiamao tiancaiamao requested a review from lcwangchao June 26, 2023 13:02
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jun 27, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 27, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lcwangchao, xhebox

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 27, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 27, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-06-27 03:24:25.27314399 +0000 UTC m=+678030.674394441: ☑️ agreed by lcwangchao.
  • 2023-06-27 07:52:11.870120593 +0000 UTC m=+694097.271371041: ☑️ agreed by xhebox.

@tiancaiamao
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 27, 2023

@tiancaiamao: We have migrated to builtin LGTM and approve plugins for reviewing.

Please use /approve when you want approve this pull request.

The changes announcement: LGTM plugin changes

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 2023
@ti-chi-bot ti-chi-bot bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 2023
@ti-chi-bot ti-chi-bot bot merged commit 9d42922 into pingcap:master Jun 27, 2023
@tiancaiamao tiancaiamao deleted the union-scan branch June 27, 2023 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants