我们的环境:Drupal+MySQL
检查查询日志表明,源自 Drupal 核心的 node_load 函数的以下查询需要相当长的时间。
node_load 查询上的 EXPLAIN 表明该索引未在 USER 表上使用。
mysql> explain SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed,
n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title,
r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data
FROM xyz_node n
INNER JOIN xyz_users u ON n.uid = u.uid
INNER JOIN xyz_node_revisions r ON r.vid = n.vid;
+----+-------------+-------+--------+---------------+---------+---------+--------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+---------------+---------+---------+--------------+------+-------------+
| 1 | SIMPLE | u | ALL | PRIMARY | NULL | NULL | NULL | 181 | |
| 1 | SIMPLE | n | ref | vid,uid | uid | 4 | xyz.u.uid | 9 | Using where |
| 1 | SIMPLE | r | eq_ref | PRIMARY | PRIMARY | 4 | xyz.n.vid | 1 | |
+----+-------------+-------+--------+---------------+---------+---------+--------------+------+-------------+
知道会发生什么,以及如何强制 MYSQL 在此查询上使用索引?