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
--------------------------------------------
-- 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
--------------------------------------------
-- 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
-- 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
-- 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
-- 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
--------------------------------------------------------
-- 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
--------------------------------------------------------
-- 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
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
--------------------------------------------
Aggregate
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
-------------------------------------------------
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
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
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p3 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p3 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p3 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p3 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
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
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p4 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p4 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p4 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p4 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p4 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
-------------------------------------------------
Aggregate
/*+ 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
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p5 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p5 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
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
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
------------------------------------
Aggregate
/*+ HashJoin(t1 t2) */
EXPLAIN (COSTS false) EXECUTE p7 (10);
-LOG: /*
+LOG: pg_hint_plan:
+used hint:
HashJoin(t1 t2)
-*/
+
QUERY PLAN
-------------------------------------------------
Aggregate
EXPLAIN (COSTS false) EXECUTE p7 (10);
LOG: /*
HashJoin(t1 t2)
-*/
+
QUERY PLAN
-------------------------------------------------
Aggregate
/* 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++)
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);