8000 Parse/analyze function renaming · postgrespro/postgres@791b1b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 791b1b7

Browse files
committed
Parse/analyze function renaming
There are three parallel ways to call parse/analyze: with fixed parameters, with variable parameters, and by supplying your own parser callback. Some of the involved functions were confusingly named and made this API structure more confusing. This patch renames some functions to make this clearer: parse_analyze() -> parse_analyze_fixedparams() pg_analyze_and_rewrite() -> pg_analyze_and_rewrite_fixedparams() (Otherwise one might think this variant doesn't accept parameters, but in fact all three ways accept parameters.) pg_analyze_and_rewrite_params() -> pg_analyze_and_rewrite_withcb() (Before, and also when considering pg_analyze_and_rewrite(), one might think this is the only way to pass parameters. Moreover, the parser callback doesn't necessarily need to parse only parameters, it's just one of the things it could do.) parse_fixed_parameters() -> setup_parse_fixed_parameters() parse_variable_parameters() -> setup_parse_variable_parameters() (These functions don't actually do any parsing, they just set up callbacks to use during parsing later.) This patch also adds some const decorations to the fixed-parameters API, so the distinction from the variable-parameters API is more clear. Reviewed-by: Nathan Bossart <bossartn@amazon.com> Discussion: https://www.postgresql.org/message-id/flat/c67ce276-52b4-0239-dc0e-39875bf81840@enterprisedb.com
1 parent d816f36 commit 791b1b7

File tree

17 files changed

+41
-40
lines changed

17 files changed

+41
-40
lines changed

src/backend/catalog/pg_proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
947947
RawStmt *parsetree = lfirst_node(RawStmt, lc);
948948
List *querytree_sublist;
949949

950-
querytree_sublist = pg_analyze_and_rewrite_params(parsetree,
950+
querytree_sublist = pg_analyze_and_rewrite_withcb(parsetree,
951951
prosrc,
952952
(ParserSetupHook) sql_fn_parser_setup,
953953
pinfo,

src/backend/commands/copyto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ BeginCopyTo(ParseState *pstate,
439439
* Run parse analysis and rewrite. Note this also acquires sufficient
440440
* locks on the source table(s).
441441
*/
442-
rewritten = pg_analyze_and_rewrite(raw_query,
442+
rewritten = pg_analyze_and_rewrite_fixedparams(raw_query,
443443
pstate->p_sourcetext, NULL, 0,
444444
NULL);
445445

src/backend/commands/extension.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ execute_sql_string(const char *sql)
757757
/* Be sure parser can see any DDL done so far */
758758
CommandCounterIncrement();
759759

760-
stmt_list = pg_analyze_and_rewrite(parsetree,
760+
stmt_list = pg_analyze_and_rewrite_fixedparams(parsetree,
761761
sql,
762762
NULL,
763763
0,

src/backend/commands/schemacmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString,
172172
/*
173173
* Execute each command contained in the CREATE SCHEMA. Since the grammar
174174
* allows only utility commands in CREATE SCHEMA, there is no need to pass
175-
* them through parse_analyze() or the rewriter; we can just hand them
175+
* them through parse_analyze_*() or the rewriter; we can just hand them
176176
* straight to ProcessUtility.
177177
*/
178178
foreach(parsetree_item, parsetree_list)

src/backend/commands/tablecmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13181,7 +13181,7 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
1318113181
/*
1318213182
* We expect that we will get only ALTER TABLE and CREATE INDEX
1318313183
* statements. Hence, there is no need to pass them through
13184-
* parse_analyze() or the rewriter, but instead we need to pass them
13184+
* parse_analyze_*() or the rewriter, but instead we need to pass them
1318513185
* through parse_utilcmd.c to make them ready for execution.
1318613186
*/
1318713187
raw_parsetree_list = raw_parser(cmd, RAW_PARSE_DEFAULT);

src/backend/commands/view.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ DefineView(ViewStmt *stmt, const char *queryString,
439439
rawstmt->stmt_location = stmt_location;
440440
rawstmt->stmt_len = stmt_len;
441441

442-
viewParse = parse_analyze(rawstmt, queryString, NULL, 0, NULL);
442+
viewParse = parse_analyze_fixedparams(rawstmt, queryString, NULL, 0, NULL);
443443

444444
/*
445445
* The grammar should ensure that the result is a single SELECT Query.

src/backend/executor/functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ init_sql_fcache(FunctionCallInfo fcinfo, Oid collation, bool lazyEvalOK)
718718
RawStmt *parsetree = lfirst_node(RawStmt, lc);
719719
List *queryTree_sublist;
720720

721-
queryTree_sublist = pg_analyze_and_rewrite_params(parsetree,
721+
queryTree_sublist = pg_analyze_and_rewrite_withcb(parsetree,
722722
fcache->src,
723723
(ParserSetupHook) sql_fn_parser_setup,
724724
fcache->pinfo,

src/backend/executor/spi.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,15 +2258,15 @@ _SPI_prepare_plan(const char *src, SPIPlanPtr plan)
22582258
if (plan->parserSetup != NULL)
22592259
{
22602260
Assert(plan->nargs == 0);
2261-
stmt_list = pg_analyze_and_rewrite_params(parsetree,
2261+
stmt_list = pg_analyze_and_rewrite_withcb(parsetree,
22622262
src,
22632263
plan->parserSetup,
22642264
plan->parserSetupArg,
22652265
_SPI_current->queryEnv);
22662266
}
22672267
else
22682268
{
2269-
stmt_list = pg_analyze_and_rewrite(parsetree,
2269+
stmt_list = pg_analyze_and_rewrite_fixedparams(parsetree,
22702270
src,
22712271
plan->argtypes,
22722272
plan->nargs,
@@ -2495,15 +2495,15 @@ _SPI_execute_plan(SPIPlanPtr plan, const SPIExecuteOptions *options,
24952495
else if (plan->parserSetup != NULL)
24962496
{
24972497
Assert(plan->nargs == 0);
2498-
stmt_list = pg_analyze_and_rewrite_params(parsetree,
2498+
stmt_list = pg_analyze_and_rewrite_withcb(parsetree,
24992499
src,
25002500
plan->parserSetup,
25012501
plan->parserSetupArg,
25022502
_SPI_current->queryEnv);
25032503
}
25042504
else
25052505
{
2506-
stmt_list = pg_analyze_and_rewrite(parsetree,
2506+
stmt_list = pg_analyze_and_rewrite_fixedparams(parsetree,
25072507
src,
25082508
plan->argtypes,
25092509
plan->nargs,

src/backend/optimizer/util/clauses.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5057,7 +5057,7 @@ inline_set_returning_function(PlannerInfo *root, RangeTblEntry *rte)
50575057
if (list_length(raw_parsetree_list) != 1)
50585058
goto fail;
50595059

5060-
querytree_list = pg_analyze_and_rewrite_params(linitial(raw_parsetree_list),
5060+
querytree_list = pg_analyze_and_rewrite_withcb(linitial(raw_parsetree_list),
50615061
src,
50625062
(ParserSetupHook) sql_fn_parser_setup,
50635063
pinfo, NULL);

src/backend/parser/analyze.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static bool test_raw_expression_coverage(Node *node, void *context);
9696

9797

9898
/*
99-
* parse_analyze
99+
* parse_analyze_fixedparams
100100
* Analyze a raw parse tree and transform it to Query form.
101101
*
102102
* Optionally, information about $n parameter types can be supplied.
@@ -107,8 +107,8 @@ static bool test_raw_expression_coverage(Node *node, void *context);
107107
* a dummy CMD_UTILITY Query node.
108108
*/
109109
Query *
110-
parse_analyze(RawStmt *parseTree, const char *sourceText,
111-
Oid *paramTypes, int numParams,
110+
parse_analyze_fixedparams(RawStmt *parseTree, const char *sourceText,
111+
const Oid *paramTypes, int numParams,
112112
QueryEnvironment *queryEnv)
113113
{
114114
ParseState *pstate = make_parsestate(NULL);
@@ -120,7 +120,7 @@ parse_analyze(RawStmt *parseTree, const char *sourceText,
120120
pstate->p_sourcetext = sourceText;
121121

122122
if (numParams > 0)
123-
parse_fixed_parameters(pstate, paramTypes, numParams);
123+
setup_parse_fixed_parameters(pstate, paramTypes, numParams);
124124

125125
pstate->p_queryEnv = queryEnv;
126126

@@ -158,7 +158,7 @@ parse_analyze_varparams(RawStmt *parseTree, const char *sourceText,
158158

159159
pstate->p_sourcetext = sourceText;
160160

161-
parse_variable_parameters(pstate, paramTypes, numParams);
161+
setup_parse_variable_parameters(pstate, paramTypes, numParams);
162162

163163
query = transformTopLevelStmt(pstate, parseTree);
164164

0 commit comments

Comments
 (0)
0