diff --git a/tiflash/use-tiflash.md b/tiflash/use-tiflash.md index fab95904bd08..309d0c1ddbb7 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 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:** +> +> 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