0
我有一个查询如何优化具有左硬连接的查询?
SELECT
"athlete"."id" AS "athlete_id"
FROM "athlete"
LEFT JOIN "athlete_in_game" ON athlete.id = athlete_in_game.id_athlete
LEFT JOIN "athlete_in_team" ON athlete.id = athlete_in_team.id_athlete
LEFT JOIN "game" ON
athlete_in_team.id_team = game.id_team_home OR
athlete_in_team.id_team = game.id_team_away OR
athlete_in_game.id_game = game.id
LEFT JOIN "sport_competition" ON sport_competition.id_game = game.id
GROUP BY "athlete"."id"
我需要选择其在比赛中发挥所有的运动员。但可能是因为几场比赛没有数据在表格“运动员在线游戏”中,并且在这种情况下,我会从表“athlete_in_team”中的所有运动员参加这些游戏。正因为如此,我在第三个左连接中使用双“OR”。我需要所有书面条件,但由于双“或”,它可能会工作太久。无论如何,是否有机会优化它?
http://wiki.postgresql.org/wiki/SlowQueryQuestions –