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

Incorrect Result by LEFT JOIN #38304

Closed
bajinsheng opened this issue Oct 6, 2022 · 1 comment · Fixed by #38430
Closed

Incorrect Result by LEFT JOIN #38304

bajinsheng opened this issue Oct 6, 2022 · 1 comment · Fixed by #38430
Assignees
Labels
severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@bajinsheng
Copy link

Bug Report

Inconsistent results by LEFT JOIN.

1. Minimal reproduce step (Required)

CREATE TABLE t0(c0 BLOB(5), c1 BLOB(5));
CREATE TABLE t1 (c0 BOOL);
INSERT INTO t1 VALUES(false);
INSERT INTO t0(c0, c1) VALUES ('>', true);

SELECT * FROM t0 LEFT OUTER JOIN t1 ON NULL; -- {>|1|NULL}
SELECT NOT '2' =(t1.c0 AND t0.c1 IS NULL) FROM t0 LEFT OUTER JOIN t1 ON NULL; -- {1}
SELECT * FROM t0 LEFT JOIN t1 ON NULL WHERE NOT '2' =(t1.c0 AND t0.c1 IS NULL); -- Empty set

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

The first SELECT returns non-empty results and the predicate NOT '2' =(t1.c0 AND t0.c1 IS NULL) is evaluated TRUE in the second SELECT, but the third SELECT returns nothing.

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

| Release Version: v6.4.0-alpha-12-g51a6684fb
Edition: Community
Git Commit Hash: 51a6684fb767cfd86a8312e0e6447963b927c791
Git Branch: master
UTC Build Time: 2022-10-05 12:40:23
GoVersion: go1.19.1
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: unistore |
@bajinsheng bajinsheng added the type/bug The issue is confirmed as a bug. label Oct 6, 2022
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 may-affects-6.1 may-affects-6.2 may-affects-6.3 labels Oct 8, 2022
@ChenPeng2013 ChenPeng2013 added affects-5.0 This bug affects 5.0.x versions. 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. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 labels Oct 11, 2022
@ti-chi-bot ti-chi-bot removed may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 may-affects-6.1 labels Oct 11, 2022
@Yisaer Yisaer removed affects-5.0 This bug affects 5.0.x versions. 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. affects-5.4 This bug affects 5.4.x versions. may-affects-4.0 This bug maybe affects 4.0.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 labels Oct 12, 2022
@Yisaer
Copy link
Contributor

Yisaer commented Oct 12, 2022

The main reason is that planner transformed left outer join into inner join due to it thinks NOT '2' =(t1.c0 AND t0.c1 IS NULL) must filter the rows which contained NULL for inner table, which is wrong.

mjonss added a commit that referenced this issue Oct 13, 2022
* mockkv: make pk id = -1 if no primary key column is used (#38443)

* ddl: support modify column on partitioned table (#38302)

close #38297

* planner: revise isnullRejected check for `And` and `OR` (#38430)

close #38304

Co-authored-by: xiongjiwei <[email protected]>
Co-authored-by: Song Gao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants