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

Commitc0b0076

Browse files
committed
Rearrange snapshot handling to make rule expansion more consistent.
With this patch, portals, SQL functions, and SPI all agree that thereshould be only a CommandCounterIncrement between the queries that aregenerated from a single SQL command by rule expansion. Fetching a wholenew snapshot now happens only between original queries. This is equivalentto the existing behavior of EXPLAIN ANALYZE, and it was judged to be thebest choice since it eliminates one source of concurrency hazards forrules. The patch should also make things marginally faster by reducing thenumber of snapshot push/pop operations.The patch removes pg_parse_and_rewrite(), which is no longer used anywhere.There was considerable discussion about more aggressive refactoring of thequery-processing functions exported by postgres.c, but for the momentnothing more has been done there.I also took the opportunity to refactor snapmgr.c's API slightly: theformer PushUpdatedSnapshot() has been split into two functions.Marko Tiikkaja, reviewed by Steve Singer and Tom Lane
1 parent57e9bda commitc0b0076

File tree

10 files changed

+389
-217
lines changed

10 files changed

+389
-217
lines changed

‎src/backend/catalog/pg_proc.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,9 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
764764
Oidfuncoid=PG_GETARG_OID(0);
765765
HeapTupletuple;
766766
Form_pg_procproc;
767+
List*raw_parsetree_list;
767768
List*querytree_list;
769+
ListCell*lc;
768770
boolisnull;
769771
Datumtmp;
770772
char*prosrc;
@@ -835,17 +837,32 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
835837
* We can run the text through the raw parser though; this will at
836838
* least catch silly syntactic errors.
837839
*/
840+
raw_parsetree_list=pg_parse_query(prosrc);
841+
838842
if (!haspolyarg)
839843
{
840-
querytree_list=pg_parse_and_rewrite(prosrc,
841-
proc->proargtypes.values,
842-
proc->pronargs);
844+
/*
845+
* OK to do full precheck: analyze and rewrite the queries,
846+
* then verify the result type.
847+
*/
848+
querytree_list=NIL;
849+
foreach(lc,raw_parsetree_list)
850+
{
851+
Node*parsetree= (Node*)lfirst(lc);
852+
List*querytree_sublist;
853+
854+
querytree_sublist=pg_analyze_and_rewrite(parsetree,
855+
prosrc,
856+
proc->proargtypes.values,
857+
proc->pronargs);
858+
querytree_list=list_concat(querytree_list,
859+
querytree_sublist);
860+
}
861+
843862
(void)check_sql_fn_retval(funcoid,proc->prorettype,
844863
querytree_list,
845864
NULL,NULL);
846865
}
847-
else
848-
querytree_list=pg_parse_query(prosrc);
849866

850867
error_context_stack=sqlerrcontext.previous;
851868
}

‎src/backend/commands/copy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,8 @@ BeginCopy(bool is_from,
12161216
* Use a snapshot with an updated command ID to ensure this query sees
12171217
* results of any previously executed queries.
12181218
*/
1219-
PushUpdatedSnapshot(GetActiveSnapshot());
1219+
PushCopiedSnapshot(GetActiveSnapshot());
1220+
UpdateActiveSnapshotCommandId();
12201221

12211222
/* Create dest receiver for COPY OUT */
12221223
dest=CreateDestReceiver(DestCopyOut);

‎src/backend/commands/explain.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ExplainState *es,
366366
* Use a snapshot with an updated command ID to ensure this query sees
367367
* results of any previously executed queries.
368368
*/
369-
PushUpdatedSnapshot(GetActiveSnapshot());
369+
PushCopiedSnapshot(GetActiveSnapshot());
370+
UpdateActiveSnapshotCommandId();
370371

371372
/* Create a QueryDesc requesting no output */
372373
queryDesc=CreateQueryDesc(plannedstmt,queryString,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp