1

我有一个很长的查询,并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 它会跳转到 5645 毫秒。

遇到此问题的其他任何人都可以解释其中的区别吗?

4

1 回答 1

1

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

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

于 2013-06-24T23:23:13.573 回答