mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Invent GENERIC_PLAN option for EXPLAIN.
This provides a very simple way to see the generic plan for a parameterized query. Without this, it's necessary to define a prepared statement and temporarily change plan_cache_mode, which is a bit tedious. One thing that's a bit of a hack perhaps is that we disable execution-time partition pruning when the GENERIC_PLAN option is given. That's because the pruning code may attempt to fetch the value of one of the parameters, which would fail. Laurenz Albe, reviewed by Julien Rouhaud, Christoph Berg, Michel Pelletier, Jim Jones, and myself Discussion: https://postgr.es/m/0a29b954b10b57f0d135fe12aa0909bd41883eb0.camel@cybertec.at
This commit is contained in:
@ -27,6 +27,7 @@
|
||||
#include "access/sysattr.h"
|
||||
#include "catalog/pg_proc.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/defrem.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
#include "nodes/nodeFuncs.h"
|
||||
@ -2906,10 +2907,38 @@ static Query *
|
||||
transformExplainStmt(ParseState *pstate, ExplainStmt *stmt)
|
||||
{
|
||||
Query *result;
|
||||
bool generic_plan = false;
|
||||
Oid *paramTypes = NULL;
|
||||
int numParams = 0;
|
||||
|
||||
/*
|
||||
* If we have no external source of parameter definitions, and the
|
||||
* GENERIC_PLAN option is specified, then accept variable parameter
|
||||
* definitions (similarly to PREPARE, for example).
|
||||
*/
|
||||
if (pstate->p_paramref_hook == NULL)
|
||||
{
|
||||
ListCell *lc;
|
||||
|
||||
foreach(lc, stmt->options)
|
||||
{
|
||||
DefElem *opt = (DefElem *) lfirst(lc);
|
||||
|
||||
if (strcmp(opt->defname, "generic_plan") == 0)
|
||||
generic_plan = defGetBoolean(opt);
|
||||
/* don't "break", as we want the last value */
|
||||
}
|
||||
if (generic_plan)
|
||||
setup_parse_variable_parameters(pstate, ¶mTypes, &numParams);
|
||||
}
|
||||
|
||||
/* transform contained query, allowing SELECT INTO */
|
||||
stmt->query = (Node *) transformOptionalSelectInto(pstate, stmt->query);
|
||||
|
||||
/* make sure all is well with parameter types */
|
||||
if (generic_plan)
|
||||
check_variable_parameters(pstate, (Query *) stmt->query);
|
||||
|
||||
/* represent the command as a utility Query */
|
||||
result = makeNode(Query);
|
||||
result->commandType = CMD_UTILITY;
|
||||
|
Reference in New Issue
Block a user