Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3fd40b6

Browse files
committed
Make better use of ParseState in ProcessUtility
Pass ParseState into the functions called fromstandard_ProcessUtility() instead passing the query string and queryenvironment separately. No functionality change, but it makes thenotation consistent. We had already started moving things intothat direction piece by piece, and this completes it.Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com>Discussion:https://www.postgresql.org/message-id/flat/6e7aa4a1-be6a-1a75-b1f9-83a678e5184a@2ndquadrant.com
1 parentd2e5e20 commit3fd40b6

File tree

9 files changed

+51
-61
lines changed

9 files changed

+51
-61
lines changed

‎src/backend/commands/createas.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ create_ctas_nodata(List *tlist, IntoClause *into)
223223
* ExecCreateTableAs -- execute a CREATE TABLE AS command
224224
*/
225225
ObjectAddress
226-
ExecCreateTableAs(CreateTableAsStmt*stmt,constchar*queryString,
226+
ExecCreateTableAs(ParseState*pstate,CreateTableAsStmt*stmt,
227227
ParamListInfoparams,QueryEnvironment*queryEnv,
228228
char*completionTag)
229229
{
@@ -270,7 +270,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
270270
ExecuteStmt*estmt=castNode(ExecuteStmt,query->utilityStmt);
271271

272272
Assert(!is_matview);/* excluded by syntax */
273-
ExecuteQuery(estmt,into,queryString,params,dest,completionTag);
273+
ExecuteQuery(pstate,estmt,into,params,dest,completionTag);
274274

275275
/* get object address that intorel_startup saved for us */
276276
address= ((DR_intorel*)dest)->reladdr;
@@ -342,7 +342,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
342342
UpdateActiveSnapshotCommandId();
343343

344344
/* Create a QueryDesc, redirecting output to our tuple receiver */
345-
queryDesc=CreateQueryDesc(plan,queryString,
345+
queryDesc=CreateQueryDesc(plan,pstate->p_sourcetext,
346346
GetActiveSnapshot(),InvalidSnapshot,
347347
dest,params,queryEnv,0);
348348

‎src/backend/commands/explain.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ static void escape_yaml(StringInfo buf, const char *str);
139139
* execute an EXPLAIN command
140140
*/
141141
void
142-
ExplainQuery(ParseState*pstate,ExplainStmt*stmt,constchar*queryString,
143-
ParamListInfoparams,QueryEnvironment*queryEnv,
144-
DestReceiver*dest)
142+
ExplainQuery(ParseState*pstate,ExplainStmt*stmt,
143+
ParamListInfoparams,DestReceiver*dest)
145144
{
146145
ExplainState*es=NewExplainState();
147146
TupOutputState*tstate;
@@ -254,7 +253,7 @@ ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString,
254253
{
255254
ExplainOneQuery(lfirst_node(Query,l),
256255
CURSOR_OPT_PARALLEL_OK,NULL,es,
257-
queryString,params,queryEnv);
256+
pstate->p_sourcetext,params,pstate->p_queryEnv);
258257

259258
/* Separate plans with an appropriate separator */
260259
if (lnext(rewritten,l)!=NULL)

‎src/backend/commands/portalcmds.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@
3939
*Execute SQL DECLARE CURSOR command.
4040
*/
4141
void
42-
PerformCursorOpen(DeclareCursorStmt*cstmt,ParamListInfoparams,
43-
constchar*queryString,boolisTopLevel)
42+
PerformCursorOpen(ParseState*pstate,DeclareCursorStmt*cstmt,ParamListInfoparams,
43+
boolisTopLevel)
4444
{
4545
Query*query=castNode(Query,cstmt->query);
4646
List*rewritten;
4747
PlannedStmt*plan;
4848
Portalportal;
4949
MemoryContextoldContext;
50+
char*queryString;
5051

5152
/*
5253
* Disallow empty-string cursor name (conflicts with protocol-level
@@ -92,15 +93,15 @@ PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params,
9293
plan=pg_plan_query(query,cstmt->options,params);
9394

9495
/*
95-
* Create a portal and copy the plan andqueryString into its memory.
96+
* Create a portal and copy the plan andquery string into its memory.
9697
*/
9798
portal=CreatePortal(cstmt->portalname, false, false);
9899

99100
oldContext=MemoryContextSwitchTo(portal->portalContext);
100101

101102
plan=copyObject(plan);
102103

103-
queryString=pstrdup(queryString);
104+
queryString=pstrdup(pstate->p_sourcetext);
104105

105106
PortalDefineQuery(portal,
106107
NULL,

‎src/backend/commands/prepare.c

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@
4646
staticHTAB*prepared_queries=NULL;
4747

4848
staticvoidInitQueryHashTable(void);
49-
staticParamListInfoEvaluateParams(PreparedStatement*pstmt,List*params,
50-
constchar*queryString,EState*estate);
49+
staticParamListInfoEvaluateParams(ParseState*pstate,
50+
PreparedStatement*pstmt,List*params,
51+
EState*estate);
5152
staticDatumbuild_regtype_array(Oid*param_types,intnum_params);
5253

5354
/*
5455
* Implements the 'PREPARE' utility statement.
5556
*/
5657
void
57-
PrepareQuery(PrepareStmt*stmt,constchar*queryString,
58+
PrepareQuery(ParseState*pstate,PrepareStmt*stmt,
5859
intstmt_location,intstmt_len)
5960
{
6061
RawStmt*rawstmt;
@@ -90,24 +91,16 @@ PrepareQuery(PrepareStmt *stmt, const char *queryString,
9091
* Create the CachedPlanSource before we do parse analysis, since it needs
9192
* to see the unmodified raw parse tree.
9293
*/
93-
plansource=CreateCachedPlan(rawstmt,queryString,
94+
plansource=CreateCachedPlan(rawstmt,pstate->p_sourcetext,
9495
CreateCommandTag(stmt->query));
9596

9697
/* Transform list of TypeNames to array of type OIDs */
9798
nargs=list_length(stmt->argtypes);
9899

99100
if (nargs)
100101
{
101-
ParseState*pstate;
102102
ListCell*l;
103103

104-
/*
105-
* typenameTypeId wants a ParseState to carry the source query string.
106-
* Is it worth refactoring its API to avoid this?
107-
*/
108-
pstate=make_parsestate(NULL);
109-
pstate->p_sourcetext=queryString;
110-
111104
argtypes= (Oid*)palloc(nargs*sizeof(Oid));
112105
i=0;
113106

@@ -125,7 +118,7 @@ PrepareQuery(PrepareStmt *stmt, const char *queryString,
125118
* passed in from above us will not be visible to it), allowing
126119
* information about unknown parameters to be deduced from context.
127120
*/
128-
query=parse_analyze_varparams(rawstmt,queryString,
121+
query=parse_analyze_varparams(rawstmt,pstate->p_sourcetext,
129122
&argtypes,&nargs);
130123

131124
/*
@@ -189,16 +182,11 @@ PrepareQuery(PrepareStmt *stmt, const char *queryString,
189182
* indicated by passing a non-null intoClause. The DestReceiver is already
190183
* set up correctly for CREATE TABLE AS, but we still have to make a few
191184
* other adjustments here.
192-
*
193-
* Note: this is one of very few places in the code that needs to deal with
194-
* two query strings at once. The passed-in queryString is that of the
195-
* EXECUTE, which we might need for error reporting while processing the
196-
* parameter expressions. The query_string that we copy from the plan
197-
* source is that of the original PREPARE.
198185
*/
199186
void
200-
ExecuteQuery(ExecuteStmt*stmt,IntoClause*intoClause,
201-
constchar*queryString,ParamListInfoparams,
187+
ExecuteQuery(ParseState*pstate,
188+
ExecuteStmt*stmt,IntoClause*intoClause,
189+
ParamListInfoparams,
202190
DestReceiver*dest,char*completionTag)
203191
{
204192
PreparedStatement*entry;
@@ -229,8 +217,7 @@ ExecuteQuery(ExecuteStmt *stmt, IntoClause *intoClause,
229217
*/
230218
estate=CreateExecutorState();
231219
estate->es_param_list_info=params;
232-
paramLI=EvaluateParams(entry,stmt->params,
233-
queryString,estate);
220+
paramLI=EvaluateParams(pstate,entry,stmt->params,estate);
234221
}
235222

236223
/* Create a new portal to run the query in */
@@ -314,23 +301,22 @@ ExecuteQuery(ExecuteStmt *stmt, IntoClause *intoClause,
314301
/*
315302
* EvaluateParams: evaluate a list of parameters.
316303
*
304+
* pstate: parse state
317305
* pstmt: statement we are getting parameters for.
318306
* params: list of given parameter expressions (raw parser output!)
319-
* queryString: source text for error messages.
320307
* estate: executor state to use.
321308
*
322309
* Returns a filled-in ParamListInfo -- this can later be passed to
323310
* CreateQueryDesc(), which allows the executor to make use of the parameters
324311
* during query execution.
325312
*/
326313
staticParamListInfo
327-
EvaluateParams(PreparedStatement*pstmt,List*params,
328-
constchar*queryString,EState*estate)
314+
EvaluateParams(ParseState*pstate,PreparedStatement*pstmt,List*params,
315+
EState*estate)
329316
{
330317
Oid*param_types=pstmt->plansource->param_types;
331318
intnum_params=pstmt->plansource->num_params;
332319
intnparams=list_length(params);
333-
ParseState*pstate;
334320
ParamListInfoparamLI;
335321
List*exprstates;
336322
ListCell*l;
@@ -354,9 +340,6 @@ EvaluateParams(PreparedStatement *pstmt, List *params,
354340
*/
355341
params=copyObject(params);
356342

357-
pstate=make_parsestate(NULL);
358-
pstate->p_sourcetext=queryString;
359-
360343
i=0;
361344
foreach(l,params)
362345
{
@@ -648,6 +631,11 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es,
648631
/* Evaluate parameters, if any */
649632
if (entry->plansource->num_params)
650633
{
634+
ParseState*pstate;
635+
636+
pstate=make_parsestate(NULL);
637+
pstate->p_sourcetext=queryString;
638+
651639
/*
652640
* Need an EState to evaluate parameters; must not delete it till end
653641
* of query, in case parameters are pass-by-reference. Note that the
@@ -656,8 +644,8 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es,
656644
*/
657645
estate=CreateExecutorState();
658646
estate->es_param_list_info=params;
659-
paramLI=EvaluateParams(entry,execstmt->params,
660-
queryString,estate);
647+
648+
paramLI=EvaluateParams(pstate,entry,execstmt->params,estate);
661649
}
662650

663651
/* Replan if needed, and acquire a transient refcount */

‎src/backend/tcop/utility.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
396396

397397
pstate=make_parsestate(NULL);
398398
pstate->p_sourcetext=queryString;
399+
pstate->p_queryEnv=queryEnv;
399400

400401
switch (nodeTag(parsetree))
401402
{
@@ -500,8 +501,8 @@ standard_ProcessUtility(PlannedStmt *pstmt,
500501
* Portal (cursor) manipulation
501502
*/
502503
caseT_DeclareCursorStmt:
503-
PerformCursorOpen((DeclareCursorStmt*)parsetree,params,
504-
queryString,isTopLevel);
504+
PerformCursorOpen(pstate,(DeclareCursorStmt*)parsetree,params,
505+
isTopLevel);
505506
break;
506507

507508
caseT_ClosePortalStmt:
@@ -558,13 +559,14 @@ standard_ProcessUtility(PlannedStmt *pstmt,
558559

559560
caseT_PrepareStmt:
560561
CheckRestrictedOperation("PREPARE");
561-
PrepareQuery((PrepareStmt*)parsetree,queryString,
562+
PrepareQuery(pstate,(PrepareStmt*)parsetree,
562563
pstmt->stmt_location,pstmt->stmt_len);
563564
break;
564565

565566
caseT_ExecuteStmt:
566-
ExecuteQuery((ExecuteStmt*)parsetree,NULL,
567-
queryString,params,
567+
ExecuteQuery(pstate,
568+
(ExecuteStmt*)parsetree,NULL,
569+
params,
568570
dest,completionTag);
569571
break;
570572

@@ -667,8 +669,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,
667669
break;
668670

669671
caseT_ExplainStmt:
670-
ExplainQuery(pstate, (ExplainStmt*)parsetree,queryString,params,
671-
queryEnv,dest);
672+
ExplainQuery(pstate, (ExplainStmt*)parsetree,params,dest);
672673
break;
673674

674675
caseT_AlterSystemStmt:
@@ -1490,9 +1491,8 @@ ProcessUtilitySlow(ParseState *pstate,
14901491
break;
14911492

14921493
caseT_CreateTableAsStmt:
1493-
address=ExecCreateTableAs((CreateTableAsStmt*)parsetree,
1494-
queryString,params,queryEnv,
1495-
completionTag);
1494+
address=ExecCreateTableAs(pstate, (CreateTableAsStmt*)parsetree,
1495+
params,queryEnv,completionTag);
14961496
break;
14971497

14981498
caseT_RefreshMatViewStmt:

‎src/include/commands/createas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include"utils/queryenvironment.h"
2222

2323

24-
externObjectAddressExecCreateTableAs(CreateTableAsStmt*stmt,constchar*queryString,
24+
externObjectAddressExecCreateTableAs(ParseState*pstate,CreateTableAsStmt*stmt,
2525
ParamListInfoparams,QueryEnvironment*queryEnv,char*completionTag);
2626

2727
externintGetIntoRelEFlags(IntoClause*intoClause);

‎src/include/commands/explain.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ typedef const char *(*explain_get_index_name_hook_type) (Oid indexId);
6464
externPGDLLIMPORTexplain_get_index_name_hook_typeexplain_get_index_name_hook;
6565

6666

67-
externvoidExplainQuery(ParseState*pstate,ExplainStmt*stmt,constchar*queryString,
68-
ParamListInfoparams,QueryEnvironment*queryEnv,DestReceiver*dest);
67+
externvoidExplainQuery(ParseState*pstate,ExplainStmt*stmt,
68+
ParamListInfoparams,DestReceiver*dest);
6969

7070
externExplainState*NewExplainState(void);
7171

‎src/include/commands/portalcmds.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
#definePORTALCMDS_H
1616

1717
#include"nodes/parsenodes.h"
18+
#include"parser/parse_node.h"
1819
#include"utils/portal.h"
1920

2021

21-
externvoidPerformCursorOpen(DeclareCursorStmt*cstmt,ParamListInfoparams,
22-
constchar*queryString,boolisTopLevel);
22+
externvoidPerformCursorOpen(ParseState*pstate,DeclareCursorStmt*cstmt,ParamListInfoparams,
23+
boolisTopLevel);
2324

2425
externvoidPerformPortalFetch(FetchStmt*stmt,DestReceiver*dest,
2526
char*completionTag);

‎src/include/commands/prepare.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ typedef struct
3535

3636

3737
/* Utility statements PREPARE, EXECUTE, DEALLOCATE, EXPLAIN EXECUTE */
38-
externvoidPrepareQuery(PrepareStmt*stmt,constchar*queryString,
38+
externvoidPrepareQuery(ParseState*pstate,PrepareStmt*stmt,
3939
intstmt_location,intstmt_len);
40-
externvoidExecuteQuery(ExecuteStmt*stmt,IntoClause*intoClause,
41-
constchar*queryString,ParamListInfoparams,
40+
externvoidExecuteQuery(ParseState*pstate,
41+
ExecuteStmt*stmt,IntoClause*intoClause,
42+
ParamListInfoparams,
4243
DestReceiver*dest,char*completionTag);
4344
externvoidDeallocateQuery(DeallocateStmt*stmt);
4445
externvoidExplainExecuteQuery(ExecuteStmt*execstmt,IntoClause*into,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp