1

次のクエリは、 where句に最大50000のIDが含まれている場合、実行に1時間以上かかります...同じクエリは、数千のIDで非常に高速に実行されます...

Select '300_new_files_2012-02-29.xml' as Filelist,
Sum(coalesce(temp_decmetadata.glare_none, 0)) as glare_none,
Sum(coalesce(temp_decmetadata.glare_sun, 0)) as glare_sun,
Sum(coalesce(temp_decmetadata.precipitation_clear, 0)) as precipitation_clear,
Sum(coalesce(temp_decmetadata.precipitation_heavyFog, 0)) as precipitation_heavyFog,
Sum(coalesce(temp_decmetadata.precipitation_mediumRain, 0)) as precipitation_mediumRain,
Sum(coalesce(temp_decmetadata.spray_clear, 0)) as spray_clear,
Sum(coalesce(temp_decmetadata.spray_heavySpray, 0)) as spray_heavySpray,
Sum(coalesce(temp_kafasccmobjectdata.laneAssignment_farRight, 0)) as laneAssignment_farRight,
Sum(coalesce(temp_kafasccmobjectdata.laneAssignment_leftAdjacent, 0)) as laneAssignment_leftAdjacent,
Sum(coalesce(temp_kafasccmobjectdata.type_motorbike, 0)) as type_motorbike,
Sum(coalesce(temp_kafasccmobjectdata.type_truck, 0)) as type_truck,
Sum(coalesce(temp_kafasccmobjectdata.type_van, 0)) as type_van,
Sum(coalesce(temp_visionmetadata.countryCode_SK, 0)) as countryCode_SK,
Sum(coalesce(temp_visionmetadata.countryCode_SM, 0)) as countryCode_SM,
Sum(coalesce(temp_visionmetadata.countryCode_TR, 0)) as countryCode_TR,
Sum(coalesce(temp_visionmetadata.countryCode_UA, 0)) as countryCode_UA,
Sum(coalesce(temp_visionmetadata.countryCode_US, 0)) as countryCode_US,
Sum(coalesce(temp_visionmetadata.countryCode_ZA, 0)) as countryCode_ZA,
Sum(coalesce(temp_visionmetadata.local_illumination_cast_shadows, 0)) as local_illumination_cast_shadows,
Sum(coalesce(temp_visionmetadata.local_illumination_oncoming, 0)) as local_illumination_oncoming,
Sum(coalesce(temp_visionmetadata.roadCharacteristics_flat, 0)) as roadCharacteristics_flat,
Sum(coalesce(temp_visionmetadata.roadCharacteristics_hilly, 0)) as roadCharacteristics_hilly,
Sum(coalesce(temp_visionmetadata.roadLocation_city, 0)) as roadLocation_city,
Sum(coalesce(temp_visionmetadata.roadLocation_cityResidential, 0)) as roadLocation_cityResidential,
Sum(coalesce(temp_visionmetadata.sky_overcast, 0)) as sky_overcast,
Sum(coalesce(temp_visionmetadata.sky_partlyCloudy, 0)) as sky_partlyCloudy,
Sum(coalesce(temp_visionmetadata.timeOfDay_day, 0)) as timeOfDay_day,
Sum(coalesce(temp_visionmetadata.timeOfDay_Sunny_daytime, 0)) as timeOfDay_Sunny_daytime
from files
left join 
(
 Select id,
 count(case when glare like '%none%' then 1 end) as glare_none,
 count(case when glare like '%sun%' then 1 end) as glare_sun,
 count(case when precipitation like '%clear%' then 1 end) as precipitation_clear,
 count(case when precipitation like '%heavyFog%' then 1 end) as precipitation_heavyFog,
 count(case when spray like '%clear%' then 1 end) as spray_clear,
 count(case when spray like '%heavySpray%' then 1 end) as spray_heavySpray,
 from decmetadata
 where id in (1264853,1264854,1264855,1264856,1264857,.....)
 group by id 
) temp_decmetadata on temp_decmetadata.id = files.id 
left join 
(
 Select id,
 count(case when laneAssignment like '%farRight%' then 1 end) as laneAssignment_farRight,
 count(case when laneAssignment like '%leftAdjacent%' then 1 end) as laneAssignment_leftAdjacent,
 count(case when type like '%car%' then 1 end) as type_car,
 count(case when type like '%motorbike%' then 1 end) as type_motorbike,
 count(case when type like '%truck%' then 1 end) as type_truck,
 count(case when type like '%van%' then 1 end) as type_van
 from kafasccmobjectdata
 where id in (1264853,1264854,1264855,1264856,1264857,.....)
 group by id 
) temp_kafasccmobjectdata on temp_kafasccmobjectdata.id = files.id 
left join 
(
 Select id,
 count(case when countryCode like '%SK%' then 1 end) as countryCode_SK,
 count(case when countryCode like '%SM%' then 1 end) as countryCode_SM,
 count(case when countryCode like '%TR%' then 1 end) as countryCode_TR,
 count(case when countryCode like '%UA%' then 1 end) as countryCode_UA,
 count(case when countryCode like '%US%' then 1 end) as countryCode_US,
 count(case when countryCode like '%ZA%' then 1 end) as countryCode_ZA,
 count(case when sky like '%lowSun%' then 1 end) as local_illumination_cast_shadows,
 count(case when comments like '%oncomingevent%' then 1 end) as local_illumination_oncoming,
 count(case when roadCharacteristics like '%flat%' then 1 end) as roadCharacteristics_flat,
 count(case when roadCharacteristics like '%hilly%' then 1 end) as roadCharacteristics_hilly,
 count(case when roadLocation like '%city%' then 1 end) as roadLocation_city,
 count(case when roadLocation like '%cityResidential%' then 1 end) as roadLocation_cityResidential,
 count(case when roadLocation like '%countryRural%' then 1 end) as roadLocation_countryRural,
 count(case when sky like '%overcast%' then 1 end) as sky_overcast,
 count(case when sky like '%partlyCloudy%' then 1 end) as sky_partlyCloudy,
 count(case when timeOfDay like '%day%' then 1 end) as timeOfDay_day,
 count(case when sky like '%clear%' and timeofday ='day' then 1 end) as timeOfDay_Sunny_daytime
 from visionmetadata
 where id in (1264853,1264854,1264855,1264856,1264857,....)
 group by id 
) temp_visionmetadata on temp_visionmetadata.id = files.id 
where files.id in (1264853,1264854,1264855,1264856,1264857,....)

「ExplainSelect...」の結果が添付されています。 ここに画像の説明を入力してください

任意のアイデア/提案/修正???

どんな助けでも大歓迎です!!!

4

1 に答える 1

2

うん...

まず、クエリに 50,000 個の数字を 3 回以上書き込む代わりに、必要なすべての ID を保持する構造を作成するのはどうですか?

2 番目: コード チェックで先頭の % を削除してみてください。(そしてそれらの列に適切なインデックスを作成します)

3番目:私はこれを提案することはほとんどありませんが、合計を事前に計算して非正規化して保存することをお勧めします。

于 2012-05-28T12:52:47.627 に答える