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

planner: speed up PhysicalTopN#containVirtualColumn #46812

Merged
merged 1 commit into from
Sep 11, 2023

Conversation

tedyu
Copy link
Contributor

@tedyu tedyu commented Sep 9, 2023

What problem does this PR solve?

Issue Number: close #46809

Problem Summary:
Using nested loop is inefficient when column count is high.

What is changed and how it works?

This is a refactoring of PhysicalTopN#containVirtualColumn.
At the beginning, we establish a map from column Id to *expression.Column.
In the main loop, we just check whether the underlying column Id is in the map.

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 ti-chi-bot bot added do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. and removed do-not-merge/needs-tests-checked labels Sep 9, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 9, 2023

Hi @tedyu. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@tiprow
Copy link

tiprow bot commented Sep 9, 2023

Hi @tedyu. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

@tedyu
Copy link
Contributor Author

tedyu commented Sep 9, 2023

cc @hawkingrei

@hawkingrei
Copy link
Member

/ok-to-test

@ti-chi-bot ti-chi-bot bot added ok-to-test Indicates a PR is ready to be tested. and removed needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Sep 9, 2023
@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 9, 2023
@tedyu
Copy link
Contributor Author

tedyu commented Sep 9, 2023

make[1]: Leaving directory `/home/jenkins/agent/workspace/pingcap/tidb/ghpr_unit_test/tidb'
make: *** [check-bazel-prepare] Error 2
root: /home/jenkins/.tidb/tmp/63a9840cd0739f2c243bb46478607469/execroot/__main__/bazel-out/k8-fastbuild/testlogs
mv: cannot stat 'bazel.xml': No such file or directory
script returned exit code 2

It seems the above error was not related to my PR.

@codecov
Copy link

codecov bot commented Sep 9, 2023

Codecov Report

Merging #46812 (9d70107) into master (d3d30f5) will decrease coverage by 0.6261%.
The diff coverage is 100.0000%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #46812        +/-   ##
================================================
- Coverage   73.3326%   72.7066%   -0.6261%     
================================================
  Files          1322       1343        +21     
  Lines        396474     402761      +6287     
================================================
+ Hits         290745     292834      +2089     
- Misses        87208      91363      +4155     
- Partials      18521      18564        +43     
Flag Coverage Δ
integration 27.8648% <71.4285%> (?)
unit 73.3236% <100.0000%> (-0.0091%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 54.0444% <ø> (ø)
parser 84.9609% <ø> (-0.0108%) ⬇️
br 48.2837% <ø> (-4.3580%) ⬇️

@hawkingrei
Copy link
Member

make[1]: Leaving directory `/home/jenkins/agent/workspace/pingcap/tidb/ghpr_unit_test/tidb'
make: *** [check-bazel-prepare] Error 2
root: /home/jenkins/.tidb/tmp/63a9840cd0739f2c243bb46478607469/execroot/__main__/bazel-out/k8-fastbuild/testlogs
mv: cannot stat 'bazel.xml': No such file or directory
script returned exit code 2

It seems the above error was not related to my PR.

Yes, I think it is about our CI.

@tedyu
Copy link
Contributor Author

tedyu commented Sep 9, 2023

 [ERROR] [runaway.go:145] ["try to get new runaway watch"] [error="[schema:1146]Table 'mysql.tidb_runaway_watch' doesn't exist"]

The above error doesn't seem to be related to my PR.

I wonder if this may happen before all the upgrade scripts in bootstrapVersion complete execution. In this case, upgradeToVer172 may not have run.

@tedyu
Copy link
Contributor Author

tedyu commented Sep 9, 2023

/test all

1 similar comment
@tedyu
Copy link
Contributor Author

tedyu commented Sep 9, 2023

/test all

@hawkingrei
Copy link
Member

 [ERROR] [runaway.go:145] ["try to get new runaway watch"] [error="[schema:1146]Table 'mysql.tidb_runaway_watch' doesn't exist"]

The above error doesn't seem to be related to my PR.

I wonder if this may happen before all the upgrade scripts in bootstrapVersion complete execution. In this case, upgradeToVer172 may not have run.

I found it. it is not your problem.

@hawkingrei
Copy link
Member

/test all

@hawkingrei
Copy link
Member

/test unit-test

@tiprow
Copy link

tiprow bot commented Sep 10, 2023

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

  • /test tiprow_fast_test

Use /test all to run all jobs.

In response to this:

/test unit-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.

@hawkingrei
Copy link
Member

/test check-dev

@tiprow
Copy link

tiprow bot commented Sep 10, 2023

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

  • /test tiprow_fast_test

Use /test all to run all jobs.

In response to this:

/test check-dev

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.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 11, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, qw4990

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 Sep 11, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 11, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-09-09 15:39:58.977356923 +0000 UTC m=+110980.901913317: ☑️ agreed by hawkingrei.
  • 2023-09-11 02:47:37.993231868 +0000 UTC m=+237439.917788262: ☑️ agreed by qw4990.

@ti-chi-bot ti-chi-bot bot merged commit 262327f into pingcap:master Sep 11, 2023
Copy link
Member

@Rustin170506 Rustin170506 left a comment

Choose a reason for hiding this comment

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

👍🏿

If we can add a golang benchmark to it, that would be nice.

for _, by := range p.ByItems {
cols := expression.ExtractColumns(by.Expr)
for _, col := range cols {
for _, tCol := range tCols {
if _, ok := tColSet[col.ID]; ok {
// A column with ID > 0 indicates that the column can be resolved by data source.
Copy link
Member

Choose a reason for hiding this comment

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

Could you please move this comment to the right place? Thanks!

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 PR has been merged.
If I happen to modify this class again, I can move it.

I think it is fine to leave the comment here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Speed up PhysicalTopN#containVirtualColumn
4 participants