pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.28k stars 5.84k forks source link

cannot deduce TableDual when the partition key does not meet the conditions #56266

Open hawkingrei opened 1 month ago

hawkingrei commented 1 month ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t(a int primary key, b int);
create table tlist (a int) partition by list (a) (
    partition p0 values in (0, 1, 2),
    partition p1 values in (3, 4, 5),
    partition p2 values in (6, 7, 8),
    partition p3 values in (9, 10, 11));
explain select 1 from t left join tlist on tlist.a=t.a where t.a in (12, 13);

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

v7.5

+-------------------------------+---------+------+---------------+-----------------------------------------------------+
| id                            | estRows | task | access object | operator info                                       |
+-------------------------------+---------+------+---------------+-----------------------------------------------------+
| Projection_8                  | 2.00    | root |               | 1->Column#5                                         |
| └─HashJoin_9                  | 2.00    | root |               | left outer join, equal:[eq(test.t.a, test.tlist.a)] |
|   ├─TableDual_12(Build)       | 0.00    | root |               | rows:0                                              |
|   └─Batch_Point_Get_11(Probe) | 2.00    | root | table:t       | handle:[12 13], keep order:false, desc:false        |
+-------------------------------+---------+------+---------------+-----------------------------------------------------+

3. What did you see instead (Required)

v8.1

+-------------------------------+----------+-----------+----------------+-----------------------------------------------------+
| id                            | estRows  | task      | access object  | operator info                                       |
+-------------------------------+----------+-----------+----------------+-----------------------------------------------------+
| Projection_7                  | 2.50     | root      |                | 1->Column#5                                         |
| └─HashJoin_9                  | 2.50     | root      |                | left outer join, equal:[eq(test.t.a, test.tlist.a)] |
|   ├─Batch_Point_Get_10(Build) | 2.00     | root      | table:t        | handle:[12 13], keep order:false, desc:false        |
|   └─TableReader_13(Probe)     | 20.00    | root      | partition:dual | data:Selection_12                                   |
|     └─Selection_12            | 20.00    | cop[tikv] |                | in(test.tlist.a, 12, 13), not(isnull(test.tlist.a)) |
|       └─TableFullScan_11      | 10000.00 | cop[tikv] | table:tlist    | keep order:false, stats:pseudo                      |
+-------------------------------+----------+-----------+----------------+-----------------------------------------------------+

if you get dual partition, we should get 1 row count.

4. What is your TiDB version? (Required)

hawkingrei commented 1 month ago

In MySQL, the row count will get 1

+----+-------------+-------+-------------+-------+---------------+---------+---------+--------+------+----------+--------------------------------------------+
| id | select_type | table | partitions  | type  | possible_keys | key     | key_len | ref    | rows | filtered | Extra                                      |
+----+-------------+-------+-------------+-------+---------------+---------+---------+--------+------+----------+--------------------------------------------+
| 1  | SIMPLE      | t     | <null>      | index | PRIMARY       | PRIMARY | 4       | <null> | 1    | 100.0    | Using where; Using index                   |
| 1  | SIMPLE      | tlist | p0,p1,p2,p3 | ALL   | <null>        | <null>  | <null>  | <null> | 1    | 100.0    | Using where; Using join buffer (hash join) |
+----+-------------+-------+-------------+-------+---------------+---------+---------+--------+------+----------+--------------------------------------------+