Skip to content

Commit 9fc24f2

Browse files
committed
Fix EXPLAIN ANALYZE bug noted by Wiebe Cazemier: although we were
properly advancing the CommandCounter between multiple sub-queries generated by rules, we forgot to update the snapshot being used, so that the successive sub-queries didn't actually see each others' results. This is still not *exactly* like the semantics of normal execution of the same queries, in that we don't take new transaction snapshots and hence don't see changes from concurrently committed commands, but I think that's OK and probably even preferable for EXPLAIN ANALYZE.
1 parent ef3b7cd commit 9fc24f2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/backend/commands/explain.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994-5, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.138 2005/10/15 02:49:15 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.139 2005/10/21 16:43:33 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -196,6 +196,15 @@ ExplainOneQuery(Query *query, ExplainStmt *stmt, TupOutputState *tstate)
196196
/* plan the query */
197197
plan = planner(query, isCursor, cursorOptions, NULL);
198198

199+
/*
200+
* Update snapshot command ID to ensure this query sees results of any
201+
* previously executed queries. (It's a bit cheesy to modify
202+
* ActiveSnapshot without making a copy, but for the limited ways in
203+
* which EXPLAIN can be invoked, I think it's OK, because the active
204+
* snapshot shouldn't be shared with anything else anyway.)
205+
*/
206+
ActiveSnapshot->curcid = GetCurrentCommandId();
207+
199208
/* Create a QueryDesc requesting no output */
200209
queryDesc = CreateQueryDesc(query, plan,
201210
ActiveSnapshot, InvalidSnapshot,

src/backend/commands/prepare.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2002-2005, PostgreSQL Global Development Group
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.41 2005/10/15 02:49:15 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.42 2005/10/21 16:43:33 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -605,6 +605,15 @@ ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate)
605605
query->into = execstmt->into;
606606
}
607607

608+
/*
609+
* Update snapshot command ID to ensure this query sees results of
610+
* any previously executed queries. (It's a bit cheesy to modify
611+
* ActiveSnapshot without making a copy, but for the limited ways
612+
* in which EXPLAIN can be invoked, I think it's OK, because the
613+
* active snapshot shouldn't be shared with anything else anyway.)
614+
*/
615+
ActiveSnapshot->curcid = GetCurrentCommandId();
616+
608617
/* Create a QueryDesc requesting no output */
609618
qdesc = CreateQueryDesc(query, plan,
610619
ActiveSnapshot, InvalidSnapshot,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy