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

TiDB returns wrong result for cartesian join #25591

Closed
windtalker opened this issue Jun 21, 2021 · 6 comments · Fixed by #25653
Closed

TiDB returns wrong result for cartesian join #25591

windtalker opened this issue Jun 21, 2021 · 6 comments · Fixed by #25653
Assignees
Labels
severity/critical sig/execution SIG execution type/bug This issue is a bug.

Comments

@windtalker
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> show create table t1_1;
+-------+----------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                   |
+-------+----------------------------------------------------------------------------------------------------------------+
| t1_1  | CREATE TABLE `t1_1` (
  `col1` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+----------------------------------------------------------------------------------------------------------------+
1 row in set (0.03 sec)

mysql> show create table t2_1;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                      |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| t2_1  | CREATE TABLE `t2_1` (
  `col1` varchar(20) DEFAULT NULL,
  `col2` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.04 sec)

mysql> select * from t1_1;
+--------+
| col1   |
+--------+
| 12.991 |
+--------+
1 row in set (0.06 sec)

mysql> select * from t2_1;
+------+--------+
| col1 | col2   |
+------+--------+
| NULL |     87 |
| NULL | -9.183 |
| NULL | -9.183 |
+------+--------+
3 rows in set (0.14 sec)
mysql> set session tidb_isolation_read_engines='tikv';
Query OK, 0 rows affected (0.04 sec)

mysql> explain select t1.col1, t2.col1, t2.col2 from t1_1 t1 inner join  t2_1 t2 on t1.col1 not in (1,t2.col1,t2.col2) order by 1,2,3;
+-------------------------------+---------+-----------+---------------+------------------------------------------------------------------------------------------------------------------+
| id                            | estRows | task      | access object | operator info                                                                                                    |
+-------------------------------+---------+-----------+---------------+------------------------------------------------------------------------------------------------------------------+
| Sort_8                        | 3.00    | root      |               | test.t1_1.col1, test.t2_1.col1, test.t2_1.col2                                                                   |
| └─HashJoin_12                 | 3.00    | root      |               | CARTESIAN inner join, other cond:not(in(test.t1_1.col1, 1, cast(test.t2_1.col1, double BINARY), test.t2_1.col2)) |
|   ├─TableReader_14(Build)     | 1.00    | root      |               | data:TableFullScan_13                                                                                            |
|   │ └─TableFullScan_13        | 1.00    | cop[tikv] | table:t1      | keep order:false, stats:pseudo                                                                                   |
|   └─TableReader_16(Probe)     | 3.00    | root      |               | data:TableFullScan_15                                                                                            |
|     └─TableFullScan_15        | 3.00    | cop[tikv] | table:t2      | keep order:false, stats:pseudo                                                                                   |
+-------------------------------+---------+-----------+---------------+------------------------------------------------------------------------------------------------------------------+
6 rows in set (0.04 sec)

mysql> select t1.col1, t2.col1, t2.col2 from t1_1 t1 inner join  t2_1 t2 on t1.col1 not in (1,t2.col1,t2.col2) order by 1,2,3;
+--------+------+--------+
| col1   | col1 | col2   |
+--------+------+--------+
| 12.991 | NULL | -9.183 |
| 12.991 | NULL | -9.183 |
+--------+------+--------+
2 rows in set (0.04 sec)

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

mysql> select t1.col1, t2.col1, t2.col2 from t1_1 t1 inner join  t2_1 t2 on t1.col1 not in (1,t2.col1,t2.col2) order by 1,2,3;
Empty set (0.00 sec)

3. What did you see instead (Required)

mysql> select t1.col1, t2.col1, t2.col2 from t1_1 t1 inner join  t2_1 t2 on t1.col1 not in (1,t2.col1,t2.col2) order by 1,2,3;
+--------+------+--------+
| col1   | col1 | col2   |
+--------+------+--------+
| 12.991 | NULL | -9.183 |
| 12.991 | NULL | -9.183 |
+--------+------+--------+
2 rows in set (0.04 sec)

4. What is your TiDB version? (Required)

mysql> select tidb_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                           |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v5.2.0-alpha-14-g75388187f
Edition: Community
Git Commit Hash: 75388187f3865db18bc70ca1ef30260d85dba2e2
Git Branch: master
UTC Build Time: 2021-06-08 09:21:55
GoVersion: go1.16.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.06 sec)
@windtalker windtalker added the type/bug This issue is a bug. label Jun 21, 2021
@ChenPeng2013
Copy link
Contributor

The latest version TiDB-v5.2.0-alpha-118-ga6f52fb45 does't have this issue

@windtalker
Copy link
Contributor Author

I can reproduce it using the latest commit 58d8b960fa69fe829cf328fe486f8f14d0d9a2b3

@ChenPeng2013
Copy link
Contributor

repro steps

use test;
drop table if exists t1_1, t2_1;
CREATE TABLE `t1_1` (
  `col1` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
CREATE TABLE `t2_1` (
  `col1` varchar(20) DEFAULT NULL,
  `col2` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
insert into t1_1 values(12.991);
insert into t2_1(col2) values(87), (-9.183), (-9.183);
analyze table t1_1;
analyze table t2_1;
select t1.col1, t2.col1, t2.col2 from t1_1 t1 inner join  t2_1 t2 on t1.col1 not in (1,t2.col1,t2.col2) order by 1,2,3;

@zz-jason
Copy link
Member

@guo-shaoge PTAL

@guo-shaoge
Copy link
Collaborator

guo-shaoge commented Jun 21, 2021

After (*builtinInRealSig) evalInt, OtherConditions in HashJoin become invalid.

Before: t1.c1 in (1, t2.c1, t2.c2)

After: t1.c1 in (t2.c2, t2.c2, t2.c2)

This code snippet describes what happend.

@ti-srebot
Copy link
Contributor

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/critical sig/execution SIG execution type/bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants