【 TiDB 使用环境】测试
【 TiDB 版本】5.7.25-TiDB-v7.3.0
mysql> explain analyze select count(*) from customer a where exists (select 1 from customer b where a.C_NATIONKEY=b.C_NATIONKEY);
+-------------------------------+------------+---------+-----------+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------+----------+---------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+-------------------------------+------------+---------+-----------+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------+----------+---------+
| StreamAgg_11 | 1.00 | 1 | root | | time:1h15m6.9s, loops:2 | funcs:count(1)->Column#18 | 8 Bytes | N/A |
| └─HashJoin_17 | 1200000.00 | 1500000 | root | | time:1h15m6.9s, loops:1467, build_hash_table:{total:585.7ms, fetch:473.8ms, build:111.9ms}, probe:{concurrency:5, total:6h15m19.3s, max:1h15m6.9s, probe:6h15m14.7s, fetch:4.65s} | semi join, equal:[eq(tpch10.customer.c_nationkey, tpch10.customer.c_nationkey)] | 46.3 MB | 0 Bytes |
| ├─TableReader_16(Build) | 1500000.00 | 1500000 | root | | time:471.4ms, loops:1468, cop_task: {num: 54, max: 66.6ms, min: 1.34ms, avg: 26.2ms, p95: 62.3ms, max_proc_keys: 50144, p95_proc_keys: 50144, tot_proc: 1.19s, tot_wait: 15ms, rpc_num: 54, rpc_time: 1.41s, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15} | data:TableFullScan_15 | 785.3 KB | N/A |
| │ └─TableFullScan_15 | 1500000.00 | 1500000 | cop[tikv] | table:b | tikv_task:{proc max:61ms, min:0s, avg: 21.9ms, p80:41ms, p95:53ms, iters:1678, tasks:54}, scan_detail: {total_process_keys: 1500000, total_process_keys_size: 305225771, total_keys: 1500054, get_snapshot_time: 1.58ms, rocksdb: {key_skipped_count: 1500000, block: {cache_hit_count: 160, read_count: 4992, read_byte: 112.6 MB, read_time: 57.9ms}}} | keep order:false | N/A | N/A |
| └─TableReader_14(Probe) | 1500000.00 | 1500000 | root | | time:88.1ms, loops:1468, cop_task: {num: 54, max: 50ms, min: 624.9µs, avg: 13.8ms, p95: 45.9ms, max_proc_keys: 50144, p95_proc_keys: 50144, tot_proc: 71ms, tot_wait: 111ms, rpc_num: 54, rpc_time: 745.2ms, copr_cache_hit_ratio: 0.70, distsql_concurrency: 15} | data:TableFullScan_13 | 1.53 MB | N/A |
| └─TableFullScan_13 | 1500000.00 | 1500000 | cop[tikv] | table:a | tikv_task:{proc max:61ms, min:0s, avg: 21ms, p80:41ms, p95:53ms, iters:1678, tasks:54}, scan_detail: {total_process_keys: 191231, total_process_keys_size: 38891884, total_keys: 191247, get_snapshot_time: 71.8ms, rocksdb: {key_skipped_count: 191231, block: {cache_hit_count: 670, read_count: 15, read_byte: 1019.5 KB, read_time: 1.6ms}}} | keep order:false | N/A | N/A |
+-------------------------------+------------+---------+-----------+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------+----------+---------+
6 rows in set (1 hour 15 min 6.93 sec)
表结构如下:
mysql> show create table customer \G
*************************** 1. row ***************************
Table: customer
Create Table: CREATE TABLE `customer` (
`C_CUSTKEY` bigint(20) NOT NULL,
`C_NAME` varchar(25) NOT NULL,
`C_ADDRESS` varchar(40) NOT NULL,
`C_NATIONKEY` bigint(20) NOT NULL,
`C_PHONE` char(15) NOT NULL,
`C_ACCTBAL` decimal(15,2) NOT NULL,
`C_MKTSEGMENT` char(10) NOT NULL,
`C_COMMENT` varchar(117) NOT NULL,
PRIMARY KEY (`C_CUSTKEY`) /*T![clustered_index] CLUSTERED */,
KEY `idx2` (`C_PHONE`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.01 sec)
mysql> select count(C_NATIONKEY),count(distinct C_NATIONKEY) from customer;
+--------------------+-----------------------------+
| count(C_NATIONKEY) | count(distinct C_NATIONKEY) |
+--------------------+-----------------------------+
| 1500000 | 25 |
+--------------------+-----------------------------+
1 row in set (0.12 sec)
半连接为何这么慢呢,应该几秒钟出结果比较正常吧?