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

Explain for Batch_Point_Get does not include partition information in access object #32815

Closed
mjonss opened this issue Mar 4, 2022 · 0 comments · Fixed by #35230
Closed

Explain for Batch_Point_Get does not include partition information in access object #32815

mjonss opened this issue Mar 4, 2022 · 0 comments · Fixed by #35230
Assignees
Labels
component/tablepartition This issue is related to Table Partition of TiDB. 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. severity/minor type/bug The issue is confirmed as a bug.

Comments

@mjonss
Copy link
Contributor

mjonss commented Mar 4, 2022

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, key (b)) partition by hash(a) (partition P0, partition p1, partition P2);
insert into t values (1,1),(2,2),(3,3);
analyze table t;
set @@tidb_partition_prune_mode = 'static';
explain select * from t where a IN (1,2);
explain select * from t where a = 1 OR a = 2;
set @@tidb_partition_prune_mode = 'dynamic';
explain select * from t where a IN (1,2);
explain select * from t where a = 1 OR a = 2;

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

tidb> create table t (a int primary key, b int, key (b)) partition by hash(a) (partition P0, partition p1, partition P2);
Query OK, 0 rows affected (0,01 sec)

tidb> insert into t values (1,1),(2,2),(3,3);
Query OK, 3 rows affected (0,00 sec)
Records: 3  Duplicates: 0  Warnings: 0

tidb> analyze table t;
Query OK, 0 rows affected, 3 warnings (0,03 sec)

tidb> set @@tidb_partition_prune_mode = 'static';
Query OK, 0 rows affected (0,00 sec)

tidb> explain select * from t where a IN (1,2);
+-------------------+---------+------+---------------+--------------------------------------------+
| id                | estRows | task | access object | operator info                              |
+-------------------+---------+------+---------------+--------------------------------------------+
| Batch_Point_Get_1 | 2.00    | root | table:t partition:p1,P2      | handle:[1 2], keep order:false, desc:false |
+-------------------+---------+------+---------------+--------------------------------------------+
1 row in set (0,00 sec)

tidb> explain select * from t where a = 1 OR a = 2;
+--------------------------+---------+------+---------------+--------------------------------------------+
| id                       | estRows | task | access object | operator info                              |
+--------------------------+---------+------+---------------+--------------------------------------------+
| PartitionUnion_9         | 2.00    | root |               |                                            |
| ├─Batch_Point_Get_10     | 1.00    | root | table:t partition:p1      | handle:[1 2], keep order:false, desc:false |
| └─Batch_Point_Get_11     | 1.00    | root | table:t partition:P2      | handle:[1 2], keep order:false, desc:false |
+--------------------------+---------+------+---------------+--------------------------------------------+
3 rows in set (0,00 sec)

tidb> set @@tidb_partition_prune_mode = 'dynamic';
Query OK, 0 rows affected (0,00 sec)

tidb> explain select * from t where a IN (1,2);
+-------------------+---------+------+---------------+--------------------------------------------+
| id                | estRows | task | access object | operator info                              |
+-------------------+---------+------+---------------+--------------------------------------------+
| Batch_Point_Get_1 | 2.00    | root | table:t partition:p1,P2      | handle:[1 2], keep order:false, desc:false |
+-------------------+---------+------+---------------+--------------------------------------------+
1 row in set (0,00 sec)

tidb> explain select * from t where a = 1 OR a = 2;
+------------------------+---------+-----------+-----------------+----------------------------------------------------+
| id                     | estRows | task      | access object   | operator info                                      |
+------------------------+---------+-----------+-----------------+----------------------------------------------------+
| TableReader_6          | 2.00    | root      | partition:p1,P2 | data:TableRangeScan_5                              |
| └─TableRangeScan_5     | 2.00    | cop[tikv] | table:t         | range:[1,1], [2,2], keep order:false, stats:pseudo |
+------------------------+---------+-----------+-----------------+----------------------------------------------------+
2 rows in set (0,00 sec)

3. What did you see instead (Required)

tidb> create table t (a int primary key, b int, key (b)) partition by hash(a) (partition P0, partition p1, partition P2);
Query OK, 0 rows affected (0,01 sec)

tidb> insert into t values (1,1),(2,2),(3,3);
Query OK, 3 rows affected (0,00 sec)
Records: 3  Duplicates: 0  Warnings: 0

tidb> analyze table t;
Query OK, 0 rows affected, 3 warnings (0,03 sec)

tidb> set @@tidb_partition_prune_mode = 'static';
Query OK, 0 rows affected (0,00 sec)

tidb> explain select * from t where a IN (1,2);
+-------------------+---------+------+---------------+--------------------------------------------+
| id                | estRows | task | access object | operator info                              |
+-------------------+---------+------+---------------+--------------------------------------------+
| Batch_Point_Get_1 | 2.00    | root | table:t       | handle:[1 2], keep order:false, desc:false |
+-------------------+---------+------+---------------+--------------------------------------------+
1 row in set (0,00 sec)

tidb> explain select * from t where a = 1 OR a = 2;
+--------------------------+---------+------+---------------+--------------------------------------------+
| id                       | estRows | task | access object | operator info                              |
+--------------------------+---------+------+---------------+--------------------------------------------+
| PartitionUnion_9         | 2.00    | root |               |                                            |
| ├─Batch_Point_Get_10     | 1.00    | root | table:t       | handle:[1 2], keep order:false, desc:false |
| └─Batch_Point_Get_11     | 1.00    | root | table:t       | handle:[1 2], keep order:false, desc:false |
+--------------------------+---------+------+---------------+--------------------------------------------+
3 rows in set (0,00 sec)

tidb> set @@tidb_partition_prune_mode = 'dynamic';
Query OK, 0 rows affected (0,00 sec)

tidb> explain select * from t where a IN (1,2);
+-------------------+---------+------+---------------+--------------------------------------------+
| id                | estRows | task | access object | operator info                              |
+-------------------+---------+------+---------------+--------------------------------------------+
| Batch_Point_Get_1 | 2.00    | root | table:t       | handle:[1 2], keep order:false, desc:false |
+-------------------+---------+------+---------------+--------------------------------------------+
1 row in set (0,00 sec)

tidb> explain select * from t where a = 1 OR a = 2;
+------------------------+---------+-----------+-----------------+----------------------------------------------------+
| id                     | estRows | task      | access object   | operator info                                      |
+------------------------+---------+-----------+-----------------+----------------------------------------------------+
| TableReader_6          | 2.00    | root      | partition:p1,P2 | data:TableRangeScan_5                              |
| └─TableRangeScan_5     | 2.00    | cop[tikv] | table:t         | range:[1,1], [2,2], keep order:false, stats:pseudo |
+------------------------+---------+-----------+-----------------+----------------------------------------------------+
2 rows in set (0,00 sec)

4. What is your TiDB version? (Required)

Release Version: v5.5.0-alpha-489-g493eb45c75
Edition: Community
Git Commit Hash: 493eb45c75a8f9687d5bf9185e5e167aadc81012
Git Branch: master
UTC Build Time: 2022-03-04 00:14:01
GoVersion: go1.17
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@mjonss mjonss added the type/bug The issue is confirmed as a bug. label Mar 4, 2022
@seiya-annie seiya-annie added component/tablepartition This issue is related to Table Partition of TiDB. severity/major labels Mar 4, 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. labels Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/tablepartition This issue is related to Table Partition of TiDB. 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. severity/minor type/bug The issue is confirmed as a bug.
Projects
None yet
5 participants