所以我必须处理一个没有索引的数据库(不是我的设计,这让我很沮丧)。我正在运行一个大约需要三秒钟才能返回的查询,我需要它更快。
以下是相关的表格和列:
gs_pass_data au_entry ground_station
-gs_pass_data_id -au_id -ground_station_id
-start_time -gs_pass_data_id -ground_station_name
-end_time -comments
-ground_station_id
我的查询是:
SELECT DISTINCT gs_pass_data_id,start_time,end_time,
ground_station_name FROM gs_pass_data
JOIN ground_station
ON gs_pass_data.ground_station_id =
ground_station.ground_station_id
JOIN au_entry ON au_entry.gs_pass_data_id =
gs_pass_data.gs_pass_data_id
WHERE (start_time BETWEEN @prevTime AND @nextTime)
AND comments = 'AU is identified.'
ORDER BY start_time
我尝试使用 EXISTS 而不是 DISTINCT,但没有任何改进。我已经阅读了有关 SQL 优化的所有内容,但我似乎无法将此查询缩短到合理的时间(合理的时间小于 0.5 秒)。任何想法将不胜感激。