-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
In clause with null causes incorrect results #51560
Labels
affects-6.1
affects-6.5
affects-7.1
affects-7.5
severity/critical
sig/planner
SIG: Planner
type/bug
The issue is confirmed as a bug.
Comments
It seems that the plans are different: mysql> select b.b
-> from A a
-> left join (
-> B b
-> left join C c on b.b = c.b)
-> on b.b = a.b
-> where a.a in (2, 3);
+------+
| b |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.01 sec)
mysql> explain select b.b from A a left join ( B b left join C c on b.b = c.b) on b.b = a.b where a.a in (2, 3);
+---------------------------------+----------+-----------+---------------+-------------------------------------------------+
| id | estRows | task | access object | operator info |
+---------------------------------+----------+-----------+---------------+-------------------------------------------------+
| HashJoin_12 | 3.12 | root | | left outer join, equal:[eq(test.a.b, test.b.b)] |
| ├─Batch_Point_Get_13(Build) | 2.00 | root | table:A | handle:[2 3], keep order:false, desc:false |
| └─HashJoin_14(Probe) | 12487.50 | root | | left outer join, equal:[eq(test.b.b, test.c.b)] |
| ├─TableReader_20(Build) | 9990.00 | root | | data:Selection_19 |
| │ └─Selection_19 | 9990.00 | cop[tikv] | | not(isnull(test.c.b)) |
| │ └─TableFullScan_18 | 10000.00 | cop[tikv] | table:c | keep order:false, stats:pseudo |
| └─TableReader_17(Probe) | 10000.00 | root | | data:TableFullScan_16 |
| └─TableFullScan_16 | 10000.00 | cop[tikv] | table:b | keep order:false, stats:pseudo |
+---------------------------------+----------+-----------+---------------+-------------------------------------------------+
8 rows in set (0.01 sec)
mysql> select b.b
-> from A a
-> left join (
-> B b
-> left join C c on b.b = c.b)
-> on b.b = a.b
-> where a.a in (2, 3, null);
+------+
| b |
+------+
| NULL |
| NULL |
+------+
2 rows in set (0.01 sec)
mysql> explain select b.b from A a left join ( B b left join C c on b.b = c.b) on b.b = a.b where a.a in (2, 3, null);
+---------------------------------+----------+-----------+---------------+-------------------------------------------------+
| id | estRows | task | access object | operator info |
+---------------------------------+----------+-----------+---------------+-------------------------------------------------+
| HashJoin_13 | 3.12 | root | | left outer join, equal:[eq(test.a.b, test.b.b)] |
| ├─Batch_Point_Get_14(Build) | 2.00 | root | table:A | handle:[2 3], keep order:false, desc:false |
| └─HashJoin_26(Probe) | 12487.50 | root | | inner join, equal:[eq(test.c.b, test.b.b)] |
| ├─TableReader_29(Build) | 9990.00 | root | | data:Selection_28 |
| │ └─Selection_28 | 9990.00 | cop[tikv] | | not(isnull(test.c.b)) |
| │ └─TableFullScan_27 | 10000.00 | cop[tikv] | table:c | keep order:false, stats:pseudo |
| └─TableReader_31(Probe) | 10000.00 | root | | data:TableFullScan_30 |
| └─TableFullScan_30 | 10000.00 | cop[tikv] | table:b | keep order:false, stats:pseudo |
+---------------------------------+----------+-----------+---------------+-------------------------------------------------+
8 rows in set (0.01 sec)
mysql> Add |
ti-chi-bot
bot
added
may-affects-5.4
This bug maybe affects 5.4.x versions.
may-affects-6.1
may-affects-6.5
may-affects-7.1
may-affects-7.5
labels
Mar 8, 2024
13 tasks
winoros
added
affects-6.1
affects-6.5
affects-7.1
affects-7.5
and removed
may-affects-5.4
This bug maybe affects 5.4.x versions.
may-affects-6.1
may-affects-6.5
may-affects-7.1
may-affects-7.5
labels
Mar 13, 2024
This was referenced Mar 25, 2024
Merged
Merged
Merged
13 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
affects-6.1
affects-6.5
affects-7.1
affects-7.5
severity/critical
sig/planner
SIG: Planner
type/bug
The issue is confirmed as a bug.
Bug Report
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
Both queries should return two rows with values
3. What did you see instead (Required)
The second query, with the addition of
null
in thein
clause, returns two rows both with valuenull
.In mysql this works as expected and both queries return the correct data.
4. What is your TiDB version? (Required)
The text was updated successfully, but these errors were encountered: