运行以下查询需要很长时间。所有表都包含超过 200,000 条记录。连接语句中的所有列上都存在索引:
Select files.filename,
coalesce(temp_decmetadata.glare_roadGlare, 0) as glare_roadGlare,
coalesce(temp_decmetadata.glare_sun, 0) as glare_sun,
coalesce(temp_decmetadata.spray_heavySpray, 0) as spray_heavySpray,
coalesce(temp_kafaspdobjectdata.contrast_wellVisible, 0) as contrast_wellVisible,
coalesce(temp_kafaspdobjectdata.roadSafety_zebraCrossing, 0) as roadSafety_zebraCrossing,
coalesce(temp_visionmetadata.roadUser_bicycle, 0) as roadUser_bicycle,
coalesce(temp_visionmetadata.roadUser_car, 0) as roadUser_car,
coalesce(temp_visionmetadata.roadUser_pedestrian, 0) as roadUser_pedestrian
from files
left join
(
Select id,
count(case when glare like '%roadGlare%' then 1 end) as glare_roadGlare,
count(case when glare like '%sun%' then 1 end) as glare_sun,
count(case when spray like '%heavySpray%' then 1 end) as spray_heavySpray
from decmetadata
group by id
) temp_decmetadata on temp_decmetadata.id = files.id
left join
(
Select id,
count(case when contrast like '%wellVisible%' then 1 end) as contrast_wellVisible,
count(case when roadSafety like '%zebraCrossing%' then 1 end) as roadSafety_zebraCrossing
from kafaspdobjectdata
group by id
) temp_kafaspdobjectdata on temp_kafaspdobjectdata.id = files.id
left join
(
Select id,
count(case when roadUser like '%bicycle%' then 1 end) as roadUser_bicycle,
count(case when roadUser like '%car%' then 1 end) as roadUser_car,
count(case when roadUser like '%pedestrian%' then 1 end) as roadUser_pedestrian
from visionmetadata
group by id
) temp_visionmetadata on temp_visionmetadata.id = files.id
“解释选择...”的结果附在下面: