Too many partitions can affect performance within a transaction
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
run tpcc with table partition by hash (`w_id`) partitions 1000, the TiDB profiling is as follows:
Version:
```
INFORMATION_SCHEMA> select `type`, version, git_hash from cluster_info;
+------+-------------------------------+------------------------------------------+
| type | version | git_hash |
+------+-------------------------------+------------------------------------------+
| tidb | 9.0.0-beta.2.pre-143-g1ebe58b | 1ebe58bade11d53b62ad8fca16db6bca3d117b64 |
| tidb | 9.0.0-beta.2.pre-143-g1ebe58b | 1ebe58bade11d53b62ad8fca16db6bca3d117b64 |
| tidb | 9.0.0-beta.2.pre-143-g1ebe58b | 1ebe58bade11d53b62ad8fca16db6bca3d117b64 |
| pd | 9.0.0-beta.2.pre-25-g7a5b221 | 7a5b221cf66ec469727f8c174493f9132c0b9d8f |
| pd | 9.0.0-beta.2.pre-25-g7a5b221 | 7a5b221cf66ec469727f8c174493f9132c0b9d8f |
| pd | 9.0.0-beta.2.pre-25-g7a5b221 | 7a5b221cf66ec469727f8c174493f9132c0b9d8f |
| tikv | 9.0.0-beta.2 | bde3acece6606816a517ecfeedb34ebb4640f452 |
| tikv | 9.0.0-beta.2 | bde3acece6606816a517ecfeedb34ebb4640f452 |
| tikv | 9.0.0-beta.2 | bde3acece6606816a517ecfeedb34ebb4640f452 |
+------+-------------------------------+------------------------------------------+
```
TPCC schema:
```sql
CREATE TABLE `customer` (
`c_id` int NOT NULL,
`c_d_id` int NOT NULL,
`c_w_id` int NOT NULL,
`c_first` varchar(16) DEFAULT NULL,
`c_middle` char(2) DEFAULT NULL,
`c_last` varchar(16) DEFAULT NULL,
`c_street_1` varchar(20) DEFAULT NULL,
`c_street_2` varchar(20) DEFAULT NULL,
`c_city` varchar(20) DEFAULT NULL,
`c_state` char(2) DEFAULT NULL,
`c_zip` char(9) DEFAULT NULL,
`c_phone` char(16) DEFAULT NULL,
`c_since` datetime DEFAULT NULL,
`c_credit` char(2) DEFAULT NULL,
`c_credit_lim` decimal(12,2) DEFAULT NULL,
`c_discount` decimal(4,4) DEFAULT NULL,
`c_balance` decimal(12,2) DEFAULT NULL,
`c_ytd_payment` decimal(12,2) DEFAULT NULL,
`c_payment_cnt` int DEFAULT NULL,
`c_delivery_cnt` int DEFAULT NULL,
`c_data` varchar(500) DEFAULT NULL,
PRIMARY KEY (`c_w_id`,`c_d_id`,`c_id`) /*T![clustered_index] CLUSTERED */,
KEY `idx_customer` (`c_w_id`,`c_d_id`,`c_last`,`c_first`)
) PARTITION BY HASH (c_w_id) PARTITIONS 1000;
CREATE TABLE `district` (
`d_id` int NOT NULL,
`d_w_id` int NOT NULL,
`d_name` varchar(10) DEFAULT NULL,
`d_street_1` varchar(20) DEFAULT NULL,
`d_street_2` varchar(20) DEFAULT NULL,
`d_city` varchar(20) DEFAULT NULL,
`d_state` char(2) DEFAULT NULL,
`d_zip` char(9) DEFAULT NULL,
`d_tax` decimal(4,4) DEFAULT NULL,
`d_ytd` decimal(12,2) DEFAULT NULL,
`d_next_o_id` int DEFAULT NULL,
PRIMARY KEY (`d_w_id`,`d_id`) /*T![clustered_index] CLUSTERED */
) PARTITION BY HASH (d_w_id) PARTITIONS 1000;
CREATE TABLE `history` (
`h_c_id` int NOT NULL,
`h_c_d_id` int NOT NULL,
`h_c_w_id` int NOT NULL,
`h_d_id` int NOT NULL,
`h_w_id` int NOT NULL,
`h_date` datetime DEFAULT NULL,
`h_amount` decimal(6,2) DEFAULT NULL,
`h_data` varchar(24) DEFAULT NULL,
KEY `idx_h_w_id` (`h_w_id`),
KEY `idx_h_c_w_id` (`h_c_w_id`)
) PARTITION BY HASH (h_w_id) PARTITIONS 1000;
-- 固定 10 万行,没有 w_id, 不用创建分区表。
CREATE TABLE `item` (
`i_id` int NOT NULL,
`i_im_id` int DEFAULT NULL,
`i_name` varchar(24) DEFAULT NULL,
`i_price` decimal(5,2) DEFAULT NULL,
`i_data` varchar(50) DEFAULT NULL,
PRIMARY KEY (`i_id`) /*T![clustered_index] CLUSTERED */
);
split table item between (0) and (100000) regions 4;
CREATE TABLE `new_order` (
`no_o_id` int NOT NULL,
`no_d_id` int NOT NULL,
`no_w_id` int NOT NULL,
PRIMARY KEY (`no_w_id`,`no_d_id`,`no_o_id`) /*T![clustered_index] CLUSTERED */
) PARTITION BY HASH (no_w_id) PARTITIONS 1000;
CREATE TABLE `order_line` (
`ol_o_id` int NOT NULL,
`ol_d_id` int NOT NULL,
`ol_w_id` int NOT NULL,
`ol_number` int NOT NULL,
`ol_i_id` int NOT NULL,
`ol_supply_w_id` int DEFAULT NULL,
`ol_delivery_d` datetime DEFAULT NULL,
`ol_quantity` int DEFAULT NULL,
`ol_amount` decimal(6,2) DEFAULT NULL,
`ol_dist_info` char(24) DEFAULT NULL,
PRIMARY KEY (`ol_w_id`,`ol_d_id`,`ol_o_id`,`ol_number`) /*T![clustered_index] CLUSTERED */
) PARTITION BY HASH (ol_w_id) PARTITIONS 1000;
CREATE TABLE `orders` (
`o_id` int NOT NULL,
`o_d_id` int NOT NULL,
`o_w_id` int NOT NULL,
`o_c_id` int DEFAULT NULL,
`o_entry_d` datetime DEFAULT NULL,
`o_carrier_id` int DEFAULT NULL,
`o_ol_cnt` int DEFAULT NULL,
`o_all_local` int DEFAULT NULL,
PRIMARY KEY (`o_w_id`,`o_d_id`,`o_id`) /*T![clustered_index] CLUSTERED */,
KEY `idx_order` (`o_w_id`,`o_d_id`,`o_c_id`,`o_id`)
) PARTITION BY HASH (o_w_id) PARTITIONS 1000;
CREATE TABLE `stock` (
`s_i_id` int NOT NULL,
`s_w_id` int NOT NULL,
`s_quantity` int DEFAULT NULL,
`s_dist_01` char(24) DEFAULT NULL,
`s_dist_02` char(24) DEFAULT NULL,
`s_dist_03` char(24) DEFAULT NULL,
`s_dist_04` char(24) DEFAULT NULL,
`s_dist_05` char(24) DEFAULT NULL,
`s_dist_06` char(24) DEFAULT NULL,
`s_dist_07` char(24) DEFAULT NULL,
`s_dist_08` char(24) DEFAULT NULL,
`s_dist_09` char(24) DEFAULT NULL,
`s_dist_10` char(24) DEFAULT NULL,
`s_ytd` int DEFAULT NULL,
`s_order_cnt` int DEFAULT NULL,
`s_remote_cnt` int DEFAULT NULL,
`s_data` varchar(50) DEFAULT NULL,
PRIMARY KEY (`s_w_id`,`s_i_id`) /*T![clustered_index] CLUSTERED */
) PARTITION BY HASH (s_w_id) PARTITIONS 1000;
CREATE TABLE `warehouse` (
`w_id` int NOT NULL,
`w_name` varchar(10) DEFAULT NULL,
`w_street_1` varchar(20) DEFAULT NULL,
`w_street_2` varchar(20) DEFAULT NULL,
`w_city` varchar(20) DEFAULT NULL,
`w_state` char(2) DEFAULT NULL,
`w_zip` char(9) DEFAULT NULL,
`w_tax` decimal(4,4) DEFAULT NULL,
`w_ytd` decimal(12,2) DEFAULT NULL,
PRIMARY KEY (`w_id`) /*T![clustered_index] CLUSTERED */
) PARTITION BY HASH (w_id) PARTITIONS 1000;
```
Contributor guide
Assessment
This issue has not been assessed yet.