查询是通过思考狮身人面像生成的。我正在寻找加快此查询的方法。返回结果实际上需要很长时间。有什么办法可以优化这个。
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 添加了重复的索引键,原来在使用 add_index 方法时 rails ActiveRecord::Migration 中存在错误。我现在已经去掉了重复的索引键,查询响应时间只有4s