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

Commit786afc1

Browse files
committed
Revert patch for taking fewer snapshots.
This reverts commitd573e23, "Take fewersnapshots". While that seemed like a good idea at the time, it causedexecution to use a snapshot that had been acquired before locking any ofthe tables mentioned in the query. This created user-visible anomaliesthat were not present in any prior release of Postgres, as reported byTomas Vondra. While this whole area could do with a redesign (since thereare related cases that have anomalies anyway), it doesn't seem likely thatany future patch would be reasonably back-patchable; and we don't want 9.2to exhibit a behavior that's subtly unlike either past or future releases.Hence, revert to prior code while we rethink the problem.
1 parenteea6ada commit786afc1

File tree

7 files changed

+32
-46
lines changed

7 files changed

+32
-46
lines changed

‎doc/src/sgml/release-9.2.sgml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -809,13 +809,6 @@
809809
</para>
810810
</listitem>
811811

812-
<listitem>
813-
<para>
814-
Take fewer <acronym>MVCC</acronym> snapshots
815-
(Robert Haas)
816-
</para>
817-
</listitem>
818-
819812
<listitem>
820813
<para>
821814
Make the number of CLOG buffers scale based on <link

‎src/backend/commands/portalcmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ PerformCursorOpen(PlannedStmt *stmt, ParamListInfo params,
121121
/*
122122
* Start execution, inserting parameters if any.
123123
*/
124-
PortalStart(portal,params,0,true);
124+
PortalStart(portal,params,0,GetActiveSnapshot());
125125

126126
Assert(portal->strategy==PORTAL_ONE_SELECT);
127127

‎src/backend/commands/prepare.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ ExecuteQuery(ExecuteStmt *stmt, IntoClause *intoClause,
289289
/*
290290
* Run the portal as appropriate.
291291
*/
292-
PortalStart(portal,paramLI,eflags,true);
292+
PortalStart(portal,paramLI,eflags,GetActiveSnapshot());
293293

294294
(void)PortalRun(portal,count, false,dest,dest,completionTag);
295295

‎src/backend/executor/spi.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,7 @@ SPI_cursor_open_internal(const char *name, SPIPlanPtr plan,
11261126
CachedPlan*cplan;
11271127
List*stmt_list;
11281128
char*query_string;
1129+
Snapshotsnapshot;
11291130
MemoryContextoldcontext;
11301131
Portalportal;
11311132

@@ -1268,6 +1269,15 @@ SPI_cursor_open_internal(const char *name, SPIPlanPtr plan,
12681269
}
12691270
}
12701271

1272+
/* Set up the snapshot to use. */
1273+
if (read_only)
1274+
snapshot=GetActiveSnapshot();
1275+
else
1276+
{
1277+
CommandCounterIncrement();
1278+
snapshot=GetTransactionSnapshot();
1279+
}
1280+
12711281
/*
12721282
* If the plan has parameters, copy them into the portal. Note that this
12731283
* must be done after revalidating the plan, because in dynamic parameter
@@ -1283,13 +1293,7 @@ SPI_cursor_open_internal(const char *name, SPIPlanPtr plan,
12831293
/*
12841294
* Start portal execution.
12851295
*/
1286-
if (read_only)
1287-
PortalStart(portal,paramLI,0, true);
1288-
else
1289-
{
1290-
CommandCounterIncrement();
1291-
PortalStart(portal,paramLI,0, false);
1292-
}
1296+
PortalStart(portal,paramLI,0,snapshot);
12931297

12941298
Assert(portal->strategy!=PORTAL_MULTI_QUERY);
12951299

‎src/backend/tcop/postgres.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,10 @@ exec_simple_query(const char *query_string)
974974

975975
plantree_list=pg_plan_queries(querytree_list,0,NULL);
976976

977+
/* Done with the snapshot used for parsing/planning */
978+
if (snapshot_set)
979+
PopActiveSnapshot();
980+
977981
/* If we got a cancel signal in analysis or planning, quit */
978982
CHECK_FOR_INTERRUPTS();
979983

@@ -998,19 +1002,9 @@ exec_simple_query(const char *query_string)
9981002
NULL);
9991003

10001004
/*
1001-
* Start the portal.
1002-
*
1003-
* If we took a snapshot for parsing/planning, the portal may be able
1004-
* to reuse it for the execution phase. Currently, this will only
1005-
* happen in PORTAL_ONE_SELECT mode. But even if PortalStart doesn't
1006-
* end up being able to do this, keeping the parse/plan snapshot
1007-
* around until after we start the portal doesn't cost much.
1005+
* Start the portal. No parameters here.
10081006
*/
1009-
PortalStart(portal,NULL,0,snapshot_set);
1010-
1011-
/* Done with the snapshot used for parsing/planning */
1012-
if (snapshot_set)
1013-
PopActiveSnapshot();
1007+
PortalStart(portal,NULL,0,InvalidSnapshot);
10141008

10151009
/*
10161010
* Select the appropriate output format: text unless we are doing a
@@ -1733,19 +1727,15 @@ exec_bind_message(StringInfo input_message)
17331727
cplan->stmt_list,
17341728
cplan);
17351729

1736-
/*
1737-
* And we're ready to start portal execution.
1738-
*
1739-
* If we took a snapshot for parsing/planning, we'll try to reuse it for
1740-
* query execution (currently, reuse will only occur if PORTAL_ONE_SELECT
1741-
* mode is chosen).
1742-
*/
1743-
PortalStart(portal,params,0,snapshot_set);
1744-
17451730
/* Done with the snapshot used for parameter I/O and parsing/planning */
17461731
if (snapshot_set)
17471732
PopActiveSnapshot();
17481733

1734+
/*
1735+
* And we're ready to start portal execution.
1736+
*/
1737+
PortalStart(portal,params,0,InvalidSnapshot);
1738+
17491739
/*
17501740
* Apply the result format requests to the portal.
17511741
*/

‎src/backend/tcop/pquery.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,18 +447,17 @@ FetchStatementTargetList(Node *stmt)
447447
* currently only honored for PORTAL_ONE_SELECT portals). Most callers
448448
* should simply pass zero.
449449
*
450-
* The use_active_snapshot parameter is currently used only for
451-
* PORTAL_ONE_SELECT portals. If it is true, the active snapshot will
452-
* be used when starting up the executor; if false, a new snapshot will
453-
* be taken. This is used both for cursors and to avoid taking an entirely
454-
* new snapshot when it isn't necessary.
450+
* The caller can optionally pass a snapshot to be used; pass InvalidSnapshot
451+
* for the normal behavior of setting a new snapshot. This parameter is
452+
* presently ignored for non-PORTAL_ONE_SELECT portals (it's only intended
453+
* to be used for cursors).
455454
*
456455
* On return, portal is ready to accept PortalRun() calls, and the result
457456
* tupdesc (if any) is known.
458457
*/
459458
void
460459
PortalStart(Portalportal,ParamListInfoparams,
461-
inteflags,booluse_active_snapshot)
460+
inteflags,Snapshotsnapshot)
462461
{
463462
PortalsaveActivePortal;
464463
ResourceOwnersaveResourceOwner;
@@ -500,8 +499,8 @@ PortalStart(Portal portal, ParamListInfo params,
500499
casePORTAL_ONE_SELECT:
501500

502501
/* Must set snapshot before starting executor. */
503-
if (use_active_snapshot)
504-
PushActiveSnapshot(GetActiveSnapshot());
502+
if (snapshot)
503+
PushActiveSnapshot(snapshot);
505504
else
506505
PushActiveSnapshot(GetTransactionSnapshot());
507506

‎src/include/tcop/pquery.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern List *FetchPortalTargetList(Portal portal);
2828
externList*FetchStatementTargetList(Node*stmt);
2929

3030
externvoidPortalStart(Portalportal,ParamListInfoparams,
31-
inteflags,booluse_active_snapshot);
31+
inteflags,Snapshotsnapshot);
3232

3333
externvoidPortalSetResultFormat(Portalportal,intnFormats,
3434
int16*formats);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp