From b2c4071299e02ed96d48d3c8e776de2fab36f88c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 13 Sep 2004 20:10:13 +0000 Subject: 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. --- src/backend/commands/explain.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/backend/commands/explain.c') diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index 9b7cf1ae491..f51b991b4d0 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -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); -- cgit v1.2.3