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

Commitdf4c3cb

Browse files
committed
Add parse_analyze_withcb()
This extracts code from pg_analyze_and_rewrite_withcb() into aseparate function that mirrors the existingparse_analyze_fixedparams() and parse_analyze_varparams().Reviewed-by: Nathan Bossart <bossartn@amazon.com>Discussion:https://www.postgresql.org/message-id/flat/c67ce276-52b4-0239-dc0e-39875bf81840@enterprisedb.com
1 parentddf590b commitdf4c3cb

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

‎src/backend/parser/analyze.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,44 @@ parse_analyze_varparams(RawStmt *parseTree, const char *sourceText,
181181
returnquery;
182182
}
183183

184+
/*
185+
* parse_analyze_withcb
186+
*
187+
* This variant is used when the caller supplies their own parser callback to
188+
* resolve parameters and possibly other things.
189+
*/
190+
Query*
191+
parse_analyze_withcb(RawStmt*parseTree,constchar*sourceText,
192+
ParserSetupHookparserSetup,
193+
void*parserSetupArg,
194+
QueryEnvironment*queryEnv)
195+
{
196+
ParseState*pstate=make_parsestate(NULL);
197+
Query*query;
198+
JumbleState*jstate=NULL;
199+
200+
Assert(sourceText!=NULL);/* required as of 8.4 */
201+
202+
pstate->p_sourcetext=sourceText;
203+
pstate->p_queryEnv=queryEnv;
204+
(*parserSetup) (pstate,parserSetupArg);
205+
206+
query=transformTopLevelStmt(pstate,parseTree);
207+
208+
if (IsQueryIdEnabled())
209+
jstate=JumbleQuery(query,sourceText);
210+
211+
if (post_parse_analyze_hook)
212+
(*post_parse_analyze_hook) (pstate,query,jstate);
213+
214+
free_parsestate(pstate);
215+
216+
pgstat_report_query_id(query->queryId, false);
217+
218+
returnquery;
219+
}
220+
221+
184222
/*
185223
* parse_sub_analyze
186224
*Entry point for recursively analyzing a sub-statement.

‎src/backend/tcop/postgres.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -736,12 +736,8 @@ pg_analyze_and_rewrite_withcb(RawStmt *parsetree,
736736
void*parserSetupArg,
737737
QueryEnvironment*queryEnv)
738738
{
739-
ParseState*pstate;
740739
Query*query;
741740
List*querytree_list;
742-
JumbleState*jstate=NULL;
743-
744-
Assert(query_string!=NULL);/* required as of 8.4 */
745741

746742
TRACE_POSTGRESQL_QUERY_REWRITE_START(query_string);
747743

@@ -751,22 +747,8 @@ pg_analyze_and_rewrite_withcb(RawStmt *parsetree,
751747
if (log_parser_stats)
752748
ResetUsage();
753749

754-
pstate=make_parsestate(NULL);
755-
pstate->p_sourcetext=query_string;
756-
pstate->p_queryEnv=queryEnv;
757-
(*parserSetup) (pstate,parserSetupArg);
758-
759-
query=transformTopLevelStmt(pstate,parsetree);
760-
761-
if (IsQueryIdEnabled())
762-
jstate=JumbleQuery(query,query_string);
763-
764-
if (post_parse_analyze_hook)
765-
(*post_parse_analyze_hook) (pstate,query,jstate);
766-
767-
free_parsestate(pstate);
768-
769-
pgstat_report_query_id(query->queryId, false);
750+
query=parse_analyze_withcb(parsetree,query_string,parserSetup,parserSetupArg,
751+
queryEnv);
770752

771753
if (log_parser_stats)
772754
ShowUsage("PARSE ANALYSIS STATISTICS");

‎src/include/parser/analyze.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndefANALYZE_H
1515
#defineANALYZE_H
1616

17+
#include"nodes/params.h"
1718
#include"parser/parse_node.h"
1819
#include"utils/queryjumble.h"
1920

@@ -28,6 +29,10 @@ extern Query *parse_analyze_fixedparams(RawStmt *parseTree, const char *sourceTe
2829
constOid*paramTypes,intnumParams,QueryEnvironment*queryEnv);
2930
externQuery*parse_analyze_varparams(RawStmt*parseTree,constchar*sourceText,
3031
Oid**paramTypes,int*numParams,QueryEnvironment*queryEnv);
32+
externQuery*parse_analyze_withcb(RawStmt*parseTree,constchar*sourceText,
33+
ParserSetupHookparserSetup,
34+
void*parserSetupArg,
35+
QueryEnvironment*queryEnv);
3136

3237
externQuery*parse_sub_analyze(Node*parseTree,ParseState*parentParseState,
3338
CommonTableExpr*parentCTE,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp