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: support left outer semi join for hash join v2 #57053

Merged
merged 32 commits into from
Nov 13, 2024

Conversation

wshwsh12
Copy link
Contributor

@wshwsh12 wshwsh12 commented Nov 1, 2024

What problem does this PR solve?

Issue Number: ref #53127

Problem Summary:

What changed and how does it work?

Support left outer semi join for hash join v2.

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.

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 ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 1, 2024
Copy link

tiprow bot commented Nov 1, 2024

Hi @wshwsh12. 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-sigs/prow repository.

Copy link

codecov bot commented Nov 1, 2024

Codecov Report

Attention: Patch coverage is 82.53275% with 40 lines in your changes missing coverage. Please review.

Project coverage is 58.1168%. Comparing base (c39f46f) to head (71d464d).
Report is 56 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #57053         +/-   ##
=================================================
- Coverage   72.9983%   58.1168%   -14.8815%     
=================================================
  Files          1657       1824        +167     
  Lines        457724     659502     +201778     
=================================================
+ Hits         334131     383282      +49151     
- Misses       103066     251034     +147968     
- Partials      20527      25186       +4659     
Flag Coverage Δ
integration 39.6730% <60.2620%> (?)
unit 73.5084% <82.8193%> (+1.2285%) ⬆️

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

Components Coverage Δ
dumpling 55.2602% <ø> (+2.3124%) ⬆️
parser ∅ <ø> (∅)
br 63.1758% <ø> (+17.4965%) ⬆️

@wshwsh12 wshwsh12 force-pushed the left-outer-semi-join branch from e340196 to 11e7453 Compare November 1, 2024 08:53
@wshwsh12 wshwsh12 force-pushed the left-outer-semi-join branch from 11e7453 to ec6ff80 Compare November 1, 2024 09:15
@wshwsh12
Copy link
Contributor Author

wshwsh12 commented Nov 4, 2024

/retest

Copy link

tiprow bot commented Nov 4, 2024

@wshwsh12: 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-sigs/prow repository.

@wshwsh12
Copy link
Contributor Author

wshwsh12 commented Nov 4, 2024

/retest

Copy link

tiprow bot commented Nov 4, 2024

@wshwsh12: 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-sigs/prow repository.

@wshwsh12
Copy link
Contributor Author

wshwsh12 commented Nov 4, 2024

/check_dev_2

@wshwsh12
Copy link
Contributor Author

wshwsh12 commented Nov 4, 2024

/retest

Copy link

tiprow bot commented Nov 4, 2024

@wshwsh12: 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-sigs/prow repository.


