Skip to content

The result of index join in associated subqueries is wrong #25799

@lilinghai

Description

@lilinghai

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

1.txt
download and source the 1.txt

select t1. `col_float_key_signed`,t1. `col_smallint_undef_signed`  from table_20_binary_undef as t1 where t1. `col_float_key_signed` not in (select `col_float_key_signed` from table_75_binary_undef as t2 where t1. `col_smallint_undef_signed` = t2. `col_tinyint_key_signed`) ;

The plan is

+------------------------------------+---------+-----------+----------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id                                 | estRows | task      | access object                                                  | operator info                                                                                                                                                                                                                                                                                                                                                                             |
+------------------------------------+---------+-----------+----------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Projection_8                       | 16.00   | root      |                                                                | rs2.table_20_binary_undef.col_float_key_signed, rs2.table_20_binary_undef.col_smallint_undef_signed                                                                                                                                                                                                                                                                                       |
| └─IndexJoin_12                     | 16.00   | root      |                                                                | anti semi join, inner:IndexLookUp_11, outer key:rs2.table_20_binary_undef.col_smallint_undef_signed, inner key:rs2.table_75_binary_undef.col_tinyint_key_signed, equal cond:eq(rs2.table_20_binary_undef.col_float_key_signed, rs2.table_75_binary_undef.col_float_key_signed), eq(rs2.table_20_binary_undef.col_smallint_undef_signed, rs2.table_75_binary_undef.col_tinyint_key_signed) |
|   ├─TableReader_22(Build)          | 20.00   | root      |                                                                | data:TableFullScan_21                                                                                                                                                                                                                                                                                                                                                                     |
|   │ └─TableFullScan_21             | 20.00   | cop[tikv] | table:t1                                                       | keep order:false, stats:pseudo                                                                                                                                                                                                                                                                                                                                                            |
|   └─IndexLookUp_11(Probe)          | 1.25    | root      |                                                                |                                                                                                                                                                                                                                                                                                                                                                                           |
|     ├─IndexRangeScan_9(Build)      | 1.25    | cop[tikv] | table:t2, index:col_tinyint_key_signed(col_tinyint_key_signed) | range: decided by [eq(rs2.table_75_binary_undef.col_tinyint_key_signed, rs2.table_20_binary_undef.col_smallint_undef_signed)], keep order:false, stats:pseudo                                                                                                                                                                                                                             |
|     └─TableRowIDScan_10(Probe)     | 1.25    | cop[tikv] | table:t2                                                       | keep order:false, stats:pseudo                                                                                                                                                                                                                                                                                                                                                            |
+------------------------------------+---------+-----------+----------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

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

+----------------------+---------------------------+
| col_float_key_signed | col_smallint_undef_signed |
+----------------------+---------------------------+
|                   -1 |                      NULL |
|               12.991 |                       -37 |
|                    1 |                        39 |
+----------------------+---------------------------+

3. What did you see instead (Required)

+----------------------+---------------------------+
| col_float_key_signed | col_smallint_undef_signed |
+----------------------+---------------------------+
|                  -87 |                         1 |
|                   -1 |                      NULL |
|                    1 |                        -9 |
|               12.991 |                       -37 |
|                    1 |                        39 |
|                 NULL |                        -1 |
|               -9.183 |                         1 |
|                  -15 |                        -9 |
+----------------------+---------------------------+

4. What is your TiDB version? (Required)

Release Version: v5.0.3
Edition: Community
Git Commit Hash: ad06648
Git Branch: heads/refs/tags/v5.0.3
UTC Build Time: 2021-06-25 10:00:40
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions