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

Commit6aba63e

Browse files
committed
Allow the planner-related functions and hook to accept the query string.
This commit adds query_string argument into the planner-related functionsand hook and allows us to pass the query string to them.Currently there is no user of the query string passed. But the upcoming patchfor the planning counters will add the planning hook function intopg_stat_statements and the function will need the query string. So this changewill be necessary for that patch.Also this change is useful for some extensions that want to use the querystring in their planner hook function.Author: Pascal Legrand, Julien RouhaudReviewed-by: Yoshikazu Imai, Tom Lane, Fujii MasaoDiscussion:https://postgr.es/m/CAOBaU_bU1m3_XF5qKYtSj1ua4dxd=FWDyh2SH4rSJAUUfsGmAQ@mail.gmail.comDiscussion:https://postgr.es/m/1583789487074-0.post@n3.nabble.com
1 parent4a539a2 commit6aba63e

File tree

13 files changed

+34
-20
lines changed

13 files changed

+34
-20
lines changed

‎src/backend/commands/copy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,8 @@ BeginCopy(ParseState *pstate,
15801580
}
15811581

15821582
/* plan the query */
1583-
plan=pg_plan_query(query,CURSOR_OPT_PARALLEL_OK,NULL);
1583+
plan=pg_plan_query(query,pstate->p_sourcetext,
1584+
CURSOR_OPT_PARALLEL_OK,NULL);
15841585

15851586
/*
15861587
* With row level security and a user using "COPY relation TO", we

‎src/backend/commands/createas.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt,
329329
Assert(query->commandType==CMD_SELECT);
330330

331331
/* plan the query */
332-
plan=pg_plan_query(query,CURSOR_OPT_PARALLEL_OK,params);
332+
plan=pg_plan_query(query,pstate->p_sourcetext,
333+
CURSOR_OPT_PARALLEL_OK,params);
333334

334335
/*
335336
* Use a snapshot with an updated command ID to ensure this query sees

‎src/backend/commands/explain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ ExplainOneQuery(Query *query, int cursorOptions,
376376
INSTR_TIME_SET_CURRENT(planstart);
377377

378378
/* plan the query */
379-
plan=pg_plan_query(query,cursorOptions,params);
379+
plan=pg_plan_query(query,queryString,cursorOptions,params);
380380

381381
INSTR_TIME_SET_CURRENT(planduration);
382382
INSTR_TIME_SUBTRACT(planduration,planstart);

‎src/backend/commands/extension.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ execute_sql_string(const char *sql)
751751
NULL,
752752
0,
753753
NULL);
754-
stmt_list=pg_plan_queries(stmt_list,CURSOR_OPT_PARALLEL_OK,NULL);
754+
stmt_list=pg_plan_queries(stmt_list,sql,CURSOR_OPT_PARALLEL_OK,NULL);
755755

756756
foreach(lc2,stmt_list)
757757
{

‎src/backend/commands/matview.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ refresh_matview_datafill(DestReceiver *dest, Query *query,
391391
CHECK_FOR_INTERRUPTS();
392392

393393
/* Plan the query which will generate data for the refresh. */
394-
plan=pg_plan_query(query,0,NULL);
394+
plan=pg_plan_query(query,queryString,0,NULL);
395395

396396
/*
397397
* Use a snapshot with an updated command ID to ensure this query sees

‎src/backend/commands/portalcmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ PerformCursorOpen(ParseState *pstate, DeclareCursorStmt *cstmt, ParamListInfo pa
9090
elog(ERROR,"non-SELECT statement in DECLARE CURSOR");
9191

9292
/* Plan the query, applying the specified options */
93-
plan=pg_plan_query(query,cstmt->options,params);
93+
plan=pg_plan_query(query,pstate->p_sourcetext,cstmt->options,params);
9494

9595
/*
9696
* Create a portal and copy the plan and query string into its memory.

‎src/backend/executor/functions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ init_execution_state(List *queryTree_list,
510510
}
511511
else
512512
stmt=pg_plan_query(queryTree,
513+
fcache->src,
513514
CURSOR_OPT_PARALLEL_OK,
514515
NULL);
515516

‎src/backend/optimizer/plan/planner.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,21 @@ static intcommon_prefix_cmp(const void *a, const void *b);
264264
*
265265
*****************************************************************************/
266266
PlannedStmt*
267-
planner(Query*parse,intcursorOptions,ParamListInfoboundParams)
267+
planner(Query*parse,constchar*query_string,intcursorOptions,
268+
ParamListInfoboundParams)
268269
{
269270
PlannedStmt*result;
270271

271272
if (planner_hook)
272-
result= (*planner_hook) (parse,cursorOptions,boundParams);
273+
result= (*planner_hook) (parse,query_string,cursorOptions,boundParams);
273274
else
274-
result=standard_planner(parse,cursorOptions,boundParams);
275+
result=standard_planner(parse,query_string,cursorOptions,boundParams);
275276
returnresult;
276277
}
277278

278279
PlannedStmt*
279-
standard_planner(Query*parse,intcursorOptions,ParamListInfoboundParams)
280+
standard_planner(Query*parse,constchar*query_string,intcursorOptions,
281+
ParamListInfoboundParams)
280282
{
281283
PlannedStmt*result;
282284
PlannerGlobal*glob;

‎src/backend/tcop/postgres.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,8 @@ pg_rewrite_query(Query *query)
854854
* This is a thin wrapper around planner() and takes the same parameters.
855855
*/
856856
PlannedStmt*
857-
pg_plan_query(Query*querytree,intcursorOptions,ParamListInfoboundParams)
857+
pg_plan_query(Query*querytree,constchar*query_string,intcursorOptions,
858+
ParamListInfoboundParams)
858859
{
859860
PlannedStmt*plan;
860861

@@ -871,7 +872,7 @@ pg_plan_query(Query *querytree, int cursorOptions, ParamListInfo boundParams)
871872
ResetUsage();
872873

873874
/* call the optimizer */
874-
plan=planner(querytree,cursorOptions,boundParams);
875+
plan=planner(querytree,query_string,cursorOptions,boundParams);
875876

876877
if (log_planner_stats)
877878
ShowUsage("PLANNER STATISTICS");
@@ -939,7 +940,8 @@ pg_plan_query(Query *querytree, int cursorOptions, ParamListInfo boundParams)
939940
* The result is a list of PlannedStmt nodes.
940941
*/
941942
List*
942-
pg_plan_queries(List*querytrees,intcursorOptions,ParamListInfoboundParams)
943+
pg_plan_queries(List*querytrees,constchar*query_string,intcursorOptions,
944+
ParamListInfoboundParams)
943945
{
944946
List*stmt_list=NIL;
945947
ListCell*query_list;
@@ -961,7 +963,8 @@ pg_plan_queries(List *querytrees, int cursorOptions, ParamListInfo boundParams)
961963
}
962964
else
963965
{
964-
stmt=pg_plan_query(query,cursorOptions,boundParams);
966+
stmt=pg_plan_query(query,query_string,cursorOptions,
967+
boundParams);
965968
}
966969

967970
stmt_list=lappend(stmt_list,stmt);
@@ -1152,7 +1155,7 @@ exec_simple_query(const char *query_string)
11521155
querytree_list=pg_analyze_and_rewrite(parsetree,query_string,
11531156
NULL,0,NULL);
11541157

1155-
plantree_list=pg_plan_queries(querytree_list,
1158+
plantree_list=pg_plan_queries(querytree_list,query_string,
11561159
CURSOR_OPT_PARALLEL_OK,NULL);
11571160

11581161
/*

‎src/backend/utils/cache/plancache.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,8 @@ BuildCachedPlan(CachedPlanSource *plansource, List *qlist,
930930
/*
931931
* Generate the plan.
932932
*/
933-
plist=pg_plan_queries(qlist,plansource->cursor_options,boundParams);
933+
plist=pg_plan_queries(qlist,plansource->query_string,
934+
plansource->cursor_options,boundParams);
934935

935936
/* Release snapshot if we got one */
936937
if (snapshot_set)

‎src/include/optimizer/optimizer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ typedef enum
102102
externintforce_parallel_mode;
103103
externboolparallel_leader_participation;
104104

105-
externstructPlannedStmt*planner(Query*parse,intcursorOptions,
105+
externstructPlannedStmt*planner(Query*parse,constchar*query_string,
106+
intcursorOptions,
106107
structParamListInfoData*boundParams);
107108

108109
externExpr*expression_planner(Expr*expr);

‎src/include/optimizer/planner.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
/* Hook for plugins to get control in planner() */
2626
typedefPlannedStmt*(*planner_hook_type) (Query*parse,
27+
constchar*query_string,
2728
intcursorOptions,
2829
ParamListInfoboundParams);
2930
externPGDLLIMPORTplanner_hook_typeplanner_hook;
@@ -37,7 +38,8 @@ typedef void (*create_upper_paths_hook_type) (PlannerInfo *root,
3738
externPGDLLIMPORTcreate_upper_paths_hook_typecreate_upper_paths_hook;
3839

3940

40-
externPlannedStmt*standard_planner(Query*parse,intcursorOptions,
41+
externPlannedStmt*standard_planner(Query*parse,constchar*query_string,
42+
intcursorOptions,
4143
ParamListInfoboundParams);
4244

4345
externPlannerInfo*subquery_planner(PlannerGlobal*glob,Query*parse,

‎src/include/tcop/tcopprot.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ extern List *pg_analyze_and_rewrite_params(RawStmt *parsetree,
5252
ParserSetupHookparserSetup,
5353
void*parserSetupArg,
5454
QueryEnvironment*queryEnv);
55-
externPlannedStmt*pg_plan_query(Query*querytree,intcursorOptions,
55+
externPlannedStmt*pg_plan_query(Query*querytree,constchar*query_string,
56+
intcursorOptions,
5657
ParamListInfoboundParams);
57-
externList*pg_plan_queries(List*querytrees,intcursorOptions,
58+
externList*pg_plan_queries(List*querytrees,constchar*query_string,
59+
intcursorOptions,
5860
ParamListInfoboundParams);
5961

6062
externboolcheck_max_stack_depth(int*newval,void**extra,GucSourcesource);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp