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: fix wrong behavior for != any() #20058

Merged
merged 3 commits into from
Sep 17, 2020
Merged

Conversation

wshwsh12
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #20007

Problem Summary:
The result is unstable.

What is changed and how it works?

Proposal: xxx

What's Changed: Use max function instead of first_row function.

How it Works:

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test

Side effects

Release note

  • Fix wrong behavior for != any()

@wshwsh12 wshwsh12 requested a review from a team as a code owner September 17, 2020 06:52
@wshwsh12 wshwsh12 requested review from eurekaka and removed request for a team September 17, 2020 06:52
@wshwsh12 wshwsh12 added sig/planner SIG: Planner type/bugfix This PR fixes a bug. labels Sep 17, 2020
Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -650,15 +652,15 @@ func (er *expressionRewriter) handleNEAny(lexpr, rexpr expression.Expression, np
return
}
plan4Agg := LogicalAggregation{
AggFuncs: []*aggregation.AggFuncDesc{firstRowFunc, countFunc},
AggFuncs: []*aggregation.AggFuncDesc{maxFunc, countFunc},
}.Init(er.sctx, er.b.getSelectOffset())
if hint := er.b.TableHints(); hint != nil {
plan4Agg.aggHints = hint.aggHints
}
plan4Agg.SetChildren(np)
firstRowResultCol := &expression.Column{
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this variable name as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

firstRowFunc, err := aggregation.NewAggFuncDesc(er.sctx, ast.AggFuncFirstRow, []expression.Expression{rexpr}, false)
// If there is NULL in s.id column, s.id should be the value that isn't null in condition t.id != s.id.
// So use function max to filter NULL.
maxFunc, err := aggregation.NewAggFuncDesc(er.sctx, ast.AggFuncMax, []expression.Expression{rexpr}, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Max would produce null result when the s.id is empty, would this impact the correctness of the result?

Copy link
Contributor Author

@wshwsh12 wshwsh12 Sep 17, 2020

Choose a reason for hiding this comment

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

I think firstrow also produces null result when the s.id is empty..

Copy link
Contributor

@eurekaka eurekaka 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-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Sep 17, 2020
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Sep 17, 2020
@eurekaka eurekaka added the status/can-merge Indicates a PR has been approved by a committer. label Sep 17, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit 8f6d120 into pingcap:master Sep 17, 2020
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Sep 17, 2020
@ti-srebot
Copy link
Contributor

cherry pick to release-3.0 in PR #20061

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Sep 17, 2020
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #20062

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect result when quering on partitioned tables
4 participants