From c083849ce1934af6da3f162e61bfa7148b624425 Mon Sep 17 00:00:00 2001 From: shichun-0415 Date: Mon, 28 Mar 2022 14:33:07 +0800 Subject: [PATCH 1/4] add docs for mpp partition table support --- tiflash/use-tiflash.md | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tiflash/use-tiflash.md b/tiflash/use-tiflash.md index fab95904bd08f..f2e509ab1d41d 100644 --- a/tiflash/use-tiflash.md +++ b/tiflash/use-tiflash.md @@ -368,6 +368,71 @@ TiFlash provides the following two global/session variables to control whether t - [`tidb_broadcast_join_threshold_size`](/system-variables.md#tidb_broadcast_join_threshold_count-new-in-v50): The unit of the value is bytes. If the table size (in the unit of bytes) is less than the value of the variable, the Broadcast Hash Join algorithm is used. Otherwise, the Shuffled Hash Join algorithm is used. - [`tidb_broadcast_join_threshold_count`](/system-variables.md#tidb_broadcast_join_threshold_count-new-in-v50): The unit of the value is rows. If the objects of the join operation belong to a subquery, the optimizer cannot estimate the size of the subquery result set, so the size is determined by the number of rows in the result set. If the estimated number of rows in the subquery is less than the value of this variable, the Broadcast Hash Join algorithm is used. Otherwise, the Shuffled Hash Join algorithm is used. +## Access partitioned tables in MPP mode + +When TiDB accesses partitioned tables in [dynamic pruning mode](https://docs.pingcap.com/tidb/stable/partitioned-table#dynamic-pruning-mode), queries on the partitioned tables are executed in the MPP mode. + +> **Note:** +> +> Currently, dynamic pruning mode for partitioned tables is still an experimental feature and is not recommended for production environments. + +Example: + +```sql +mysql> DROP TABLE if exists test.employees; +Query OK, 0 rows affected, 1 warning (0.00 sec) + +mysql> CREATE TABLE test.employees ( id int(11) NOT NULL, fname varchar(30) DEFAULT NULL, lname varchar(30) DEFAULT NULL, hired date NOT NULL DEFAULT '1970-01-01', separated date DEFAULT '99 +99-12-31', job_code int(11) DEFAULT NULL, store_id int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin PARTITION BY RANGE (store_id) (PARTITION p0 VALUES LESS THAN ( +6), PARTITION p1 VALUES LESS THAN (11), PARTITION p2 VALUES LESS THAN (16), PARTITION p3 VALUES LESS THAN (MAXVALUE)); +Query OK, 0 rows affected (0.10 sec) + +mysql> ALTER table test.employees SET tiflash replica 1; +Query OK, 0 rows affected (0.09 sec) + +mysql> SET tidb_partition_prune_mode=static; +Query OK, 0 rows affected (0.00 sec) + +mysql> explain SELECT count(*) FROM test.employees; ++----------------------------------+----------+-------------------+-------------------------------+-----------------------------------+ +| id | estRows | task | access object | operator info | ++----------------------------------+----------+-------------------+-------------------------------+-----------------------------------+ +| HashAgg_19 | 1.00 | root | | funcs:count(Column#10)->Column#9 | +| └─PartitionUnion_21 | 4.00 | root | | | +| ├─StreamAgg_40 | 1.00 | root | | funcs:count(Column#12)->Column#10 | +| │ └─TableReader_41 | 1.00 | root | | data:StreamAgg_27 | +| │ └─StreamAgg_27 | 1.00 | batchCop[tiflash] | | funcs:count(1)->Column#12 | +| │ └─TableFullScan_39 | 10000.00 | batchCop[tiflash] | table:employees, partition:p0 | keep order:false, stats:pseudo | +| ├─StreamAgg_63 | 1.00 | root | | funcs:count(Column#14)->Column#10 | +| │ └─TableReader_64 | 1.00 | root | | data:StreamAgg_50 | +| │ └─StreamAgg_50 | 1.00 | batchCop[tiflash] | | funcs:count(1)->Column#14 | +| │ └─TableFullScan_62 | 10000.00 | batchCop[tiflash] | table:employees, partition:p1 | keep order:false, stats:pseudo | +| ├─StreamAgg_86 | 1.00 | root | | funcs:count(Column#16)->Column#10 | +| │ └─TableReader_87 | 1.00 | root | | data:StreamAgg_73 | +| │ └─StreamAgg_73 | 1.00 | batchCop[tiflash] | | funcs:count(1)->Column#16 | +| │ └─TableFullScan_85 | 10000.00 | batchCop[tiflash] | table:employees, partition:p2 | keep order:false, stats:pseudo | +| └─StreamAgg_109 | 1.00 | root | | funcs:count(Column#18)->Column#10 | +| └─TableReader_110 | 1.00 | root | | data:StreamAgg_96 | +| └─StreamAgg_96 | 1.00 | batchCop[tiflash] | | funcs:count(1)->Column#18 | +| └─TableFullScan_108 | 10000.00 | batchCop[tiflash] | table:employees, partition:p3 | keep order:false, stats:pseudo | ++----------------------------------+----------+-------------------+-------------------------------+-----------------------------------+ +18 rows in set, 4 warnings (0.00 sec) + +mysql> SET tidb_partition_prune_mode=dynamic; +Query OK, 0 rows affected (0.00 sec) + +mysql> explain SELECT count(*) FROM test.employees; ++------------------------------+----------+-------------------+-----------------+----------------------------------+ +| id | estRows | task | access object | operator info | ++------------------------------+----------+-------------------+-----------------+----------------------------------+ +| HashAgg_21 | 1.00 | root | | funcs:count(Column#11)->Column#9 | +| └─TableReader_23 | 1.00 | root | partition:all | data:ExchangeSender_22 | +| └─ExchangeSender_22 | 1.00 | batchCop[tiflash] | | ExchangeType: PassThrough | +| └─HashAgg_9 | 1.00 | batchCop[tiflash] | | funcs:count(1)->Column#11 | +| └─TableFullScan_20 | 10000.00 | batchCop[tiflash] | table:employees | keep order:false, stats:pseudo | ++------------------------------+----------+-------------------+-----------------+----------------------------------+ +``` + ## Data validation ### User scenarios From 503dcd4cf72826cd087d9937495440ed35e68f29 Mon Sep 17 00:00:00 2001 From: shichun-0415 <89768198+shichun-0415@users.noreply.github.com> Date: Mon, 28 Mar 2022 14:48:14 +0800 Subject: [PATCH 2/4] change note to warning --- tiflash/use-tiflash.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tiflash/use-tiflash.md b/tiflash/use-tiflash.md index f2e509ab1d41d..281cbd1e5ad87 100644 --- a/tiflash/use-tiflash.md +++ b/tiflash/use-tiflash.md @@ -372,7 +372,7 @@ TiFlash provides the following two global/session variables to control whether t When TiDB accesses partitioned tables in [dynamic pruning mode](https://docs.pingcap.com/tidb/stable/partitioned-table#dynamic-pruning-mode), queries on the partitioned tables are executed in the MPP mode. -> **Note:** +> **Warning:** > > Currently, dynamic pruning mode for partitioned tables is still an experimental feature and is not recommended for production environments. From 59e21d3c732d18af22bc37dad18ee96994248dfd Mon Sep 17 00:00:00 2001 From: shichun-0415 <89768198+shichun-0415@users.noreply.github.com> Date: Mon, 28 Mar 2022 15:02:37 +0800 Subject: [PATCH 3/4] Update tiflash/use-tiflash.md --- tiflash/use-tiflash.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tiflash/use-tiflash.md b/tiflash/use-tiflash.md index 281cbd1e5ad87..58db4198ffa39 100644 --- a/tiflash/use-tiflash.md +++ b/tiflash/use-tiflash.md @@ -370,7 +370,7 @@ TiFlash provides the following two global/session variables to control whether t ## Access partitioned tables in MPP mode -When TiDB accesses partitioned tables in [dynamic pruning mode](https://docs.pingcap.com/tidb/stable/partitioned-table#dynamic-pruning-mode), queries on the partitioned tables are executed in the MPP mode. +To access partitioned tables in the MPP mode, you need to enable [dynamic pruning mode](https://docs.pingcap.com/tidb/stable/partitioned-table#dynamic-pruning-mode) first. > **Warning:** > From f715d86d992b18a5a97c297ab19c6886842ee559 Mon Sep 17 00:00:00 2001 From: shichun-0415 <89768198+shichun-0415@users.noreply.github.com> Date: Mon, 28 Mar 2022 15:03:09 +0800 Subject: [PATCH 4/4] Update tiflash/use-tiflash.md Co-authored-by: Grace Cai --- tiflash/use-tiflash.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tiflash/use-tiflash.md b/tiflash/use-tiflash.md index 58db4198ffa39..309d0c1ddbb70 100644 --- a/tiflash/use-tiflash.md +++ b/tiflash/use-tiflash.md @@ -368,7 +368,7 @@ TiFlash provides the following two global/session variables to control whether t - [`tidb_broadcast_join_threshold_size`](/system-variables.md#tidb_broadcast_join_threshold_count-new-in-v50): The unit of the value is bytes. If the table size (in the unit of bytes) is less than the value of the variable, the Broadcast Hash Join algorithm is used. Otherwise, the Shuffled Hash Join algorithm is used. - [`tidb_broadcast_join_threshold_count`](/system-variables.md#tidb_broadcast_join_threshold_count-new-in-v50): The unit of the value is rows. If the objects of the join operation belong to a subquery, the optimizer cannot estimate the size of the subquery result set, so the size is determined by the number of rows in the result set. If the estimated number of rows in the subquery is less than the value of this variable, the Broadcast Hash Join algorithm is used. Otherwise, the Shuffled Hash Join algorithm is used. -## Access partitioned tables in MPP mode +## Access partitioned tables in the MPP mode To access partitioned tables in the MPP mode, you need to enable [dynamic pruning mode](https://docs.pingcap.com/tidb/stable/partitioned-table#dynamic-pruning-mode) first.