Postgresql解释分析:隐藏时间

时间:2013-06-24 15:36:50

标签: postgresql query-optimization postgresql-performance

我的查询很长,explain analyze没有帮助。

PostgreSQL版本:9.1

目前的计划:

http://explain.depesz.com/s/sWG

查询:

SELECT temps_mois.rfoperyea      AS c0, 
       dwhinv.dwhinv___rfovsnide AS c1, 
       rfoadv_1.rfoadvsup        AS c2, 
       rfoadv_2.rfoadvsup        AS c3, 
       rsaaev_3.rsaaevsup        AS c4, 
       Sum(( CASE 
               WHEN dwhinv.dwhinv___rfodomide = 'LABO' 
                    AND dwhinv.dwhinv___rfoindide = '17' THEN dwhinv.dwhinvqte 
               ELSE 0 
             END ))              AS m0, 
       Sum(( CASE 
               WHEN dwhinv.dwhinv___rfodomide = 'LABO' 
                    AND dwhinv.dwhinv___rfoindide = '18' THEN dwhinv.dwhinvqte 
               ELSE 0 
             END ))              AS m1, 
       Sum(( CASE 
               WHEN dwhinv.dwhinv___rfodomide = 'LABO' 
                    AND dwhinv.dwhinv___rfoindide = '15' THEN dwhinv.dwhinvqte 
               ELSE 0 
             END ))              AS m2, 
       Sum(( CASE 
               WHEN dwhinv.dwhinv___rfodomide = 'LABO' 
                    AND dwhinv.dwhinv___rfoindide = '16' THEN dwhinv.dwhinvqte 
               ELSE 0 
             END ))              AS m3, 
       Sum(( CASE 
               WHEN dwhinv.dwhinv___rfodomide = 'ANAPATH' 
                    AND dwhinv.dwhinv___rfoindide = '20' THEN dwhinv.dwhinvqte 
               ELSE 0 
             END ))              AS m4, 
       Sum(( CASE 
               WHEN dwhinv.dwhinv___rfodomide = 'ANAPATH' 
                    AND dwhinv.dwhinv___rfoindide = '17' THEN dwhinv.dwhinvqte 
               ELSE 0 
             END ))              AS m5, 
       Sum(( CASE 
               WHEN dwhinv.dwhinv___rfodomide = 'ANAPATH' 
                    AND dwhinv.dwhinv___rfoindide = '18' THEN dwhinv.dwhinvqte 
               ELSE 0 
             END ))              AS m6, 
       Sum(( CASE 
               WHEN dwhinv.dwhinv___rfodomide = 'ANAPATH' 
                    AND dwhinv.dwhinv___rfoindide = '15' THEN dwhinv.dwhinvqte 
               ELSE 0 
             END ))              AS m7, 
       Sum(( CASE 
               WHEN dwhinv.dwhinv___rfodomide = 'ANAPATH' 
                    AND dwhinv.dwhinv___rfoindide = '19' THEN dwhinv.dwhinvqte 
               ELSE 0 
             END ))              AS m8, 
       Sum(( CASE 
               WHEN dwhinv.dwhinv___rfodomide = 'ANAPATH' 
                    AND dwhinv.dwhinv___rfoindide = '16' THEN dwhinv.dwhinvqte 
               ELSE 0 
             END ))              AS m9 
FROM   rfoper_temps_mois AS temps_mois, 
       dwhinv AS dwhinv, 
       rfoadv AS rfoadv_1, 
       rfoadv AS rfoadv_2, 
       rsaaev AS rsaaev_3 
