0

クエリを高速化するために、インデックスを追加したり、既存のインデックスを変更したりできる場所を見つけようとしています。

主な問題は、ビジネス オブジェクトによって生成されたクエリ自体を変更できないことです。

奇妙なことに、WHERE 句を別のテーブルを使用するように変更すると、クエリが非常に高速になります。

クエリは次のとおりです。

SELECT Year(listingperformanceindicator.date), 
       Month(listingperformanceindicator.date), 
       categoryflattened.parentname, 
       categoryflattened.groupname, 
       categoryflattened.categoryname, 
       Count(listingperformanceindicator.listingid), 
       ( Count(listingperformanceindicator.listingid) ) / 30, 
       Sum(listingperformanceindicator.listingviews), 
       CASE 
         WHEN ( ( Count(listingperformanceindicator.listingid) ) / 30 ) = 0 THEN 
         0 
         ELSE ( Sum(listingperformanceindicator.listingviews) ) / 
              ( ( Count(listingperformanceindicator.listingid) ) / 30 ) 
       END 
FROM   listingperformanceindicator 
       RIGHT OUTER JOIN categorytolisting 
                     ON ( categorytolisting.siteid = listingperformanceindicator.siteid 
                          AND categorytolisting.listingid = listingperformanceindicator.listingid ) 
       RIGHT OUTER JOIN categoryflattened 
                     ON ( categoryflattened.siteid = categorytolisting.siteid 
                          AND ( categoryflattened.parentid = categorytolisting.categoryid 
                                 OR categoryflattened.categoryid = categorytolisting.categoryid 
                                 OR categoryflattened.groupid = categorytolisting.categoryid ) ) 
       RIGHT OUTER JOIN site ON (site.id=categoryflattened.siteId)
WHERE  --listingperformanceindicator.siteid = 'DED29E78-17B0-423B-A1D1-67E2F3CA864D' --THIS IS REALLY FAST :/
       site.id = 'DED29E78-17B0-423B-A1D1-67E2F3CA864D' --THIS IS REALLY SLOW! :(
       AND categoryflattened.languagecode ='SE'
GROUP  BY Year(listingperformanceindicator.date), 
          Month(listingperformanceindicator.date), 
          categoryflattened.parentname, 
          categoryflattened.groupname, 
          categoryflattened.categoryname 

実行計画を見てみましたが、意味がありません:(

どうぞ:

高速: http://imageshack.us/a/img211/5755/fastquery.png

遅い: http://imageshack.us/a/img823/7227/slowquery.png

どんな提案でも大歓迎です!

ありがとう!

4

0 に答える 0