-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: fix bug that UnionScan can't keep order caused wrong result #33218
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/5d5555ed1845632a82528c440f8bebfe50310596 |
When was this introduced? @tiancaiamao |
I believe it's been there for quite a long time... |
executor/mem_reader.go
Outdated
// TODO: `IterReverse` is not used... to get the same effect, reverse the kv ranges first, | ||
// Then reverse the whole added rows. | ||
// [99, 100] [44, 45] [1, 3] => [1, 3] [44, 45] [99, 100] => [100, 99] [45, 44] [3 1] | ||
if m.desc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may still cause bugs when the int is signed, try the following:
create global temporary table `tmp2` (id bigint primary key) on commit delete rows;
begin;
insert into tmp2 values(-2),(-1),(0),(1),(2);
-- The following query will give a wrong result:
-- expected 2, 1, 0, -1, -2 , actual: -1, -2, 2, 1
select * from tmp2 where id <= -1 or id > 0 order by id desc;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update, PTAL @lcwangchao
Co-authored-by: 王超 <[email protected]>
/run-unit-test |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 41b3f5b
|
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-6.0 in PR #33319 |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-5.4 in PR #37805 |
What problem does this PR solve?
Issue Number: close #33175
Problem Summary:
What is changed and how it works?
Actually, there are two bugs that cause the UnionScan fail to keep order,
and since it can't keep order, the following plan return wrong result.
Limit1->UnionScan->XXX
doesn't return themax(id)
The first bug is the datum comparing, the data type is KindUint64, but the old code treat it as
GetInt64()
,10353107668348738101 become a negative number and 10353107668348738101 < 33
The second bug is the handling of kv range, in TiKV, the range is singed int
Here the data type is uint, so correct range handling is:
the wrong range handling is:
i.e. the kv range order should be [-max int64, 0] [0, max int64]
Check List
Tests
Side effects
Documentation
Release note