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: fix a bug on generated column cause wrong read result #33050

Merged
merged 10 commits into from
Mar 15, 2022

Conversation

tiancaiamao
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #33038

Problem Summary:

What is changed and how it works?

func (us *UnionScanExec) Next(ctx context.Context, req *chunk.Chunk) error {
    ...
    for i, batchSize := 0, req.Capacity(); i < batchSize; i++ {
	    ....
	    matched, _, err := expression.EvalBool(us.ctx, us.conditionsWithVirCol, mutableRow.ToRow())
	    if err != nil {
		    return err
	    }
	    if matched {
		    req.AppendRow(mutableRow.ToRow())
	    }
    }
    return nil
}

When a batch of data (32 rows by default) is processed, but no row match, an empty chunk is returned.
The parent executor treat empty chunk as the reading process has finished.
So the Next() will never be called again!
Only the first batch of chunk is handled, all the others are ignored.

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

Fix a bug that reading from a table with generated column may get wrong result.
It happens when all the following conditions hold:
- A UnionScan executor is used
- The query comes with a filter condition on the generated column
- No row from the first batch of the chunk rows match the filter condition 

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Mar 14, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • lcwangchao
  • wjhuang2016

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 14, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Mar 14, 2022

executor/union_scan.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 15, 2022
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 15, 2022
@tiancaiamao
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: b5bf9b7

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 15, 2022
@tiancaiamao
Copy link
Contributor Author

/merge

@tiancaiamao
Copy link
Contributor Author

/run-unit-test

@tiancaiamao
Copy link
Contributor Author

/run-unit-test

@tiancaiamao
Copy link
Contributor Author

/run-mysql-test

@tiancaiamao
Copy link
Contributor Author

/run-unit-test

@ti-chi-bot ti-chi-bot merged commit ed489e6 into pingcap:master Mar 15, 2022
@tiancaiamao tiancaiamao deleted the issue-33038 branch March 15, 2022 13:30
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 15, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #33099

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 15, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.0 in PR #33100

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 15, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.1 in PR #33101

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 15, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.2 in PR #33102

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 15, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.3 in PR #33103

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 15, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.4 in PR #33104

@tiancaiamao
Copy link
Contributor Author

PTAL @wjhuang2016 @lcwangchao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.0 needs-cherry-pick-release-5.1 needs-cherry-pick-release-5.2 needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Type: Need cherry pick to release-5.4 release-note size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

the results is unstable
6 participants