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

wrong result in the combined expression #27831

Closed
ChenPeng2013 opened this issue Sep 6, 2021 · 2 comments · Fixed by #29375
Closed

wrong result in the combined expression #27831

ChenPeng2013 opened this issue Sep 6, 2021 · 2 comments · Fixed by #29375
Assignees
Labels
affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. severity/critical sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@ChenPeng2013
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

use test;
drop table if exists t;
create table t(a enum("a", "b"), b enum("a", "b"), c bool);
insert into t values("a", "a", 1);
select * from t t1 right join t t2 on t1.a=t2.b;
select * from t t1 right join t t2 on t1.a=t2.c;
select * from t t1 right join t t2 on t1.a=t2.b and t1.a= t2.c;

2. What did you expect to see? (Required)

release-5.0 & release-4.0

mysql> select * from t t1 right join t t2 on t1.a=t2.b;
+------+------+------+------+------+------+
| a    | b    | c    | a    | b    | c    |
+------+------+------+------+------+------+
| a    | a    |    1 | a    | a    |    1 |
+------+------+------+------+------+------+
1 row in set (0.00 sec)

mysql> select * from t t1 right join t t2 on t1.a=t2.c;
+------+------+------+------+------+------+
| a    | b    | c    | a    | b    | c    |
+------+------+------+------+------+------+
| a    | a    |    1 | a    | a    |    1 |
+------+------+------+------+------+------+
1 row in set (0.01 sec)

mysql> select * from t t1 right join t t2 on t1.a=t2.b and t1.a= t2.c;
+------+------+------+------+------+------+
| a    | b    | c    | a    | b    | c    |
+------+------+------+------+------+------+
| a    | a    |    1 | a    | a    |    1 |
+------+------+------+------+------+------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

release-5.1 & release-5.2 & master


mysql> select * from t t1 right join t t2 on t1.a=t2.b;
+------+------+------+------+------+------+
| a    | b    | c    | a    | b    | c    |
+------+------+------+------+------+------+
| a    | a    |    1 | a    | a    |    1 |
+------+------+------+------+------+------+
1 row in set (0.00 sec)

mysql> select * from t t1 right join t t2 on t1.a=t2.c;
+------+------+------+------+------+------+
| a    | b    | c    | a    | b    | c    |
+------+------+------+------+------+------+
| a    | a    |    1 | a    | a    |    1 |
+------+------+------+------+------+------+
1 row in set (0.00 sec)

mysql> select * from t t1 right join t t2 on t1.a=t2.b and t1.a= t2.c;
+------+------+------+------+------+------+
| a    | b    | c    | a    | b    | c    |
+------+------+------+------+------+------+
| NULL | NULL | NULL | a    | a    |    1 |
+------+------+------+------+------+------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

@ChenPeng2013 ChenPeng2013 added type/bug The issue is confirmed as a bug. sig/execution SIG execution severity/critical affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. labels Sep 6, 2021
@wshwsh12 wshwsh12 self-assigned this Sep 6, 2021
@wshwsh12
Copy link
Contributor

In this case, t1.a should use ETString in t1.a=t2.b and use ETInt in t1.a=t2.c. We use the flag to distinguish them.
When building hashJoin, the flag have been overwritten by mistake, because t1.a use the same column index for the two conditions.

tidb/executor/builder.go

Lines 1260 to 1265 in efec5c3

for _, key := range e.buildKeys {
e.buildTypes[key.Index].Flag = key.RetType.Flag
}
for _, key := range e.probeKeys {
e.probeTypes[key.Index].Flag = key.RetType.Flag
}

@github-actions
Copy link

github-actions bot commented Nov 5, 2021

Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. severity/critical sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants