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: optimize (left outer) (anti) semi join which has no other condition #47764

Merged
merged 7 commits into from
Oct 23, 2023

Conversation

gengliqi
Copy link
Contributor

@gengliqi gengliqi commented Oct 18, 2023

What problem does this PR solve?

Issue Number: close #47424

Problem Summary:
The sql will be very slow if there are a lot of matched row for each row from build side in (left outer) (anti) semi join.

What is changed and how it works?

Recognize this case then optimize it.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Before

mysql> select count(*) from customer a where exists (select 1 from customer b where a.C_NATIONKEY=b.C_NATIONKEY);
+----------+
| count(*) |
+----------+
|   150000 |
+----------+
1 row in set (36.32 sec)

After

mysql> select count(*) from customer a where exists (select 1 from customer b where a.C_NATIONKEY=b.C_NATIONKEY);
+----------+
| count(*) |
+----------+
|   150000 |
+----------+
1 row in set (0.16 sec)

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.

optimize (left outer) (anti) semi join which has no other condition

Signed-off-by: gengliqi <gengliqiii@gmail.com>
Signed-off-by: gengliqi <gengliqiii@gmail.com>
@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/needs-triage-completed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 18, 2023
@gengliqi
Copy link
Contributor Author

/cc @windtalker

@ti-chi-bot ti-chi-bot bot requested a review from windtalker October 18, 2023 18:42
@tiprow
Copy link

tiprow bot commented Oct 18, 2023

Hi @gengliqi. 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.

@gengliqi
Copy link
Contributor Author

/check-issue-triage-complete

@gengliqi
Copy link
Contributor Author

/retest

@tiprow
Copy link

tiprow bot commented Oct 19, 2023

@gengliqi: 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.

Signed-off-by: gengliqi <gengliqiii@gmail.com>
@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

Merging #47764 (9e27d1e) into master (ab32fc7) will increase coverage by 0.8802%.
Report is 27 commits behind head on master.
The diff coverage is 71.0843%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #47764        +/-   ##
================================================
+ Coverage   71.9012%   72.7815%   +0.8802%     
================================================
  Files          1398       1422        +24     
  Lines        405200     411908      +6708     
================================================
+ Hits         291344     299793      +8449     
+ Misses        94244      93239      -1005     
+ Partials      19612      18876       -736     
Flag Coverage Δ
integration 41.8509% <69.8795%> (?)
unit 71.7326% <71.0843%> (-0.1686%) ⬇️

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

Components Coverage Δ
dumpling 53.9913% <ø> (ø)
parser ∅ <ø> (∅)
br 48.7178% <ø> (-4.2196%) ⬇️

Signed-off-by: gengliqi <gengliqiii@gmail.com>
@gengliqi
Copy link
Contributor Author

/cc @XuHuaiyu

@ti-chi-bot ti-chi-bot bot requested a review from XuHuaiyu October 19, 2023 09:55
pkg/executor/hash_table.go Outdated Show resolved Hide resolved
@@ -490,6 +499,10 @@ func (naaj *nullAwareAntiSemiJoiner) onMissMatch(_ bool, outer chunk.Row, chk *c
chk.AppendRowByColIdxs(outer, naaj.lUsed)
}

func (naaj *nullAwareAntiSemiJoiner) isSemiJoinWithoutCondition() bool {
return len(naaj.conditions) == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this optimazation works for nullaware join? And since only joinMatchedProbeSideRow2Chunk is check isSemiJoinWithoutCondition, nullaware join is not optimized even if it return true here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. This function is useless for null-aware semi join.

Signed-off-by: gengliqi <gengliqiii@gmail.com>
@gengliqi gengliqi changed the title executor: optimize (left) (anti) semi join which has no other condition executor: optimize (left outer) (anti) semi join which has no other condition Oct 20, 2023
Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Oct 20, 2023
@@ -565,7 +611,7 @@ func (es *entryStore) GetStore() (e *entry, memDelta int64) {

type baseHashTable interface {
Put(hashKey uint64, rowPtr chunk.RowPtr)
Get(hashKey uint64) (rowPtrs []chunk.RowPtr)
Get(hashKey uint64) *entry
Copy link
Contributor

Choose a reason for hiding this comment

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

Will it be better to add a comment example here for how to iterator the stored ptrs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. Nice suggestion.

Signed-off-by: gengliqi <gengliqiii@gmail.com>
Signed-off-by: gengliqi <gengliqiii@gmail.com>
@ti-chi-bot
Copy link

ti-chi-bot bot commented Oct 23, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: windtalker, XuHuaiyu

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:
  • OWNERS [XuHuaiyu,windtalker]

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 the lgtm label Oct 23, 2023
@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Oct 23, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Oct 23, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-10-20 07:45:56.966628495 +0000 UTC m=+1988754.553738638: ☑️ agreed by windtalker.
  • 2023-10-23 06:27:35.511807679 +0000 UTC m=+2243253.098917808: ☑️ agreed by XuHuaiyu.

@ti-chi-bot ti-chi-bot bot merged commit 1d3b53e into pingcap:master Oct 23, 2023
12 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

execution: semi join takes too long to run
3 participants