我运行了如下的 mysql 查询
在非分区表上
mysql> use test31
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> explain partitions SELECT * FROM my_friends WHERE (requestor = '1234567890' OR contact = '1234567890') AND status = 1 ORDER BY request_id DESC LIMIT 0,100\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: my_friends
partitions: NULL
type: index_merge
possible_keys: friend_index,requestor,contact
key: friend_index,contact
key_len: 17,17
ref: NULL
rows: 2
Extra: Using sort_union(friend_index,contact); Using where; Using filesort
1 row in set (0.00 sec)
在分区表上
mysql> explain partitions SELECT * FROM my_friends WHERE (requestor = '1234567890' OR contact = '1234567890') AND status = 1 ORDER BY request_id DESC LIMIT 0,100\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: my_friends
partitions: p1_p1sp0,p1_p1sp1,p1_p1sp2,p1_p1sp3,p1_p1sp4,p1_p1sp5,p1_p1sp6,p1_p1sp7,p1_p1sp8,p1_p1sp9,p1_p1sp10,p1_p1sp11,p1_p1sp12,p1_p1sp13,p1_p1sp14,p1_p1sp15,p1_p1sp16,p1_p1sp17,p1_p1sp18,p1_p1sp19,p1_p1sp20,p1_p1sp21,p1_p1sp22,p1_p1sp23,p1_p1sp24,p1_p1sp25,p1_p1sp26,p1_p1sp27,p1_p1sp28,p1_p1sp29
type: index_merge
possible_keys: friend_index,requestor,contact
key: friend_index,contact
key_len: 17,17
ref: NULL
rows: 60
Extra: Using sort_union(friend_index,contact); Using where; Using filesort
1 row in set (0.01 sec)
“行”是什么意思?行越少,查询速度越快?
答案1
这MySQL 参考手册说:
从 MySQL 5.1.28 开始,EXPLAIN PARTITIONS 输出的行列始终显示表中的记录总数。以前,这是匹配行的数量。(Bug#35745)