pingcap / pingcap/tidb

Dynamic Pruning should work when join partitioned table with non-partitioned table

Open
#41,535 2 comments 0 reactions 2 assignees Claimed by @qw4990 View on GitHub
sig/planner type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Enhancement
As describe in the asktug.
https://asktug.com/t/topic/1001731

```sql
mysql> show create table t1;
±------±---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
±------±---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t1 | CREATE TABLE t1 (
fname varchar(50) NOT NULL,
lname varchar(50) NOT NULL,
region_code tinyint(3) unsigned NOT NULL,
dob date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY RANGE (region_code)
(PARTITION p0 VALUES LESS THAN (64),
PARTITION p1 VALUES LESS THAN (128),
PARTITION p2 VALUES LESS THAN (192),
PARTITION p3 VALUES LESS THAN (MAXVALUE)) |
±------±---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> show create table t2;
±------±-----------------------------------------------------------------------------------------------------------+
| Table | Create Table |
±------±-----------------------------------------------------------------------------------------------------------+
| t2 | CREATE TABLE t2 (
x int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
±------±-----------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

```

```sql
mysql> explain select /*+ INL_JOIN(t1, t2) */ * from t1 left join t2 on
t1.region_code = t2.x where t2.x > 70 and t2.x<120;
±-------------------------------±--------±----------±-----------------------±--------------------------------------------------------+
| id | estRows | task | access object | operator info |
±-------------------------------±--------±----------±-----------------------±--------------------------------------------------------+
| HashJoin_13 | 49.00 | root | | inner join, equal:[eq(zk.t1.region_code, zk.t2.x)] |
| ├─TableReader_26(Build) | 49.00 | root | | data:Selection_25 |
| │ └─Selection_25 | 49.00 | cop[tikv] | | gt(zk.t2.x, 70), lt(zk.t2.x, 120), not(isnull(zk.t2.x)) |
| │ └─TableFullScan_24 | 201.00 | cop[tikv] | table:t2 | keep order:false |
| └─PartitionUnion_15(Probe) | 201.00 | root | | |
| ├─TableReader_17 | 63.00 | root | | data:TableFullScan_16 |
| │ └─TableFullScan_16 | 63.00 | cop[tikv] | table:t1, partition:p0 | keep order:false |
| ├─TableReader_19 | 64.00 | root | | data:TableFullScan_18 |
| │ └─TableFullScan_18 | 64.00 | cop[tikv] | table:t1, partition:p1 | keep order:false |
| ├─TableReader_21 | 64.00 | root | | data:TableFullScan_20 |
| │ └─TableFullScan_20 | 64.00 | cop[tikv] | table:t1, partition:p2 | keep order:false |
| └─TableReader_23 | 10.00 | root | | data:TableFullScan_22 |
| └─TableFullScan_22 | 10.00 | cop[tikv] | table:t1, partition:p3 | keep order:false |
±-------------------------------±--------±----------±-----------------------±--------------------------------------------------------+
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.