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

The partition table scan reader missing the point get #51406

Closed
winoros opened this issue Feb 28, 2024 · 4 comments
Closed

The partition table scan reader missing the point get #51406

winoros opened this issue Feb 28, 2024 · 4 comments
Labels
component/tablepartition This issue is related to Table Partition of TiDB. sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@winoros
Copy link
Member

winoros commented Feb 28, 2024

Enhancement

CREATE TABLE tkey0 (col1 INT NOT NULL, col2 DATE NOT NULL, col3 VARCHAR(12) NOT NULL, col4 INT NOT NULL,UNIQUE KEY (col3)) PARTITION BY KEY(col3) PARTITIONS 4;
INSERT INTO tkey0 VALUES(1, '2023-02-22', 'linpin', 1), (2, '2023-02-22', 'zhangsan', 2), (3, '2023-02-22', 'anqila', 3), (4, '2023-02-22', 'xingtian', 4),(1, '2023-02-22', 'renleifeng', 5), (2, '2023-02-22', 'peilin', 2),(1, '2023-02-22', 'abcdeeg', 7), (2, '2023-02-22', 'rpstdfed', 8);

explain SELECT count(*) FROM tkey0 WHERE col3 = 'zhangsan' or col3 = 'linpin';

create table tkey1 (col1 INT NOT NULL, col2 DATE NOT NULL, col3 VARCHAR(12) NOT NULL, col4 INT NOT NULL,UNIQUE KEY (col3)) ;

