mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Redesign query-snapshot timing so that volatile functions in READ COMMITTED
mode see a fresh snapshot for each command in the function, rather than using the latest interactive command's snapshot. Also, suppress fresh snapshots as well as CommandCounterIncrement inside STABLE and IMMUTABLE functions, instead using the snapshot taken for the most closely nested regular query. (This behavior is only sane for read-only functions, so the patch also enforces that such functions contain only SELECT commands.) As per my proposal of 6-Sep-2004; I note that I floated essentially the same proposal on 19-Jun-2002, but that discussion tailed off without any action. Since 8.0 seems like the right place to be taking possibly nontrivial backwards compatibility hits, let's get it done now.
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.129 2004/08/29 05:06:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.130 2004/09/13 20:06:23 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -202,8 +202,8 @@ cluster(ClusterStmt *stmt)
|
||||
|
||||
/* Start a new transaction for each relation. */
|
||||
StartTransactionCommand();
|
||||
SetQuerySnapshot(); /* might be needed for functions in
|
||||
* indexes */
|
||||
/* functions in indexes may want a snapshot set */
|
||||
ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
|
||||
cluster_rel(rvtc, true);
|
||||
CommitTransactionCommand();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.231 2004/09/10 18:39:56 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.232 2004/09/13 20:06:27 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1182,7 +1182,6 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
Oid *typioparams;
|
||||
bool *isvarlena;
|
||||
char *string;
|
||||
Snapshot mySnapshot;
|
||||
ListCell *cur;
|
||||
MemoryContext oldcontext;
|
||||
MemoryContext mycontext;
|
||||
@@ -1260,9 +1259,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
strlen(null_print));
|
||||
}
|
||||
|
||||
mySnapshot = CopyQuerySnapshot();
|
||||
|
||||
scandesc = heap_beginscan(rel, mySnapshot, 0, NULL);
|
||||
scandesc = heap_beginscan(rel, ActiveSnapshot, 0, NULL);
|
||||
|
||||
while ((tuple = heap_getnext(scandesc, ForwardScanDirection)) != NULL)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994-5, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.125 2004/09/10 18:39:56 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.126 2004/09/13 20:06:28 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -180,7 +180,9 @@ ExplainOneQuery(Query *query, ExplainStmt *stmt, TupOutputState *tstate)
|
||||
plan = planner(query, isCursor, cursorOptions, NULL);
|
||||
|
||||
/* Create a QueryDesc requesting no output */
|
||||
queryDesc = CreateQueryDesc(query, plan, None_Receiver, NULL,
|
||||
queryDesc = CreateQueryDesc(query, plan,
|
||||
ActiveSnapshot, InvalidSnapshot,
|
||||
None_Receiver, NULL,
|
||||
stmt->analyze);
|
||||
|
||||
ExplainOnePlan(queryDesc, stmt, tstate);
|
||||
@@ -212,7 +214,7 @@ ExplainOnePlan(QueryDesc *queryDesc, ExplainStmt *stmt,
|
||||
AfterTriggerBeginQuery();
|
||||
|
||||
/* call ExecutorStart to prepare the plan for execution */
|
||||
ExecutorStart(queryDesc, false, !stmt->analyze);
|
||||
ExecutorStart(queryDesc, !stmt->analyze);
|
||||
|
||||
/* Execute the plan for statistics if asked for */
|
||||
if (stmt->analyze)
|
||||
@@ -272,7 +274,9 @@ ExplainOnePlan(QueryDesc *queryDesc, ExplainStmt *stmt,
|
||||
|
||||
FreeQueryDesc(queryDesc);
|
||||
|
||||
CommandCounterIncrement();
|
||||
/* We need a CCI just in case query expanded to multiple plans */
|
||||
if (stmt->analyze)
|
||||
CommandCounterIncrement();
|
||||
|
||||
totaltime += elapsed_time(&starttime);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.125 2004/08/29 05:06:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.126 2004/09/13 20:06:29 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1060,8 +1060,8 @@ ReindexDatabase(const char *dbname, bool force /* currently unused */ ,
|
||||
Oid relid = lfirst_oid(l);
|
||||
|
||||
StartTransactionCommand();
|
||||
SetQuerySnapshot(); /* might be needed for functions in
|
||||
* indexes */
|
||||
/* functions in indexes may want a snapshot set */
|
||||
ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
|
||||
if (reindex_relation(relid, true))
|
||||
ereport(NOTICE,
|
||||
(errmsg("table \"%s\" was reindexed",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.34 2004/09/10 18:39:56 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.35 2004/09/13 20:06:29 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -135,7 +135,7 @@ PerformCursorOpen(DeclareCursorStmt *stmt, ParamListInfo params)
|
||||
/*
|
||||
* Start execution, inserting parameters if any.
|
||||
*/
|
||||
PortalStart(portal, params);
|
||||
PortalStart(portal, params, ActiveSnapshot);
|
||||
|
||||
Assert(portal->strategy == PORTAL_ONE_SELECT);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* Copyright (c) 2002-2004, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.31 2004/08/29 05:06:41 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.32 2004/09/13 20:06:29 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -186,7 +186,7 @@ ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest, char *completionTag)
|
||||
/*
|
||||
* Run the portal to completion.
|
||||
*/
|
||||
PortalStart(portal, paramLI);
|
||||
PortalStart(portal, paramLI, ActiveSnapshot);
|
||||
|
||||
(void) PortalRun(portal, FETCH_ALL, dest, dest, completionTag);
|
||||
|
||||
@@ -544,7 +544,9 @@ ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate)
|
||||
}
|
||||
|
||||
/* Create a QueryDesc requesting no output */
|
||||
qdesc = CreateQueryDesc(query, plan, None_Receiver,
|
||||
qdesc = CreateQueryDesc(query, plan,
|
||||
ActiveSnapshot, InvalidSnapshot,
|
||||
None_Receiver,
|
||||
paramLI, stmt->analyze);
|
||||
|
||||
ExplainOnePlan(qdesc, stmt, tstate);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.290 2004/08/30 02:54:38 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.291 2004/09/13 20:06:29 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -402,8 +402,8 @@ vacuum(VacuumStmt *vacstmt)
|
||||
if (use_own_xacts)
|
||||
{
|
||||
StartTransactionCommand();
|
||||
SetQuerySnapshot(); /* might be needed for functions
|
||||
* in indexes */
|
||||
/* functions in indexes may want a snapshot set */
|
||||
ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
|
||||
}
|
||||
else
|
||||
old_context = MemoryContextSwitchTo(anl_context);
|
||||
@@ -865,8 +865,8 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
|
||||
|
||||
/* Begin a transaction for vacuuming this relation */
|
||||
StartTransactionCommand();
|
||||
SetQuerySnapshot(); /* might be needed for functions in
|
||||
* indexes */
|
||||
/* functions in indexes may want a snapshot set */
|
||||
ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
|
||||
|
||||
/*
|
||||
* Tell the cache replacement strategy that vacuum is causing all
|
||||
|
||||
Reference in New Issue
Block a user