OSDN Git Service

ヒントのダンプ関数をクリーンアップした。
authorMitsuru Hasegawa <hasegawa@metrosystems.co.jp>
Thu, 5 Jul 2012 02:11:49 +0000 (11:11 +0900)
committerMitsuru Hasegawa <hasegawa@metrosystems.co.jp>
Thu, 5 Jul 2012 02:11:49 +0000 (11:11 +0900)
expected/prepare-9.1.out
expected/prepare-9.2.out
pg_hint_plan.c

index 1d05e67..89ec2d8 100644 (file)
@@ -1,7 +1,7 @@
 LOAD 'pg_hint_plan';
 SET pg_hint_plan.enable TO on;
-SET pg_hint_plan.debug_print TO true;
-SET client_min_messages TO 'LOG';
+SET pg_hint_plan.debug_print TO on;
+SET client_min_messages TO LOG;
 EXPLAIN (COSTS false) SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id;
                  QUERY PLAN                 
 --------------------------------------------
@@ -27,9 +27,10 @@ EXPLAIN (COSTS false) SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id AND t1.id
 -- 9.2:PREPAREでヒント句を指定しても、実行計画は制御できない
 /*+ NestLoop(t1 t2) */
 PREPARE p1 AS SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id;
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 NestLoop(t1 t2)
-*/
+
 EXPLAIN (COSTS false) EXECUTE p1;
                  QUERY PLAN                 
 --------------------------------------------
@@ -44,9 +45,10 @@ EXPLAIN (COSTS false) EXECUTE p1;
 -- 9.2:パラメータがない場合は、1回目のEXPLAINで実行計画が決定する
 /*+ NestLoop(t1 t2) */
 PREPARE p2 AS SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id;
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 NestLoop(t1 t2)
-*/
+
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p2;
                  QUERY PLAN                 
@@ -82,9 +84,10 @@ EXPLAIN (COSTS false) EXECUTE p2;
 -- 9.2:5回目のEXPLAINまでヒント句を指定しても、6回目以降は本来の実行計画に戻る
 /*+ NestLoop(t1 t2) */
 PREPARE p3 AS SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id AND t1.id > $1;
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 NestLoop(t1 t2)
-*/
+
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p3 (10);
                        QUERY PLAN                       
@@ -174,9 +177,10 @@ EXPLAIN (COSTS false) EXECUTE p3 (10);
 -- 9.2:6回目のEXPLAINまでヒント句を指定すると、7回目以降も実行計画が固定される
 /*+ NestLoop(t1 t2) */
 PREPARE p4 AS SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id AND t1.id > $1;
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 NestLoop(t1 t2)
-*/
+
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p4 (10);
                        QUERY PLAN                       
@@ -267,9 +271,10 @@ EXPLAIN (COSTS false) EXECUTE p4 (10);
 -- 9.2:6回目のEXPLAINでヒント句を指定すると、7回目以降も実行計画を制御できる
 /*+ NestLoop(t1 t2) */
 PREPARE p5 AS SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id AND t1.id > $1;
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 NestLoop(t1 t2)
-*/
+
 EXPLAIN (COSTS false) EXECUTE p5 (10);
                        QUERY PLAN                       
 --------------------------------------------------------
@@ -357,9 +362,10 @@ EXPLAIN (COSTS false) EXECUTE p5 (10);
 -- 9.2:7回目以降のEXPLAINでヒント句を指定しても、以降も実行計画は制御できない
 /*+ NestLoop(t1 t2) */
 PREPARE p6 AS SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id AND t1.id > $1;
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 NestLoop(t1 t2)
-*/
+
 EXPLAIN (COSTS false) EXECUTE p6 (10);
                        QUERY PLAN                       
 --------------------------------------------------------
@@ -446,9 +452,10 @@ EXPLAIN (COSTS false) EXECUTE p6 (10);
 -- 9.2:実行計画が固定されたあと、ANALYZEをすると1回目のEXECUTEで実行計画が固定される
 /*+ NestLoop(t1 t2) */
 PREPARE p7 AS SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id AND t1.id > $1;
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 NestLoop(t1 t2)
-*/
+
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p7 (10);
                        QUERY PLAN                       
@@ -586,9 +593,10 @@ EXPLAIN (COSTS false) SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id AND t1.id
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
                  QUERY PLAN                 
 --------------------------------------------
  Aggregate
index 471f4bd..c8eff74 100644 (file)
@@ -1,7 +1,7 @@
 LOAD 'pg_hint_plan';
 SET pg_hint_plan.enable TO on;
-SET pg_hint_plan.debug_print TO true;
-SET client_min_messages TO 'LOG';
+SET pg_hint_plan.debug_print TO on;
+SET client_min_messages TO LOG;
 EXPLAIN (COSTS false) SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id;
                    QUERY PLAN                    
 -------------------------------------------------
@@ -43,9 +43,10 @@ EXPLAIN (COSTS false) EXECUTE p1;
 PREPARE p2 AS SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id;
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p2;
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -84,9 +85,10 @@ EXPLAIN (COSTS false) EXECUTE p2;
 PREPARE p3 AS SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id AND t1.id > $1;
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p3 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -100,9 +102,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p3 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -116,9 +119,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p3 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -132,9 +136,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p3 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -148,9 +153,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p3 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -201,9 +207,10 @@ EXPLAIN (COSTS false) EXECUTE p3 (10);
 PREPARE p4 AS SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id AND t1.id > $1;
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p4 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -217,9 +224,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p4 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -233,9 +241,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p4 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -249,9 +258,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p4 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -265,9 +275,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p4 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -281,9 +292,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p4 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
                    QUERY PLAN                    
 -------------------------------------------------
  Aggregate
@@ -380,12 +392,14 @@ EXPLAIN (COSTS false) EXECUTE p5 (10);
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p5 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
-LOG:  /*
+
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -399,9 +413,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p5 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -415,9 +430,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p5 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -529,9 +545,10 @@ EXPLAIN (COSTS false) EXECUTE p6 (10);
 PREPARE p7 AS SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id AND t1.id > $1;
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -545,9 +562,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -561,9 +579,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -577,9 +596,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -593,9 +613,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
              QUERY PLAN             
 ------------------------------------
  Aggregate
@@ -609,9 +630,10 @@ HashJoin(t1 t2)
 
 /*+ HashJoin(t1 t2) */
 EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG:  /*
+LOG:  pg_hint_plan:
+used hint:
 HashJoin(t1 t2)
-*/
+
                    QUERY PLAN                    
 -------------------------------------------------
  Aggregate
@@ -700,7 +722,7 @@ EXPLAIN (COSTS false) SELECT count(*) FROM t1, t2 WHERE t1.id = t2.id AND t1.id
 EXPLAIN (COSTS false) EXECUTE p7 (10);
 LOG:  /*
 HashJoin(t1 t2)
-*/
+
                    QUERY PLAN                    
 -------------------------------------------------
  Aggregate
index ea724e1..c9db46e 100644 (file)
@@ -530,30 +530,22 @@ PlanHintIsEmpty(PlanHint *hint)
 
 /* TODO オブジェクト名のクォート処理を追加 */
 static void
-PlanHintDump(PlanHint *hint)
+all_hint_dump(PlanHint *hint, StringInfo buf, const char *title, HintStatus state)
 {
-       StringInfoData  buf;
-       ListCell           *l;
        int                             i;
+       ListCell           *l;
        bool                    is_first = true;
 
-       if (!hint)
-       {
-               elog(LOG, "pg_hint_plan:\nno hint");
-               return;
-       }
-
-       initStringInfo(&buf);
-       appendStringInfo(&buf, "pg_hint_plan:\nused hint:\n");
+       appendStringInfo(buf, "%s:\n", title);
        for (i = 0; i < hint->nscan_hints; i++)
        {
                ScanMethodHint *h = hint->scan_hints[i];
                ListCell           *n;
 
-               appendStringInfo(&buf, "%s(%s", h->base.keyword, h->relname);
+               appendStringInfo(buf, "%s(%s", h->base.keyword, h->relname);
                foreach(n, h->indexnames)
-                       appendStringInfo(&buf, " %s", (char *) lfirst(n));
-               appendStringInfoString(&buf, ")\n");
+                       appendStringInfo(buf, " %s", (char *) lfirst(n));
+               appendStringInfoString(buf, ")\n");
        }
 
        for (i = 0; i < hint->njoin_hints; i++)
@@ -564,30 +556,47 @@ PlanHintDump(PlanHint *hint)
                if (h->enforce_mask == ENABLE_ALL_JOIN)
                        continue;
 
-               appendStringInfo(&buf, "%s(%s", h->base.keyword, h->relnames[0]);
+               appendStringInfo(buf, "%s(%s", h->base.keyword, h->relnames[0]);
                for (i = 1; i < h->nrels; i++)
-                       appendStringInfo(&buf, " %s", h->relnames[i]);
-               appendStringInfoString(&buf, ")\n");
+                       appendStringInfo(buf, " %s", h->relnames[i]);
+               appendStringInfoString(buf, ")\n");
        }
 
        foreach(l, hint->set_hints)
        {
                SetHint    *h = (SetHint *) lfirst(l);
-               appendStringInfo(&buf, "%s(%s %s)\n", HINT_SET, h->name, h->value);
+               appendStringInfo(buf, "%s(%s %s)\n", HINT_SET, h->name, h->value);
        }
 
        foreach(l, hint->leading)
        {
                if (is_first)
                {
-                       appendStringInfo(&buf, "%s(%s", HINT_LEADING, (char *)lfirst(l));
+                       appendStringInfo(buf, "%s(%s", HINT_LEADING, (char *)lfirst(l));
                        is_first = false;
                }
                else
-                       appendStringInfo(&buf, " %s", (char *)lfirst(l));
+                       appendStringInfo(buf, " %s", (char *)lfirst(l));
        }
        if (!is_first)
-               appendStringInfoString(&buf, ")\n");
+               appendStringInfoString(buf, ")\n");
+
+}
+
+static void
+PlanHintDump(PlanHint *hint)
+{
+       StringInfoData  buf;
+
+       if (!hint)
+       {
+               elog(LOG, "pg_hint_plan:\nno hint");
+               return;
+       }
+
+       initStringInfo(&buf);
+       appendStringInfoString(&buf, "pg_hint_plan:\n");
+       all_hint_dump(hint, &buf, "used hint", HINT_STATE_USED);
 
        elog(LOG, "%s", buf.data);