rows_examined是什么?
https://dev.mysql.com/doc/refman/8.4/en/slow-query-log.html
文档上的slow query log部分有解释:
The number of rows examined by the server layer (not counting any processing internal to storage engines).
rows examined实际上是server层检查的行数,没有统计storage engine层内部处理的行数。这样很多看似是有问题的,就很好理解了,
但是,很多人把rows examined当成SQL性能的一种重要指标,认为这个是SQL扫描的行数,这就有问题了,实际上rows examined有时候,并不能准确反应storage engines扫描的行数。
engine层返回给server层数据,engine层对表使用访问方法:索引访问、全表扫描,过滤条件也即执行计划里的Filter是在server层做的。
如果索引访问有ICP,则可能导致rows_examined并不能反应索引真正扫描的行数,还有其它缺陷,比如分组聚合、排序影响。
总结如下:
1)二级索引的ICP,会导致返回给server层行数变少,所以此时的rows_examined是包含ICP的结果,并不能准确反应索引扫描的行数。
而覆盖索引扫描,是没有ICP的,过滤发生在server层,则是准确的。
2)分组聚合如果没有其他字段会让Rows_examined是0,这应该是个BUG
3)index skip scan貌似是0,禁用skip scan则rows_examined不是0
4)排序的行数会加到Rows_examined里,如果有limit,rows_examined会加上limit行数。
1.有ICP时候rows_examined不能反应索引扫描的行数
-
explain select * from employees e where e.first_name like 'Am%' and e.last_name like 'B%';
-
+----+-------------+-------+------------+-------+-------------------+----------+---------+------+------+----------+-----------------------+
-
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
-
+----+-------------+-------+------------+-------+-------------------+----------+---------+------+------+----------+-----------------------+
-
| 1 | SIMPLE | e | NULL | range | idx1_emp,idx2_emp | idx1_emp | 94 | NULL | 696 | 11.11 | Using index condition |
-
+----+-------------+-------+------------+-------+-------------------+----------+---------+------+------+----------+-----------------------+
-
1 row in set, 1 warning (0.00 sec)
-
-
flush status;
-
show status like '%handler_read%';
-
+-----------------------+-------+
-
| Variable_name | Value |
-
+-----------------------+-------+
-
| Handler_read_first | 0 |
-
| Handler_read_key | 0 |
-
| Handler_read_last | 0 |
-
| Handler_read_next | 0 |
-
| Handler_read_prev | 0 |
-
| Handler_read_rnd | 0 |
-
| Handler_read_rnd_next | 0 |
-
+-----------------------+-------+
-
7 rows in set (0.00 sec)
-
-
explain analyze select * from employees e where e.first_name like 'Am%' and e.last_name like 'B%'\G
-
*************************** 1. row ***************************
-
EXPLAIN: -> Index range scan on e using idx1_emp over
-
('Am\0\0\0\0\0\0\0\0\0\0\0\0' <= first_name <= 'Am????????????' AND 'B\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'
-
<= last_name <= 'B???????????????'), with index condition: ((e.first_name like 'Am%') and (e.last_name like 'B%'))
-
(cost=836.21 rows=696) (actual time=3.599..65.615 rows=69 loops=1)
-
-
1 row in set (0.07 sec)
-
-
(root@localhost) [employees_10:58:41]> show status like '%handler_read%';
-
+-----------------------+-------+
-
| Variable_name | Value |
-
+-----------------------+-------+
-
| Handler_read_first | 0 |
-
| Handler_read_key | 1 |
-
| Handler_read_last | 0 |
-
| Handler_read_next | 69 |
-
| Handler_read_prev | 0 |
-
| Handler_read_rnd | 0 |
-
| Handler_read_rnd_next | 0 |
-
+-----------------------+-------+
-
7 rows in set (0.00 sec)
-
-
select THREAD_ID,SQL_TEXT,ROWS_AFFECTED,ROWS_SENT,ROWS_EXAMINED from performance_schema.events_statements_history where thread_id=48;
-
+-----------+---------------------------------------------------------------------------------------------------+---------------+-----------+---------------+
-
| THREAD_ID | SQL_TEXT | ROWS_AFFECTED | ROWS_SENT | ROWS_EXAMINED |
-
+-----------+---------------------------------------------------------------------------------------------------+---------------+-----------+---------------+
-
| 48 | show status like '%handler_read%' | 0 | 7 | 7 |
-
| 48 | explain analyze select * from employees e where e.first_name like 'Am%' and e.last_name like 'B%' | 0 | 1 | 69 |
-
+-----------+---------------------------------------------------------------------------------------------------+---------------+-----------+---------------+
-
10 rows in set (0.00 sec)
-
-
# Time: 2025-03-14T10:58:41.069062+08:00
-
# User@Host: root[root] @ localhost [] Id: 8
-
# Query_time: 0.066471 Lock_time: 0.000005 Rows_sent: 1 Rows_examined: 69 Thread_id: 8 Errno: 0 Killed: 0 Bytes_received: 104 Bytes_sent: 440 Read_first: 0 Read_last: 0 Read_key: 1 Read_next: 69 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 0 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T10:58:41.002591+08:00 End: 2025-03-14T10:58:41.069062+08:00
-
SET timestamp=1741921121;
-
explain analyze select * from employees e where e.first_name like 'Am%' and e.last_name like 'B%';
实际行数:实际上index access只按前导列,应该是扫描696行,但是rows_examined=69行,这是MySQL缺陷,
MySQL的rows_examined实际上是engine返回给server层的行数,因为有ICP,导致返回给server层行数包括ICP,
对应的行数是engine(index)=69行--->engine(table)回表 69行--->server 69行:
-
select count(*) from employees e where e.first_name like 'Am%';
-
+----------+
-
| count(*) |
-
+----------+
-
| 696 |
-
+----------+
-
-
select count(*) from employees e where e.first_name like 'Am%' and e.last_name like 'B%' ;
-
+----------+
-
| count(*) |
-
+----------+
-
| 69 |
-
+----------+
如果没有ICP,比如下面的是覆盖索引扫描,则是696行,直接访问表扫描696行,过滤是在server层做的。
-
explain select first_name,last_name from employees e where e.first_name like 'Am%' and e.last_name like 'B%'
-
-> ;
-
+----+-------------+-------+------------+-------+-------------------+----------+---------+------+------+----------+--------------------------+
-
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
-
+----+-------------+-------+------------+-------+-------------------+----------+---------+------+------+----------+--------------------------+
-
| 1 | SIMPLE | e | NULL | range | idx1_emp,idx2_emp | idx1_emp | 94 | NULL | 696 | 11.11 | Using where; Using index |
-
+----+-------------+-------+------------+-------+-------------------+----------+---------+------+------+----------+--------------------------+
-
1 row in set, 1 warning (0.00 sec)
-
-
explain analyze select first_name,last_name from employees e where e.first_name like 'Am%' and e.last_name like 'B%'\G
-
*************************** 1. row ***************************
-
EXPLAIN: -> Filter: ((e.first_name like 'Am%') and (e.last_name like 'B%')) (cost=141.53 rows=77) (actual time=0.053..0.584 rows=69 loops=1)
-
-> Covering index range scan on e using idx1_emp over ('Am\0\0\0\0\0\0\0\0\0\0\0\0' <= first_name <= 'Am????????????' AND 'B\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' <= last_name <= 'B???????????????') (cost=141.53 rows=696) (actual time=0.030..0.431 rows=696 loops=1)
-
-
1 row in set (0.00 sec)
-
-
# Time: 2025-03-14T14:31:44.984084+08:00
-
# User@Host: root[root] @ localhost [] Id: 15
-
# Query_time: 0.001385 Lock_time: 0.000004 Rows_sent: 1 Rows_examined: 696 Thread_id: 15 Errno: 0 Killed: 0 Bytes_received: 123 Bytes_sent: 507 Read_first: 0 Read_last: 0 Read_key: 1 Read_next: 696 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 0 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T14:31:44.982699+08:00 End: 2025-03-14T14:31:44.984084+08:00
-
SET timestamp=1741933904;
-
explain analyze select first_name,last_name from employees e where e.first_name like 'Am%' and e.last_name like 'B%';
可以看到,覆盖索引扫描的Rows_examined: 696。
2.分组聚合,如果是通过索引直接聚合的会让Rows_examined是0,如果是全表扫描则没有问题
无条件的聚合操作,Rows_examined: 0,因为走索引
-
select count(*) from employees e;
-
+----------+
-
| count(*) |
-
+----------+
-
| 300024 |
-
+----------+
-
1 row in set (0.14 sec)
-
-
explain select count(*) from employees e;
-
+----+-------------+-------+------------+-------+---------------+----------+---------+------+--------+----------+-------------+
-
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
-
+----+-------------+-------+------------+-------+---------------+----------+---------+------+--------+----------+-------------+
-
| 1 | SIMPLE | e | NULL | index | NULL | idx3_emp | 1 | NULL | 300024 | 100.00 | Using index |
-
+----+-------------+-------+------------+-------+---------------+----------+---------+------+--------+----------+-------------+
-
1 row in set, 1 warning (0.01 sec)
-
-
select THREAD_ID,SQL_TEXT,ROWS_AFFECTED,ROWS_SENT,ROWS_EXAMINED from performance_schema.events_statements_history where thread_id=48;
-
+-----------+---------------------------------------------------------------------------------------------------+---------------+-----------+---------------+
-
| THREAD_ID | SQL_TEXT | ROWS_AFFECTED | ROWS_SENT | ROWS_EXAMINED |
-
+-----------+---------------------------------------------------------------------------------------------------+---------------+-----------+---------------+
-
| 48 | select count(*) from employees e | 0 | 1 | 0 |
-
-
-
# Time: 2025-03-14T11:02:53.082873+08:00
-
# User@Host: root[root] @ localhost [] Id: 8
-
# Query_time: 0.130915 Lock_time: 0.000005 Rows_sent: 1 Rows_examined: 0 Thread_id: 8 Errno: 0 Killed: 0 Bytes_received: 39 Bytes_sent: 61 Read_first: 0 Read_last: 0 Read_key: 0 Read_next: 0 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 0 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T11:02:52.951958+08:00 End: 2025-03-14T11:02:53.082873+08:00
-
SET timestamp=1741921372;
-
select count(*) from employees e;
-
-
-
有条件的也是Rows_examined: 0,因为走last_name列索引
-
select count(*) from employees e where last_name like 'A%';
-
+----------+
-
| count(*) |
-
+----------+
-
| 10673 |
-
+----------+
-
-
-
# Time: 2025-03-14T11:03:51.564739+08:00
-
# User@Host: root[root] @ localhost [] Id: 8
-
# Query_time: 0.107009 Lock_time: 0.000005 Rows_sent: 1 Rows_examined: 0 Thread_id: 8 Errno: 0 Killed: 0 Bytes_received: 65 Bytes_sent: 60 Read_first: 1 Read_last: 0 Read_key: 2551 Read_next: 10673 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 0 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T11:03:51.457730+08:00 End: 2025-03-14T11:03:51.564739+08:00
-
SET timestamp=1741921431;
-
select count(*) from employees e where last_name like 'A%';
-
-
-
# Time: 2025-03-14T11:04:47.356855+08:00
-
# User@Host: root[root] @ localhost [] Id: 8
-
# Query_time: 0.026070 Lock_time: 0.000005 Rows_sent: 1 Rows_examined: 0 Thread_id: 8 Errno: 0 Killed: 0 Bytes_received: 71 Bytes_sent: 66 Read_first: 1 Read_last: 0 Read_key: 2551 Read_next: 10673 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 0 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T11:04:47.330785+08:00 End: 2025-03-14T11:04:47.356855+08:00
-
SET timestamp=1741921487;
-
select max(last_name) from employees e where last_name like 'A%';
-
-
-- 全表扫描则没有问题
-
SELECT/*+no_index(e)*/ COUNT(*) FROM employees e WHERE last_name LIKE 'A%';
-
+----------+
-
| COUNT(*) |
-
+----------+
-
| 10673 |
-
+----------+
-
1 row in set (0.10 sec)
-
-
# Time: 2025-03-14T15:06:13.796973+08:00
-
# User@Host: root[root] @ localhost [] Id: 15
-
# Query_time: 0.092579 Lock_time: 0.000006 Rows_sent: 1 Rows_examined: 300024 Thread_id: 15 Errno: 0 Killed: 0 Bytes_received: 81 Bytes_sent: 60 Read_first: 1 Read_last: 0 Read_key: 1 Read_next: 0 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 300025 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T15:06:13.704394+08:00 End: 2025-03-14T15:06:13.796973+08:00
-
SET timestamp=1741935973;
-
SELECT/*+no_index(e)*/ COUNT(*) FROM employees e WHERE last_name LIKE 'A%';
3.index skip scan貌似是0,禁用skip scan则rows_examined不是0
-
explain select last_name from employees e where last_name like 'A%';
-
+----+-------------+-------+------------+-------+-------------------+----------+---------+------+-------+----------+----------------------------------------+
-
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
-
+----+-------------+-------+------------+-------+-------------------+----------+---------+------+-------+----------+----------------------------------------+
-
| 1 | SIMPLE | e | NULL | range | idx1_emp,idx2_emp | idx1_emp | 94 | NULL | 33332 | 100.00 | Using where; Using index for skip scan |
-
+----+-------------+-------+------------+-------+-------------------+----------+---------+------+-------+----------+----------------------------------------+
-
1 row in set, 1 warning (0.00 sec)
-
-
-- index skip scan的Rows_examined: 0
-
# User@Host: root[root] @ localhost [] Id: 8
-
# Query_time: 0.030014 Lock_time: 0.000006 Rows_sent: 10673 Rows_examined: 0 Thread_id: 8 Errno: 0 Killed: 0 Bytes_received: 66 Bytes_sent: 129296 Read_first: 1 Read_last: 0 Read_key: 2551 Read_next: 10673 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 0 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T11:05:08.350082+08:00 End: 2025-03-14T11:05:08.380096+08:00
-
SET timestamp=1741921508;
-
select last_name from employees e where last_name like 'A%';
-
-
-
-- 禁用skip scan则rows_examined不是0
-
select/*+set_var(optimizer_switch='skip_scan=off')*/ last_name from employees e where last_name like 'A%';
-
-
# Time: 2025-03-14T15:18:20.895184+08:00
-
# User@Host: root[root] @ localhost [] Id: 15
-
# Query_time: 0.083965 Lock_time: 0.000005 Rows_sent: 10673 Rows_examined: 300024 Thread_id: 15 Errno: 0 Killed: 0 Bytes_received: 112 Bytes_sent: 129296 Read_first: 1 Read_last: 0 Read_key: 1 Read_next: 300024 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 0 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T15:18:20.811219+08:00 End: 2025-03-14T15:18:20.895184+08:00
-
SET timestamp=1741936700;
-
select/*+set_var(optimizer_switch='skip_scan=off')*/ last_name from employees e where last_name like 'A%';
-
-
-
-
-
有其他字段则可以
-
select gender,count(*) from employees e where last_name like 'A%' group by gender;
-
# Time: 2025-03-14T14:49:36.060981+08:00
-
# User@Host: root[root] @ localhost [] Id: 15
-
# Query_time: 0.886257 Lock_time: 0.000008 Rows_sent: 2 Rows_examined: 300024 Thread_id: 15 Errno: 0 Killed: 0 Bytes_received: 88 Bytes_sent: 129 Read_first: 1 Read_last: 0 Read_key: 1 Read_next: 300024 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 0 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T14:49:35.174724+08:00 End: 2025-03-14T14:49:36.060981+08:00
-
SET timestamp=1741934975;
-
select gender,count(*) from employees e where last_name like 'A%' group by gender;
-
-
-- 查点其他字段才对,Rows_examined: 300024
-
-
# Time: 2025-03-14T11:05:51.264599+08:00
-
# User@Host: root[root] @ localhost [] Id: 8
-
# Query_time: 0.153229 Lock_time: 0.000004 Rows_sent: 1 Rows_examined: 300024 Thread_id: 8 Errno: 0 Killed: 0 Bytes_received: 75 Bytes_sent: 266 Read_first: 1 Read_last: 0 Read_key: 1 Read_next: 0 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 300025 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T11:05:51.111370+08:00 End: 2025-03-14T11:05:51.264599+08:00
-
SET timestamp=1741921551;
-
explain analyze select * from employees e where last_name like 'A%';
-
-
4.order by的行会累加到rows_examined,这个应该也是BUG,order by实际上是在server层发生的
-
-- order by竟然让Rows_examined翻倍
-
# Time: 2025-03-14T11:06:59.889233+08:00
-
# User@Host: root[root] @ localhost [] Id: 8
-
# Query_time: 0.000366 Lock_time: 0.000005 Rows_sent: 10 Rows_examined: 10 Thread_id: 8 Errno: 0 Killed: 0 Bytes_received: 29 Bytes_sent: 131 Read_first: 1 Read_last: 0 Read_key: 1 Read_next: 0 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 11 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T11:06:59.888867+08:00 End: 2025-03-14T11:06:59.889233+08:00
-
SET timestamp=1741921619;
-
select * from limit_t1;
-
# Time: 2025-03-14T11:07:14.836767+08:00
-
# User@Host: root[root] @ localhost [] Id: 8
-
# Query_time: 0.000443 Lock_time: 0.000005 Rows_sent: 10 Rows_examined: 20 Thread_id: 8 Errno: 0 Killed: 0 Bytes_received: 41 Bytes_sent: 131 Read_first: 1 Read_last: 0 Read_key: 1 Read_next: 0 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 11 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 10 Sort_scan_count: 1 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T11:07:14.836324+08:00 End: 2025-03-14T11:07:14.836767+08:00
-
SET timestamp=1741921634;
-
select * from limit_t1 order by id;
-
-
-
-- 走索引,查询出4行,对
-
# Time: 2025-03-14T11:09:16.819234+08:00
-
# User@Host: root[root] @ localhost [] Id: 8
-
# Query_time: 0.000482 Lock_time: 0.000005 Rows_sent: 4 Rows_examined: 4 Thread_id: 8 Errno: 0 Killed: 0 Bytes_received: 52 Bytes_sent: 95 Read_first: 0 Read_last: 0 Read_key: 1 Read_next: 4 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 0 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T11:09:16.818752+08:00 End: 2025-03-14T11:09:16.819234+08:00
-
SET timestamp=1741921756;
-
select * from limit_t1 where id>3 order by id;
-
-
-
-
-
show create table t\G
-
*************************** 1. row ***************************
-
Table: t
-
Create Table: CREATE TABLE `t` (
-
`id` int NOT NULL,
-
`a` int DEFAULT NULL,
-
`b` int DEFAULT NULL,
-
PRIMARY KEY (`id`),
-
KEY `idx_a` (`a`),
-
KEY `idx1_t` (`b`)
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
-
1 row in set (0.00 sec)
-
-
(root@localhost) [employees_11:10:17]> select * from t;
-
+----+------+------+
-
| id | a | b |
-
+----+------+------+
-
| 1 | 1 | 1 |
-
| 2 | 1 | 2 |
-
| 3 | 1 | 3 |
-
| 4 | 1 | 4 |
-
| 5 | 1 | 5 |
-
| 6 | 1 | 6 |
-
| 7 | 1 | 7 |
-
| 8 | 1 | 8 |
-
| 9 | 1 | 9 |
-
| 10 | 1 | 10 |
-
+----+------+------+
-
10 rows in set (0.00 sec)
-
-
(root@localhost) [employees_11:10:21]> select * from t where a=1 and b>3 order by b limit 2;
-
+----+------+------+
-
| id | a | b |
-
+----+------+------+
-
| 4 | 1 | 4 |
-
| 5 | 1 | 5 |
-
+----+------+------+
-
2 rows in set (0.00 sec)
-
-
表有10行,order by limit 2,Rows_examined: 12,还是order by问题,因为a列有索引,全是1,读取10行+排序2行=12
-
# Time: 2025-03-14T11:10:35.769475+08:00
-
# User@Host: root[root] @ localhost [] Id: 8
-
# Query_time: 0.000579 Lock_time: 0.000007 Rows_sent: 2 Rows_examined: 12 Thread_id: 8 Errno: 0 Killed: 0 Bytes_received: 59 Bytes_sent: 155 Read_first: 0 Read_last: 0 Read_key: 1 Read_next: 10 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 0 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 2 Sort_scan_count: 1 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T11:10:35.768896+08:00 End: 2025-03-14T11:10:35.769475+08:00
-
SET timestamp=1741921835;
-
select * from t where a=1 and b>3 order by b limit 2;
-
-
-
-
explain select * from t where a=1 and b>3 order by b limit 2;
-
+----+-------------+-------+------------+------+---------------+-------+---------+-------+------+----------+-----------------------------+
-
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
-
+----+-------------+-------+------------+------+---------------+-------+---------+-------+------+----------+-----------------------------+
-
| 1 | SIMPLE | t | NULL | ref | idx_a,idx1_t | idx_a | 5 | const | 10 | 70.00 | Using where; Using filesort |
-
+----+-------------+-------+------------+------+---------------+-------+---------+-------+------+----------+-----------------------------+
-
1 row in set, 1 warning (0.00 sec)
-
-
-- 不走索引,也是12行
-
select/*+no_index(t)*/ * from t where a=1 and b>3 order by b limit 2;
-
-
# Time: 2025-03-14T14:54:34.514207+08:00
-
# User@Host: root[root] @ localhost [] Id: 15
-
# Query_time: 0.000935 Lock_time: 0.000008 Rows_sent: 2 Rows_examined: 12 Thread_id: 15 Errno: 0 Killed: 0 Bytes_received: 75 Bytes_sent: 155 Read_first: 1 Read_last: 0 Read_key: 1 Read_next: 0 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 11 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 2 Sort_scan_count: 1 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-03-14T14:54:34.513272+08:00 End: 2025-03-14T14:54:34.514207+08:00
-
SET timestamp=1741935274;
-
select/*+no_index(t)*/ * from t where a=1 and b>3 order by b limit 2;