gpt4 book ai didi

mysql - 加速包含 100K+ 记录的 MYSQL 左连接查询

转载 作者:行者123 更新时间:2023-11-29 08:23:46 25 4
gpt4 key购买 nike

查询是通过思考sphinx生成的。我正在寻找加快此查询速度的方法。实际上需要很长时间才能返回结果。我们有什么办法可以优化这个吗?

SELECT 
SQL_NO_CACHE `meetings`.`id` * CAST(8 AS SIGNED) + 3 AS `id`,
GROUP_CONCAT(DISTINCT IFNULL(CONCAT_WS(' ', `members`.`first_name`, `members`.`last_name`), '0') SEPARATOR ' ') AS `mentor_name`,
`meetings`.`id` AS `sphinx_internal_id`,
0 AS `sphinx_deleted`,
984144037 AS `class_crc`,
`meetings`.`program_id` AS `program_id`,
UNIX_TIMESTAMP(`meetings`.`start_time`) AS `start_time`,
`meetings`.`active` AS `active`,
`meetings`.`calendar_time_available` AS `calendar_time_available`,
`meetings`.`group_id` AS `group_id`
FROM `meetings`
LEFT OUTER JOIN `member_meetings`
ON `member_meetings`.`meeting_id` = `meetings`.`id`
LEFT OUTER JOIN `members`
ON `members`.`id` = `member_meetings`.`member_id`
WHERE
`meetings`.`delta` = 0
GROUP BY
`meetings`.`id`
ORDER BY NULL

计数

select count(*) from meetings : 194685
select count(*) from member_meetings : 522309
select count(*) from members : 112016

编辑

我已经解决了这个问题,我已经正确配置了所有适当的索引

为member_meetings.meeting_id和member_meetings.member_id添加了重复的索引键,结果发现rails ActiveRecord::Migration在使用add_index方法时存在错误。我现在已经删除了重复的索引键,查询响应时间只有4s

最佳答案

确保您有索引

`member_meetings`.`meeting_id`
`meetings`.`id`
`members`.`id`
`member_meetings`.`member_id`
`meetings`.`delta`

关于mysql - 加速包含 100K+ 记录的 MYSQL 左连接查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18524930/

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