gpt4 book ai didi

mysql索引和优化,使用where;使用临时的;使用文件排序

转载 作者:可可西里 更新时间:2023-11-01 07:50:01 25 4
gpt4 key购买 nike

哪些表和列应该有索引?我在 flow_permanent_id 和 entry_id 上有一个索引,但它似乎正在使用文件排序?

我可以做些什么来优化它?

mysql> explain SELECT COUNT(*) AS count_all, entry_id AS entry_id FROM `votes` WHERE `votes`.`flow_permanent_id` = '4fab490cdc1c82cfa800000a' GROUP BY entry_id;
+----+-------------+-------+------+----------------------------------+----------------------------------+---------+-------+------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+----------------------------------+----------------------------------+---------+-------+------+----------------------------------------------+
| 1 | SIMPLE | votes | ref | index_votes_on_flow_permanent_id | index_votes_on_flow_permanent_id | 74 | const | 1 | Using where; Using temporary; Using filesort |
+----+-------------+-------+------+----------------------------------+----------------------------------+---------+-------+------+----------------------------------------------+
1 row in set (0.00 sec)

最佳答案

为了避免文件排序,您需要一个关于 (flow_permanent_id, entry_id) 的复合索引,以便 MySQL 可以将索引用于 WHERE 和 GROUP BY .

关于mysql索引和优化,使用where;使用临时的;使用文件排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10609640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com