explain SELECT count(*) FROM tkey1 WHERE col3 = 'zhangsan' or col3 = 'linpin';
mysql> explain SELECT count(*) FROM tkey6 WHERE col3 = 'zhangsan' or col3 = 'linpin';
+-----------------------------+---------+-----------+-------------------------------+----------------------------------------------------------------------+
| id                          | estRows | task      | access object                 | operator info                                                        |
+-----------------------------+---------+-----------+-------------------------------+----------------------------------------------------------------------+
| StreamAgg_17                | 1.00    | root      |                               | funcs:count(Column#8)->Column#6                                      |
| └─IndexReader_18            | 1.00    | root      | partition:p2,p3               | index:StreamAgg_9                                                    |
|   └─StreamAgg_9             | 1.00    | cop[tikv] |                               | funcs:count(1)->Column#8                                             |
|     └─IndexRangeScan_16     | 2.00    | cop[tikv] | table:tkey6, index:col3(col3) | range:["linpin","linpin"], ["zhangsan","zhangsan"], keep order:false |
+-----------------------------+---------+-----------+-------------------------------+----------------------------------------------------------------------+
4 rows in set (0.00 sec)

mysql> explain SELECT count(*) FROM tkey1 WHERE col3 = 'zhangsan' or col3 = 'linpin';
+--------------------------+---------+------+-------------------------------+------------------------------+
| id                       | estRows | task | access object                 | operator info                |
+--------------------------+---------+------+-------------------------------+------------------------------+
| StreamAgg_9              | 1.00    | root |                               | funcs:count(1)->Column#6     |
| └─Batch_Point_Get_13     | 2.00    | root | table:tkey1, index:col3(col3) | keep order:false, desc:false |
+--------------------------+---------+------+-------------------------------+------------------------------+
2 rows in set (0.00 sec)
@winoros winoros added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner component/tablepartition This issue is related to Table Partition of TiDB. labels Feb 28, 2024
@Defined2014
Copy link
Contributor

A previous issue link #45532

@jiyfhust
Copy link
Contributor

jiyfhust commented Mar 4, 2024

After pr #51405 merged, the batchpoint can be used by set the session variables:

set session tidb_skip_missing_partition_stats=0;
set session tidb_opt_fix_control = "";

That is:

mysql> CREATE TABLE tkey0 (col1 INT NOT NULL, col2 DATE NOT NULL, col3 VARCHAR(12) NOT NULL, col4 INT NOT NULL,UNIQUE KEY (col3)) PARTITION BY KEY(col3) PARTITIONS 4;
INSERT INTO tkey0 VALUES(1, '2023-02-22', 'linpin', 1), (2, '2023-02-22', 'zhangsan', 2), (3, '2023-02-22', 'anqila', 3), (4, '2023-02-22', 'xingtian', 4),(1, '2023-02-22', 'renleifeng', 5), (2, '2023-02-22', 'peilin', 2),(1, '2023-02-22', 'abcdeeg', 7), (2, '2023-02-22', 'rpstdfed', 8);Query OK, 0 rows affected (0.13 sec)

mysql> INSERT INTO tkey0 VALUES(1, '2023-02-22', 'linpin', 1), (2, '2023-02-22', 'zhangsan', 2), (3, '2023-02-22', 'anqila', 3), (4, '2023-02-22', 'xingtian', 4),(1, '2023-02-22', 'renleifeng', 5), (2, '2023-02-22', 'peilin', 2),(1, '2023-02-22', 'abcdeeg', 7), (2, '2023-02-22', 'rpstdfed', 8);
Query OK, 8 rows affected (0.02 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> set session tidb_skip_missing_partition_stats=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set session tidb_opt_fix_control = "";
Query OK, 0 rows affected (0.00 sec)

mysql> explain SELECT count(*) FROM tkey0 WHERE col3 = 'zhangsan' or col3 = 'linpin';
+--------------------------------+---------+------+-------------------------------+---------------------------------+
| id                             | estRows | task | access object                 | operator info                   |
+--------------------------------+---------+------+-------------------------------+---------------------------------+
| HashAgg_12                     | 1.00    | root |                               | funcs:count(Column#7)->Column#6 |
| └─PartitionUnion_13            | 2.00    | root |                               |                                 |
|   ├─StreamAgg_17               | 1.00    | root |                               | funcs:count(1)->Column#7        |
|   │ └─Batch_Point_Get_21       | 2.00    | root | table:tkey0, index:col3(col3) | keep order:false, desc:false    |
|   └─StreamAgg_26               | 1.00    | root |                               | funcs:count(1)->Column#7        |
|     └─Batch_Point_Get_30       | 2.00    | root | table:tkey0, index:col3(col3) | keep order:false, desc:false    |
+--------------------------------+---------+------+-------------------------------+---------------------------------+
6 rows in set, 1 warning (0.01 sec)

@winoros
Copy link
Member Author

winoros commented Mar 5, 2024

After pr #51405 merged, the batchpoint can be used by set the session variables:

set session tidb_skip_missing_partition_stats=0;
set session tidb_opt_fix_control = "";

That is:

mysql> CREATE TABLE tkey0 (col1 INT NOT NULL, col2 DATE NOT NULL, col3 VARCHAR(12) NOT NULL, col4 INT NOT NULL,UNIQUE KEY (col3)) PARTITION BY KEY(col3) PARTITIONS 4;
INSERT INTO tkey0 VALUES(1, '2023-02-22', 'linpin', 1), (2, '2023-02-22', 'zhangsan', 2), (3, '2023-02-22', 'anqila', 3), (4, '2023-02-22', 'xingtian', 4),(1, '2023-02-22', 'renleifeng', 5), (2, '2023-02-22', 'peilin', 2),(1, '2023-02-22', 'abcdeeg', 7), (2, '2023-02-22', 'rpstdfed', 8);Query OK, 0 rows affected (0.13 sec)

mysql> INSERT INTO tkey0 VALUES(1, '2023-02-22', 'linpin', 1), (2, '2023-02-22', 'zhangsan', 2), (3, '2023-02-22', 'anqila', 3), (4, '2023-02-22', 'xingtian', 4),(1, '2023-02-22', 'renleifeng', 5), (2, '2023-02-22', 'peilin', 2),(1, '2023-02-22', 'abcdeeg', 7), (2, '2023-02-22', 'rpstdfed', 8);
Query OK, 8 rows affected (0.02 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> set session tidb_skip_missing_partition_stats=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set session tidb_opt_fix_control = "";
Query OK, 0 rows affected (0.00 sec)

mysql> explain SELECT count(*) FROM tkey0 WHERE col3 = 'zhangsan' or col3 = 'linpin';
+--------------------------------+---------+------+-------------------------------+---------------------------------+
| id                             | estRows | task | access object                 | operator info                   |
+--------------------------------+---------+------+-------------------------------+---------------------------------+
| HashAgg_12                     | 1.00    | root |                               | funcs:count(Column#7)->Column#6 |
| └─PartitionUnion_13            | 2.00    | root |                               |                                 |
|   ├─StreamAgg_17               | 1.00    | root |                               | funcs:count(1)->Column#7        |
|   │ └─Batch_Point_Get_21       | 2.00    | root | table:tkey0, index:col3(col3) | keep order:false, desc:false    |
|   └─StreamAgg_26               | 1.00    | root |                               | funcs:count(1)->Column#7        |
|     └─Batch_Point_Get_30       | 2.00    | root | table:tkey0, index:col3(col3) | keep order:false, desc:false    |
+--------------------------------+---------+------+-------------------------------+---------------------------------+
6 rows in set, 1 warning (0.01 sec)

@jiyfhust
That plan is not expected to be generated by default. It's not related to this thread.

Set tidb_skip_missing_partition_stats to 0 is not an encouraged behavior.

@winoros
Copy link
Member Author

winoros commented Mar 5, 2024

A previous issue link #45532

Wow, i closed this one since there's already one.

@winoros winoros closed this as completed Mar 5, 2024
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. sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

3 participants