2017-11-26 2 views
0

私は次のクエリ(PostgreSQLの)持っている:同じテーブルの2つのGINインデックスでパフォーマンスが低下する可能性がありますか?

select prt.a, 
(SELECT count(ind.b) FROM ind WHERE ind.indexed_field_1 @@ to_tsquery(prt.a) 
AND lower(ind.t) not in ('a', 'b', 'c')) cnt 
from p as prt 
order by cnt desc 
limit 200; 

ind.indexed_field_1はGINインデックスにインデックスされます。これまではとても良い - 約1秒間実行されていた(indは〜600K行)。

私はindテーブルにindexed_field_2を追加し、GINインデックスとインデックスにそれをしたら - 元のクエリが突然〜5秒間実行し、同じことがindexed_field_2に類似したクエリのために行く:任意の手掛かりを

select prt.a, 
(SELECT count(ind.b) FROM ind WHERE ind.indexed_field_2 @@ to_tsquery(prt.a) 
AND lower(ind.t) not in ('a', 'b', 'c')) cnt 
from p as prt 
order by cnt desc 
limit 200; 

何が原因でしょうか?

実行計画は同じように見えます。

EDIT:第2クエリに対する

実行計画:

[ 
    { 
    "Execution Time": 4863.615, 
    "Planning Time": 0.3, 
    "Plan": { 
     "Startup Cost": 383480149.03, 
     "Shared Hit Blocks": 1296773, 
     "Shared Written Blocks": 0, 
     "Shared Read Blocks": 267565, 
     "Plans": [ 
     { 
      "Temp Written Blocks": 0, 
      "Sort Key": [ 
      "((SubPlan 1)) DESC" 
      ], 
      "Node Type": "Sort", 
      "Sort Space Used": 46, 
      "Shared Hit Blocks": 1296773, 
      "Plans": [ 
      { 
       "Node Type": "Seq Scan", 
       "Shared Hit Blocks": 1296773, 
       "Plans": [ 
       { 
        "Partial Mode": "Simple", 
        "Node Type": "Aggregate", 
        "Strategy": "Plain", 
        "Shared Hit Blocks": 1296773, 
        "Subplan Name": "SubPlan 1", 
        "Plans": [ 
        { 
         "Exact Heap Blocks": 1383693, 
         "Node Type": "Bitmap Heap Scan", 
         "Shared Hit Blocks": 1296773, 
         "Plans": [ 
         { 
          "Startup Cost": 0, 
          "Plan Width": 0, 
          "Temp Written Blocks": 0, 
          "Shared Written Blocks": 0, 
          "Shared Read Blocks": 5872, 
          "Local Written Blocks": 0, 
          "Node Type": "Bitmap Index Scan", 
          "Index Cond": "(indexed_field_2 @@ to_tsquery(prt.a)", 
          "Plan Rows": 3156, 
          "Temp Read Blocks": 0, 
          "Shared Dirtied Blocks": 0, 
          "Local Hit Blocks": 0, 
          "Parallel Aware": false, 
          "Actual Rows": 51, 
          "Local Dirtied Blocks": 0, 
          "Parent Relationship": "Outer", 
          "Total Cost": 43.68, 
          "Shared Hit Blocks": 173739, 
          "Actual Loops": 44742, 
          "Local Read Blocks": 0, 
          "Index Name": "part_ids2_idx" 
         } 
         ], 
         "Shared Read Blocks": 266531, 
         "Relation Name": "ind", 
         "Local Hit Blocks": 0, 
         "Local Dirtied Blocks": 0, 
         "Temp Written Blocks": 0, 
         "Plan Width": 16, 
         "Actual Loops": 44742, 
         "Rows Removed by Index Recheck": 0, 
         "Lossy Heap Blocks": 0, 
         "Filter": "(lower(ind.t) <> ALL ('{a,b,c}'::text[]))", 
         "Alias": "ind", 
         "Recheck Cond": "(indexed_field_2 @@ to_tsquery(prt.a)", 
         "Temp Read Blocks": 0, 
         "Local Read Blocks": 0, 
         "Startup Cost": 44.46, 
         "Shared Dirtied Blocks": 0, 
         "Shared Written Blocks": 0, 
         "Local Written Blocks": 0, 
         "Plan Rows": 3109, 
         "Parallel Aware": false, 
         "Actual Rows": 51, 
         "Parent Relationship": "Outer", 
         "Total Cost": 8563.06, 
         "Rows Removed by Filter": 0 
        } 
        ], 
        "Shared Read Blocks": 266531, 
        "Temp Written Blocks": 0, 
        "Local Dirtied Blocks": 0, 
        "Local Hit Blocks": 0, 
        "Plan Width": 8, 
        "Actual Loops": 44742, 
        "Temp Read Blocks": 0, 
        "Local Read Blocks": 0, 
        "Startup Cost": 8570.83, 
        "Shared Dirtied Blocks": 0, 
        "Shared Written Blocks": 0, 
        "Local Written Blocks": 0, 
        "Plan Rows": 1, 
        "Parallel Aware": false, 
        "Actual Rows": 1, 
        "Parent Relationship": "SubPlan", 
        "Total Cost": 8570.84 
       } 
       ], 
       "Shared Read Blocks": 267565, 
       "Relation Name": "parties", 
       "Temp Written Blocks": 0, 
       "Local Dirtied Blocks": 0, 
       "Local Hit Blocks": 0, 
       "Plan Width": 24, 
       "Actual Loops": 1, 
       "Alias": "parties", 
       "Temp Read Blocks": 0, 
       "Local Read Blocks": 0, 
       "Startup Cost": 0, 
       "Shared Dirtied Blocks": 0, 
       "Shared Written Blocks": 0, 
       "Local Written Blocks": 0, 
       "Plan Rows": 44742, 
       "Parallel Aware": false, 
       "Actual Rows": 44742, 
       "Parent Relationship": "Outer", 
       "Total Cost": 383478215.31 
      } 
      ], 
      "Shared Read Blocks": 267565, 
      "Local Hit Blocks": 0, 
      "Local Dirtied Blocks": 0, 
      "Sort Method": "top-N heapsort", 
      "Plan Width": 24, 
      "Actual Loops": 1, 
      "Temp Read Blocks": 0, 
      "Local Read Blocks": 0, 
      "Shared Written Blocks": 0, 
      "Startup Cost": 383480149.03, 
      "Shared Dirtied Blocks": 0, 
      "Sort Space Type": "Memory", 
      "Local Written Blocks": 0, 
      "Plan Rows": 44742, 
      "Parallel Aware": false, 
      "Actual Rows": 200, 
      "Parent Relationship": "Outer", 
      "Total Cost": 383480260.89 
     } 
     ], 
     "Local Written Blocks": 0, 
     "Node Type": "Limit", 
     "Plan Rows": 200, 
     "Temp Read Blocks": 0, 
     "Shared Dirtied Blocks": 0, 
     "Local Hit Blocks": 0, 
     "Parallel Aware": false, 
     "Actual Rows": 200, 
     "Local Dirtied Blocks": 0, 
     "Temp Written Blocks": 0, 
     "Plan Width": 24, 
     "Actual Loops": 1, 
     "Local Read Blocks": 0, 
     "Total Cost": 383480149.53 
    }, 
    "Triggers": [] 
    } 
] 

答えて

0

新しいインデックスは、オプティマイザの見積もりと選択した実行計画を変更することができ、そして新しい計画は、(偶然)より悪いかもしれません古いものよりも。

これは、両方のクエリに対してEXPLAIN (ANALYZE, BUFFERS)の出力がないと言うことができます。

+0

ありがとうございます、私は質問を編集し、計画+実行時間を追加します。 –

関連する問題