版本:v6.5.3
数据来源于tpch
语句:
explain analyze select * from orders where O_ORDERKEY >=(select O_ORDERKEY from orders where O_TOTALPRICE >=370000 order by O_ORDERDATE asc limit 500,1) limit 10;
表结构
mysql> show create table orders;
+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| orders | CREATE TABLE `orders` (
`O_ORDERKEY` bigint(20) NOT NULL,
`O_CUSTKEY` bigint(20) NOT NULL,
`O_ORDERSTATUS` char(1) NOT NULL,
`O_TOTALPRICE` decimal(15,2) NOT NULL,
`O_ORDERDATE` date NOT NULL,
`O_ORDERPRIORITY` char(15) NOT NULL,
`O_CLERK` char(15) NOT NULL,
`O_SHIPPRIORITY` bigint(20) NOT NULL,
`O_COMMENT` varchar(79) NOT NULL,
PRIMARY KEY (`O_ORDERKEY`) /*T![clustered_index] CLUSTERED */,
KEY `index_O_TOTALPRICE` (`O_TOTALPRICE`),
KEY `index_a` (`O_ORDERSTATUS`,`O_TOTALPRICE`),
KEY `indexO_CUSTKEY` (`O_CUSTKEY`),
KEY `index_date` (`O_ORDERDATE`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
在此处键入或粘贴代码
执行计划
mysql> explain analyze select * from orders where O_ORDERKEY >=(select O_ORDERKEY from orders where O_TOTALPRICE >=370000 order by O_ORDERDATE asc limit 500,1) limit 10;
+---------------------------+---------+---------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------+---------+------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+---------------------------+---------+---------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------+---------+------+
| Limit_31 | 10.00 | 10 | root | | time:2.19ms, loops:2 | offset:0, count:10 | N/A | N/A |
| └─TableReader_34 | 10.00 | 32 | root | | time:2.19ms, loops:1, cop_task: {num: 1, max: 2.07ms, proc_keys: 224, rpc_num: 1, rpc_time: 2.04ms, copr_cache: disabled, distsql_concurrency: 15} | data:TableRangeScan_33 | 39.3 KB | N/A |
| └─TableRangeScan_33 | 10.00 | 224 | cop[tikv] | table:orders | tikv_task:{time:0s, loops:3}, scan_detail: {total_process_keys: 224, total_process_keys_size: 33960, total_keys: 225, get_snapshot_time: 20.2µs, rocksdb: {key_skipped_count: 224, block: {cache_hit_count: 7}}} | range:[2980966,+inf], keep order:false | N/A | N/A |
+---------------------------+---------+---------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------+---------+------+
3 rows in set (0.11 sec)
有个比较好奇的点,为什么执行计划没有sort 算子?