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

Support BatchPointGet for Range and List Partition #45532

Closed
Defined2014 opened this issue Jul 24, 2023 · 1 comment · Fixed by #45646 or #49161
Closed

Support BatchPointGet for Range and List Partition #45532

Defined2014 opened this issue Jul 24, 2023 · 1 comment · Fixed by #45646 or #49161
Labels
component/tablepartition This issue is related to Table Partition of TiDB. type/enhancement

Comments

@Defined2014
Copy link
Contributor

Defined2014 commented Jul 24, 2023

Enhancement

We could support BatchPointGet plan for Range and List Partition and remove the code below.

// We can only build batch point get for hash partitions on a simple column now. This is
// decided by the current implementation of `BatchPointGetExec::initialize()`, specifically,
// the `getPhysID()` function. Once we optimize that part, we can come back and enable
// BatchPointGet plan for more cases.
hashPartColName = getHashOrKeyPartitionColumnName(ds.ctx, tblInfo)
if hashPartColName == nil {
canConvertPointGet = false
}
}

Some things need to consider,

  1. Support keepOrder = true for partition table in BatchPointGetExec #45702
  2. Explain info, like Support display partition info for batchPointGet on normal plan way #45888
  3. join partition return wrong result #45720
  4. The statement: select ... where _tidb_rowid in (...) returns an wrong result #45889
  5. case *plannercore.BatchPointGetPlan:
    , prefetchPointPlanKeys function, not sure if this will affect.

Most test cases are added in TestBatchPointGetTablePartition, but please take care about all of them.

@Defined2014
Copy link
Contributor Author

Some interesting things

mysql> show create table t;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                                     |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `a` int(11) NOT NULL,
  `b` int(11) DEFAULT NULL,
  PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY RANGE (`a`)
(PARTITION `p0` VALUES LESS THAN (10),
 PARTITION `p1` VALUES LESS THAN (20)) |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

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

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

mysql> explain select * from t where a in (1, 11, -1);
+------------------------+---------+-----------+---------------+---------------------------------------------------------------+
| id                     | estRows | task      | access object | operator info                                                 |
+------------------------+---------+-----------+---------------+---------------------------------------------------------------+
| TableReader_6          | 3.00    | root      | partition:all | data:TableRangeScan_5                                         |
| └─TableRangeScan_5     | 3.00    | cop[tikv] | table:t       | range:[-1,-1], [1,1], [11,11], keep order:false, stats:pseudo |
+------------------------+---------+-----------+---------------+---------------------------------------------------------------+
2 rows in set (0.00 sec)

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. type/enhancement
Projects
None yet
1 participant