type leftOuterSemiJoinProbe struct {
baseJoinProbe
// build/probe side used columns and offset in result chunk
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the comments can not explain the code clearly?

@@ -747,6 +747,8 @@ func NewJoinProbe(ctx *HashJoinCtxV2, workID uint, joinType logicalop.JoinType,
return newOuterJoinProbe(base, !rightAsBuildSide, rightAsBuildSide)
case logicalop.RightOuterJoin:
return newOuterJoinProbe(base, rightAsBuildSide, rightAsBuildSide)
case logicalop.LeftOuterSemiJoin:
Copy link
Contributor

Choose a reason for hiding this comment

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

check rightAsBuildSide is always true here?


func (j *leftOuterSemiJoinProbe) buildResult(chk *chunk.Chunk, startProbeRow int) {
selected := make([]bool, j.chunkRows)
for i := startProbeRow; i < j.currentProbeRow; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

if chk is empty, and startProbeRow == 0 && j.currentProbeRow == j.chunkRows && j.currentChunk.sel() == nil is true, can we use shallow copy instead of deep copy?

}

if j.ctx.hasOtherCondition() {
err = j.probeForInnerSideBuildWithOtherCondition(joinResult.chk, joinedChk, sqlKiller)
Copy link
Contributor

Choose a reason for hiding this comment

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

seems no need to add ForInnerSideBuild since it always use inner side build

if j.ctx.hasOtherCondition() {
err = j.probeForInnerSideBuildWithOtherCondition(joinResult.chk, joinedChk, sqlKiller)
} else {
err = j.probeForInnerSideBuildWithoutOtherCondition(joinResult.chk, joinedChk, remainCap, sqlKiller)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto


// isMatchedRows marks whether the left side row is matched
isMatchedRows []bool
// isNullRows marks whether the left side row is null
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// isNullRows marks whether the left side row is null
// isNullRows marks whether the left side row match result is null

baseJoinProbe: base,
processedProbeRowIdxSet: make(map[int]struct{}),
}
probe.leftColUsed = base.lUsed
Copy link
Contributor

Choose a reason for hiding this comment

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

why copy this field, you can use base.lUsed directly?

}

if j.currentProbeRow == j.chunkRows && len(j.processedProbeRowIdxSet) == 0 {
j.buildResult(chk, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it would exceed chk's capacity if the chk is not empty?

@wshwsh12 wshwsh12 requested a review from windtalker November 6, 2024 16:41
j.processedProbeRowIdxQueue.Push(i)
}
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like L56-L69 is exactly the same as L78-91, I think we can reuse the code

}
if j.ctx.hasOtherCondition() {
j.processedProbeRowIdxQueue.Clear()
for i := 0; i < j.chunkRows; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since matchedRowsHeaders is already set in base.SetChunkForProbe, I think we can only add the rows that matchedRowsHeaders[rows] != 0 to processedProbeIdxQueue.

isNulls []bool

// used in other condition to record which rows need to be processed
processedProbeRowIdxQueue *queue.Queue[int]
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe unFinishedProbeRowIdxQueue is a more self-explain name?

}
if j.ctx.hasOtherCondition() {
j.processedProbeRowIdxQueue.Clear()
for i := 0; i < j.chunkRows; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

}

func (j *leftOuterSemiJoinProbe) concatenateProbeAndBuildRows(joinedChk *chunk.Chunk, sqlKiller *sqlkiller.SQLKiller) error {
joinedChkRemainCap := joinedChk.Capacity()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
joinedChkRemainCap := joinedChk.Capacity()
joinedChkRemainCap := joinedChk.Capacity() - joinedChk.NumRows()

}
}

func TestLeftOuterSemiJoinSpillBasic(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need add 3 tests for spill

  • basic tests
  • with other condition
  • with other condition and sel array.


err := failpoint.Enable("github.com/pingcap/tidb/pkg/executor/join/slowWorkers", `return(true)`)
require.NoError(t, err)
defer failpoint.Disable("github.com/pingcap/tidb/pkg/executor/join/slowWorkers")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think basic test don't need to enable slow workers?

if startProbeRow == 0 && j.currentProbeRow == j.chunkRows && j.currentChunk.Sel() == nil && chk.NumRows() == 0 && len(j.spilledIdx) == 0 {
// TODO: Can do a shallow copy by directly copying the Column pointers
for index, colIndex := range j.lUsed {
chk.SetCol(index, j.currentChunk.Column(colIndex).CopyConstruct(nil))
Copy link
Contributor

Choose a reason for hiding this comment

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

why not pass chk.Column(index) to CopyConstruct?

@wshwsh12
Copy link
Contributor Author

wshwsh12 commented Nov 7, 2024

/retest

Copy link

tiprow bot commented Nov 7, 2024

@wshwsh12: 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-sigs/prow repository.

@wshwsh12 wshwsh12 requested a review from windtalker November 7, 2024 06:01
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 the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 7, 2024
Copy link
Contributor

@xzhangxian1008 xzhangxian1008 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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 8, 2024
Copy link

ti-chi-bot bot commented Nov 8, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-07 06:26:57.09115944 +0000 UTC m=+1108729.930314989: ☑️ agreed by windtalker.
  • 2024-11-08 08:13:36.449571081 +0000 UTC m=+1201529.288726628: ☑️ agreed by xzhangxian1008.

Copy link

ti-chi-bot bot commented Nov 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, windtalker, xzhangxian1008

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 the approved label Nov 11, 2024
@wshwsh12
Copy link
Contributor Author

/retest

Copy link

tiprow bot commented Nov 11, 2024

@wshwsh12: 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-sigs/prow repository.

@windtalker
Copy link
Contributor

/test unit-test

Copy link

tiprow bot commented Nov 13, 2024

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

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-sigs/prow repository.

@windtalker
Copy link
Contributor

/test unit-test

Copy link

tiprow bot commented Nov 13, 2024

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

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-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot merged commit 8832684 into pingcap:master Nov 13, 2024
23 checks passed
you06 pushed a commit to you06/tidb that referenced this pull request Nov 18, 2024
ref pingcap#53127

handle key-too-large error from MemBuffer

Signed-off-by: you06 <you1474600@gmail.com>

test MemBuffer's oversize error to tidb error

Signed-off-by: you06 <you1474600@gmail.com>

update errdoc

Signed-off-by: you06 <you1474600@gmail.com>
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Nov 20, 2024
ref pingcap#53127

handle key-too-large error from MemBuffer

Signed-off-by: you06 <you1474600@gmail.com>

test MemBuffer's oversize error to tidb error

Signed-off-by: you06 <you1474600@gmail.com>

update errdoc

Signed-off-by: you06 <you1474600@gmail.com>
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. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants