es.costs = defGetBoolean(opt);
else if (strcmp(opt->defname, "buffers") == 0)
es.buffers = defGetBoolean(opt);
+ else if (strcmp(opt->defname, "plan") == 0)
+ es.plan = defGetBoolean(opt);
+ else if (strcmp(opt->defname, "rewrite") == 0)
+ es.rewrite = defGetBoolean(opt);
else if (strcmp(opt->defname, "format") == 0)
{
char *p = defGetString(opt);
opt->defname)));
}
+
if (es.buffers && !es.analyze)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("EXPLAIN option BUFFERS requires ANALYZE")));
+ if ((!es.plan || !es.rewrite) && es.analyze)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("EXPLAIN option !PLAN contradicts ANALYZE")));
+ /*
+ * XXX: we could check for !plan && rewrite but that would mean !rewrite
+ * would have to explicitly specified when disabling planning...
+ */
+
+ /* emit opening boilerplate */
+ ExplainBeginOutput(&es);
+
+ Assert(IsA(stmt->query, Query));
/*
* Parse analysis was done already, but we still have to run the rule
* rewriter. We do not do AcquireRewriteLocks: we assume the query either
* executed repeatedly. (See also the same hack in DECLARE CURSOR and
* PREPARE.) XXX FIXME someday.
*/
- Assert(IsA(stmt->query, Query));
- rewritten = QueryRewrite((Query *) copyObject(stmt->query));
+ if(!es.rewrite){
+ if (es.format == EXPLAIN_FORMAT_TEXT)
+ appendStringInfoString(es.str, "not rewriting query because auf !rewrite\n");
+ goto out;
+ }
- /* emit opening boilerplate */
- ExplainBeginOutput(&es);
+ rewritten = QueryRewrite((Query *) copyObject(stmt->query));
if (rewritten == NIL)
{
*/
if (es.format == EXPLAIN_FORMAT_TEXT)
appendStringInfoString(es.str, "Query rewrites to nothing\n");
+ goto out;
}
- else
- {
- ListCell *l;
- /* Explain every plan */
- foreach(l, rewritten)
- {
- ExplainOneQuery((Query *) lfirst(l), &es, queryString, params);
+ if(!es.plan){
+ if (es.format == EXPLAIN_FORMAT_TEXT)
+ appendStringInfoString(es.str, "not planning or rewriting query because !plan\n");
+ goto out;
+ }
- /* Separate plans with an appropriate separator */
- if (lnext(l) != NULL)
- ExplainSeparatePlans(&es);
- }
+ /* Explain every plan */
+ foreach(lc, rewritten)
+ {
+ ExplainOneQuery((Query *) lfirst(lc), &es, queryString, params);
+
+ /* Separate plans with an appropriate separator */
+ if (lnext(lc) != NULL)
+ ExplainSeparatePlans(&es);
}
+out:
/* emit closing boilerplate */
ExplainEndOutput(&es);
Assert(es.indent == 0);
/* Set default options. */
memset(es, 0, sizeof(ExplainState));
es->costs = true;
+ es->plan = true;
+ es->rewrite = true;
/* Prepare output buffer. */
es->str = makeStringInfo();
}