WHERE  ( temps_mois.rfoper___rforefide = 'REF' ) 
       AND ( dwhinv.dwhinv___rforefide = 'REF' 
             AND ( ( dwhinv.dwhinv___rfodomide = 'LABO' 
                     AND dwhinv.dwhinv___rfoindide = '17' ) 
                    OR ( dwhinv.dwhinv___rfodomide = 'LABO' 
                         AND dwhinv.dwhinv___rfoindide = '18' ) 
                    OR ( dwhinv.dwhinv___rfodomide = 'LABO' 
                         AND dwhinv.dwhinv___rfoindide = '15' ) 
                    OR ( dwhinv.dwhinv___rfodomide = 'LABO' 
                         AND dwhinv.dwhinv___rfoindide = '16' ) 
                    OR ( dwhinv.dwhinv___rfodomide = 'ANAPATH' 
                         AND dwhinv.dwhinv___rfoindide = '20' ) 
                    OR ( dwhinv.dwhinv___rfodomide = 'ANAPATH' 
                         AND dwhinv.dwhinv___rfoindide = '17' ) 
                    OR ( dwhinv.dwhinv___rfodomide = 'ANAPATH' 
                         AND dwhinv.dwhinv___rfoindide = '18' ) 
                    OR ( dwhinv.dwhinv___rfodomide = 'ANAPATH' 
                         AND dwhinv.dwhinv___rfoindide = '15' ) 
                    OR ( dwhinv.dwhinv___rfodomide = 'ANAPATH' 
                         AND dwhinv.dwhinv___rfoindide = '19' ) 
                    OR ( dwhinv.dwhinv___rfodomide = 'ANAPATH' 
                         AND dwhinv.dwhinv___rfoindide = '16' ) ) ) 
       AND dwhinv.dwhinvdtd = temps_mois.rfoperdtd 
       AND temps_mois.rfoperyea IN ( '2011', '2012' ) 
       AND dwhinv.dwhinv___rfovsnide = 'version' 
       AND ( rfoadv_1.rfoadv___rfovdeide = 'STRC' 
             AND rfoadv_1.rfoadvrvs = 1 
             AND rfoadv_1.rfoadv___rforefide = 'REF' ) 
       AND dwhinv.dwhinv_d2rfodstide = rfoadv_1.rfoadvinf 
       AND rfoadv_1.rfoadvsup = 'REF' 
       AND ( rfoadv_2.rfoadv___rfovdeide = 'STRC_REF' 
             AND rfoadv_2.rfoadvrvs = 1 
             AND rfoadv_2.rfoadv___rforefide = 'REF' ) 
       AND dwhinv.dwhinv_p2rfodstide = rfoadv_2.rfoadvinf 
       AND rfoadv_2.rfoadvsup IN ( '01', '04', '05', '06', 
                                   '07', '99', 'REF', 'CR2107', 
                                   'CR2108', 'CR2109', 'CR2110', 'CR2111', 
                                   'CR2114', 'CR2116', 'CR2126', 'CR4101', 
                                   'CR4201' ) 
       AND ( rsaaev_3.rsaaev___rsavedide = 'PRESTA_ACTE' 
             AND rsaaev_3.rsaaevrvs = 1 
             AND rsaaev_3.rsaaev___rforefide = 'REF' ) 
       AND dwhinv.dwhinv___rsaedtide = rsaaev_3.rsaaevinf 
       AND rsaaev_3.rsaaevsup IN ( 'PRISE_EN_CHARGE', 'REG_EXT', 
                                   'REG_HOSPI_SEANCE' ) 
GROUP  BY temps_mois.rfoperyea, 
          dwhinv.dwhinv___rfovsnide, 
          rfoadv_1.rfoadvsup, 
          rfoadv_2.rfoadvsup, 
          rsaaev_3.rsaaevsup

似乎HashJoin和Hashaggregate之间经过了几秒钟。 Hashjoin需要1200到1600毫秒。使用HashAggregate,它会跳到5645ms。

任何遇到此问题的人都可以解释其中的差异吗?

1 个答案:

答案 0 :(得分:1)

发布的计划似乎与您的描述不符。例如,在给出的计划中没有5645ms的“实际时间”,也许您的复制和粘贴中缺少顶部节点。

但无论如何,1600到5645之间的时间是从HashAggregate读取它需要读取的最后一行开始的时间,但是还不能生成它的第一行。例如,因为它需要对它读取的数据进行一些批量操作。