* ExecCreateTableAs -- execute a CREATE TABLE AS command
*/
ObjectAddress
-ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
+ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt,
ParamListInfo params, QueryEnvironment *queryEnv,
char *completionTag)
{
ExecuteStmt *estmt = castNode(ExecuteStmt, query->utilityStmt);
Assert(!is_matview); /* excluded by syntax */
- ExecuteQuery(estmt, into, queryString, params, dest, completionTag);
+ ExecuteQuery(pstate, estmt, into, params, dest, completionTag);
/* get object address that intorel_startup saved for us */
address = ((DR_intorel *) dest)->reladdr;
UpdateActiveSnapshotCommandId();
/* Create a QueryDesc, redirecting output to our tuple receiver */
- queryDesc = CreateQueryDesc(plan, queryString,
+ queryDesc = CreateQueryDesc(plan, pstate->p_sourcetext,
GetActiveSnapshot(), InvalidSnapshot,
dest, params, queryEnv, 0);
* execute an EXPLAIN command
*/
void
-ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString,
- ParamListInfo params, QueryEnvironment *queryEnv,
- DestReceiver *dest)
+ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
+ ParamListInfo params, DestReceiver *dest)
{
ExplainState *es = NewExplainState();
TupOutputState *tstate;
{
ExplainOneQuery(lfirst_node(Query, l),
CURSOR_OPT_PARALLEL_OK, NULL, es,
- queryString, params, queryEnv);
+ pstate->p_sourcetext, params, pstate->p_queryEnv);
/* Separate plans with an appropriate separator */
if (lnext(rewritten, l) != NULL)
* Execute SQL DECLARE CURSOR command.
*/
void
-PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params,
- const char *queryString, bool isTopLevel)
+PerformCursorOpen(ParseState *pstate, DeclareCursorStmt *cstmt, ParamListInfo params,
+ bool isTopLevel)
{
Query *query = castNode(Query, cstmt->query);
List *rewritten;
PlannedStmt *plan;
Portal portal;
MemoryContext oldContext;
+ char *queryString;
/*
* Disallow empty-string cursor name (conflicts with protocol-level
plan = pg_plan_query(query, cstmt->options, params);
/*
- * Create a portal and copy the plan and queryString into its memory.
+ * Create a portal and copy the plan and query string into its memory.
*/
portal = CreatePortal(cstmt->portalname, false, false);
plan = copyObject(plan);
- queryString = pstrdup(queryString);
+ queryString = pstrdup(pstate->p_sourcetext);
PortalDefineQuery(portal,
NULL,
static HTAB *prepared_queries = NULL;
static void InitQueryHashTable(void);
-static ParamListInfo EvaluateParams(PreparedStatement *pstmt, List *params,
- const char *queryString, EState *estate);
+static ParamListInfo EvaluateParams(ParseState *pstate,
+ PreparedStatement *pstmt, List *params,
+ EState *estate);
static Datum build_regtype_array(Oid *param_types, int num_params);
/*
* Implements the 'PREPARE' utility statement.
*/
void
-PrepareQuery(PrepareStmt *stmt, const char *queryString,
+PrepareQuery(ParseState *pstate, PrepareStmt *stmt,
int stmt_location, int stmt_len)
{
RawStmt *rawstmt;
* Create the CachedPlanSource before we do parse analysis, since it needs
* to see the unmodified raw parse tree.
*/
- plansource = CreateCachedPlan(rawstmt, queryString,
+ plansource = CreateCachedPlan(rawstmt, pstate->p_sourcetext,
CreateCommandTag(stmt->query));
/* Transform list of TypeNames to array of type OIDs */
if (nargs)
{
- ParseState *pstate;
ListCell *l;
- /*
- * typenameTypeId wants a ParseState to carry the source query string.
- * Is it worth refactoring its API to avoid this?
- */
- pstate = make_parsestate(NULL);
- pstate->p_sourcetext = queryString;
-
argtypes = (Oid *) palloc(nargs * sizeof(Oid));
i = 0;
* passed in from above us will not be visible to it), allowing
* information about unknown parameters to be deduced from context.
*/
- query = parse_analyze_varparams(rawstmt, queryString,
+ query = parse_analyze_varparams(rawstmt, pstate->p_sourcetext,
&argtypes, &nargs);
/*
* indicated by passing a non-null intoClause. The DestReceiver is already
* set up correctly for CREATE TABLE AS, but we still have to make a few
* other adjustments here.
- *
- * Note: this is one of very few places in the code that needs to deal with
- * two query strings at once. The passed-in queryString is that of the
- * EXECUTE, which we might need for error reporting while processing the
- * parameter expressions. The query_string that we copy from the plan
- * source is that of the original PREPARE.
*/
void
-ExecuteQuery(ExecuteStmt *stmt, IntoClause *intoClause,
- const char *queryString, ParamListInfo params,
+ExecuteQuery(ParseState *pstate,
+ ExecuteStmt *stmt, IntoClause *intoClause,
+ ParamListInfo params,
DestReceiver *dest, char *completionTag)
{
PreparedStatement *entry;
*/
estate = CreateExecutorState();
estate->es_param_list_info = params;
- paramLI = EvaluateParams(entry, stmt->params,
- queryString, estate);
+ paramLI = EvaluateParams(pstate, entry, stmt->params, estate);
}
/* Create a new portal to run the query in */
/*
* EvaluateParams: evaluate a list of parameters.
*
+ * pstate: parse state
* pstmt: statement we are getting parameters for.
* params: list of given parameter expressions (raw parser output!)
- * queryString: source text for error messages.
* estate: executor state to use.
*
* Returns a filled-in ParamListInfo -- this can later be passed to
* during query execution.
*/
static ParamListInfo
-EvaluateParams(PreparedStatement *pstmt, List *params,
- const char *queryString, EState *estate)
+EvaluateParams(ParseState *pstate, PreparedStatement *pstmt, List *params,
+ EState *estate)
{
Oid *param_types = pstmt->plansource->param_types;
int num_params = pstmt->plansource->num_params;
int nparams = list_length(params);
- ParseState *pstate;
ParamListInfo paramLI;
List *exprstates;
ListCell *l;
*/
params = copyObject(params);
- pstate = make_parsestate(NULL);
- pstate->p_sourcetext = queryString;
-
i = 0;
foreach(l, params)
{
/* Evaluate parameters, if any */
if (entry->plansource->num_params)
{
+ ParseState *pstate;
+
+ pstate = make_parsestate(NULL);
+ pstate->p_sourcetext = queryString;
+
/*
* Need an EState to evaluate parameters; must not delete it till end
* of query, in case parameters are pass-by-reference. Note that the
*/
estate = CreateExecutorState();
estate->es_param_list_info = params;
- paramLI = EvaluateParams(entry, execstmt->params,
- queryString, estate);
+
+ paramLI = EvaluateParams(pstate, entry, execstmt->params, estate);
}
/* Replan if needed, and acquire a transient refcount */
pstate = make_parsestate(NULL);
pstate->p_sourcetext = queryString;
+ pstate->p_queryEnv = queryEnv;
switch (nodeTag(parsetree))
{
* Portal (cursor) manipulation
*/
case T_DeclareCursorStmt:
- PerformCursorOpen((DeclareCursorStmt *) parsetree, params,
- queryString, isTopLevel);
+ PerformCursorOpen(pstate, (DeclareCursorStmt *) parsetree, params,
+ isTopLevel);
break;
case T_ClosePortalStmt:
case T_PrepareStmt:
CheckRestrictedOperation("PREPARE");
- PrepareQuery((PrepareStmt *) parsetree, queryString,
+ PrepareQuery(pstate, (PrepareStmt *) parsetree,
pstmt->stmt_location, pstmt->stmt_len);
break;
case T_ExecuteStmt:
- ExecuteQuery((ExecuteStmt *) parsetree, NULL,
- queryString, params,
+ ExecuteQuery(pstate,
+ (ExecuteStmt *) parsetree, NULL,
+ params,
dest, completionTag);
break;
break;
case T_ExplainStmt:
- ExplainQuery(pstate, (ExplainStmt *) parsetree, queryString, params,
- queryEnv, dest);
+ ExplainQuery(pstate, (ExplainStmt *) parsetree, params, dest);
break;
case T_AlterSystemStmt:
break;
case T_CreateTableAsStmt:
- address = ExecCreateTableAs((CreateTableAsStmt *) parsetree,
- queryString, params, queryEnv,
- completionTag);
+ address = ExecCreateTableAs(pstate, (CreateTableAsStmt *) parsetree,
+ params, queryEnv, completionTag);
break;
case T_RefreshMatViewStmt:
#include "utils/queryenvironment.h"
-extern ObjectAddress ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
+extern ObjectAddress ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt,
ParamListInfo params, QueryEnvironment *queryEnv, char *completionTag);
extern int GetIntoRelEFlags(IntoClause *intoClause);
extern PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook;
-extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString,
- ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest);
+extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
+ ParamListInfo params, DestReceiver *dest);
extern ExplainState *NewExplainState(void);
#define PORTALCMDS_H
#include "nodes/parsenodes.h"
+#include "parser/parse_node.h"
#include "utils/portal.h"
-extern void PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params,
- const char *queryString, bool isTopLevel);
+extern void PerformCursorOpen(ParseState *pstate, DeclareCursorStmt *cstmt, ParamListInfo params,
+ bool isTopLevel);
extern void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest,
char *completionTag);
/* Utility statements PREPARE, EXECUTE, DEALLOCATE, EXPLAIN EXECUTE */
-extern void PrepareQuery(PrepareStmt *stmt, const char *queryString,
+extern void PrepareQuery(ParseState *pstate, PrepareStmt *stmt,
int stmt_location, int stmt_len);
-extern void ExecuteQuery(ExecuteStmt *stmt, IntoClause *intoClause,
- const char *queryString, ParamListInfo params,
+extern void ExecuteQuery(ParseState *pstate,
+ ExecuteStmt *stmt, IntoClause *intoClause,
+ ParamListInfo params,
DestReceiver *dest, char *completionTag);
extern void DeallocateQuery(DeallocateStmt *stmt);
extern void ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into,