由于某种原因,这个非常简单的WordPress查询使用临时表。我甚至试图强迫它使用索引,但无济于事。
EXPLAIN SELECT DISTINCT(meta_key) FROM wp_postmeta
+------+-------------+-------------+------+---------------+------+---------+------+---------+-----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------------+------+---------------+------+---------+------+---------+-----------------+
| 1 | SIMPLE | wp_postmeta | ALL | NULL | NULL | NULL | NULL | 1756487 | Using temporary |
+------+-------------+-------------+------+---------------+------+---------+------+---------+-----------------+
SHOW INDEX FROM wp_postmeta
+-------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| wp_postmeta | 0 | PRIMARY | 1 | meta_id | A | 1756487 | NULL | NULL | | BTREE | | |
| wp_postmeta | 1 | post_id | 1 | post_id | A | 159680 | NULL | NULL | | BTREE | | |
| wp_postmeta | 1 | meta_key | 1 | meta_key | A | 1578 | 191 | NULL | YES | BTREE | | |
+-------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
答案 0 :(得分:0)
如果您尝试使用GROUP BY
代替SELECT DISTINCT
,该怎么办?
SELECT meta_key
FROM wp_postmeta
GROUP BY meta_key