planner: a parition table's column UniqueID may mismatch or collide with planner's#13490
planner: a parition table's column UniqueID may mismatch or collide with planner's#13490sre-bot merged 5 commits intopingcap:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #13490 +/- ##
===========================================
Coverage 80.2663% 80.2663%
===========================================
Files 472 472
Lines 115098 115098
===========================================
Hits 92385 92385
Misses 15465 15465
Partials 7248 7248 |
|
/run-all-tests |
|
/run-all-tests |
|
When do pruning, it's used |
Pruning calls |
| case model.PartitionTypeHash: | ||
| return generateHashPartitionExpr(pi, columns, names) | ||
| } | ||
| panic("cannot reach here") |
There was a problem hiding this comment.
create table t partition by list ?
There was a problem hiding this comment.
TiDB currently supports hash partition and range partiion.
mysql> CREATE TABLE employees (
-> id INT NOT NULL,
-> fname VARCHAR(30),
-> lname VARCHAR(30),
-> hired DATE NOT NULL DEFAULT '1970-01-01',
-> separated DATE NOT NULL DEFAULT '9999-12-31',
-> job_code INT,
-> store_id INT
-> )
-> PARTITION BY LIST(store_id) (
-> PARTITION pNorth VALUES IN (3,5,6,9,17),
-> PARTITION pEast VALUES IN (1,2,10,11,19,20),
-> PARTITION pWest VALUES IN (4,12,13,14,18),
-> PARTITION pCentral VALUES IN (7,8,15,16)
-> );
Query OK, 0 rows affected, 1 warning (0.16 sec)
mysql> show warnings;
+---------+------+---------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------+
| Warning | 8200 | Unsupported partition type, treat as normal table |
+---------+------+---------------------------------------------------+
1 row in set (0.00 sec)There was a problem hiding this comment.
And the code of the normal table doesn't run to here, so this panic is reasonable ...
table/tables/partition.go
Outdated
| func (t *partitionedTable) PartitionExpr() *PartitionExpr { | ||
| return t.partitionExpr | ||
| func (t *partitionedTable) PartitionExpr(columns []*expression.Column, names types.NameSlice) (*PartitionExpr, error) { | ||
| return newPartitionExprBySchema(t.meta, columns, names) |
There was a problem hiding this comment.
Is there any way to avoid this allocation every time?
There was a problem hiding this comment.
Maybe we can traverse the Expression, find all columns and rewrite them. We can do it in the future.
|
LGTM. |
|
/run-all-tests |
|
/run-cherry-picker |
|
cherry pick to release-2.1 failed |
|
cherry pick to release-3.0 failed |
…upstream-release-3.0
What problem does this PR solve?
Fix #13491
A partition table's column
UniqueIDis generated by itself using its ownSessionContextand does not associate with planner's.If mismatched, partition pruning does not take any effect.
If collided, partition pruning may prune extra partitions and lead wrong results.
What is changed and how it works?
Use planner's schema to build partition expression during optimization.
Check List
Tests
Code changes
Side effects
Related changes
Release note