1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

Some infrastructure changes for the upcoming auto-explain contrib module:

* Refactor explain.c slightly to export a convenient-to-use subroutine
for printing EXPLAIN results.

* Provide hooks for plugins to get control at ExecutorStart and ExecutorEnd
as well as ExecutorRun.

* Add some minimal support for tracking the total runtime of ExecutorRun.
This code won't actually do anything unless a plugin prods it to.

* Change the API of the DefineCustomXXXVariable functions to allow nonzero
"flags" to be specified for a custom GUC variable.  While at it, also make
the "bootstrap" default value for custom GUCs be explicitly specified as a
parameter to these functions.  This is to eliminate confusion over where the
default comes from, as has been expressed in the past by some users of the
custom-variable facility.

* Refactor GUC code a bit to ensure that a custom variable gets initialized to
something valid (like its default value) even if the placeholder value was
invalid.
This commit is contained in:
Tom Lane
2008-11-19 01:10:24 +00:00
parent 667685ca7d
commit cd35e9d746
10 changed files with 293 additions and 170 deletions

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1994-5, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.180 2008/10/06 20:29:38 tgl Exp $
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.181 2008/11/19 01:10:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -224,7 +224,6 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ParamListInfo params,
QueryDesc *queryDesc;
instr_time starttime;
double totaltime = 0;
ExplainState *es;
StringInfoData buf;
int eflags;
@ -265,17 +264,9 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ParamListInfo params,
totaltime += elapsed_time(&starttime);
}
es = (ExplainState *) palloc0(sizeof(ExplainState));
es->printTList = stmt->verbose;
es->printAnalyze = stmt->analyze;
es->pstmt = queryDesc->plannedstmt;
es->rtable = queryDesc->plannedstmt->rtable;
/* Create textual dump of plan tree */
initStringInfo(&buf);
explain_outNode(&buf,
queryDesc->plannedstmt->planTree, queryDesc->planstate,
NULL, 0, es);
ExplainPrintPlan(&buf, queryDesc, stmt->analyze, stmt->verbose);
/*
* If we ran the command, run any AFTER triggers it queued. (Note this
@ -290,7 +281,7 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ParamListInfo params,
}
/* Print info about runtime of triggers */
if (es->printAnalyze)
if (stmt->analyze)
{
ResultRelInfo *rInfo;
bool show_relname;
@ -335,7 +326,34 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ParamListInfo params,
do_text_output_multiline(tstate, buf.data);
pfree(buf.data);
pfree(es);
}
/*
* ExplainPrintPlan -
* convert a QueryDesc's plan tree to text and append it to 'str'
*
* 'analyze' means to include runtime instrumentation results
* 'verbose' means a verbose printout (currently, it shows targetlists)
*
* NB: will not work on utility statements
*/
void
ExplainPrintPlan(StringInfo str, QueryDesc *queryDesc,
bool analyze, bool verbose)
{
ExplainState es;
Assert(queryDesc->plannedstmt != NULL);
memset(&es, 0, sizeof(es));
es.printTList = verbose;
es.printAnalyze = analyze;
es.pstmt = queryDesc->plannedstmt;
es.rtable = queryDesc->plannedstmt->rtable;
explain_outNode(str,
queryDesc->plannedstmt->planTree, queryDesc->planstate,
NULL, 0, &es);
}
/*