Re: Rewrite, normal execution vs. EXPLAIN ANALYZE

Marko Tiikkaja <marko.tiikkaja@cs.helsinki.fi>

From: Marko Tiikkaja <marko.tiikkaja@cs.helsinki.fi>
To: Robert Haas <robertmhaas@gmail.com>
Cc: David Fetter <david@fetter.org>, pgsql-hackers@postgresql.org
Date: 2010-07-23T19:19:53Z
Lists: pgsql-hackers
On 7/23/2010 10:06 PM, I wrote:
> ProcessQuery() and ExplainOnePlan().  ProcessQuery calls
> PushActiveSnapshot(GetTransactionSnapshot()) for every statement while
> ExplainOnePlan calls PushUpdatedSnapshot(GetActiveSnapshot()).

Here's a test case demonstrating the difference:

=# create table foo(a int);
CREATE TABLE
=# create table bar(a int);
CREATE TABLE
=# create table baz(a int);
CREATE TABLE

=# create rule foorule as on update to foo do instead (select 
pg_sleep(5); insert into bar select * from baz);
CREATE RULE

=# insert into foo values(0);


no EXPLAIN:

=# truncate bar, baz;
TRUNCATE TABLE

T1=# begin; update foo set a=a;
BEGIN
-- sleeps..

T2=# insert into baz values(0);
INSERT 0 1

-- T1 returns
  pg_sleep
----------

(1 row)

UPDATE 0

T1=# select * from bar;
  a
---
  0
(1 row)



EXPLAIN:

=# truncate bar, baz;
TRUNCATE TABLE

T1=# begin; explain analyze update foo set a=a;
BEGIN
-- sleeps..

T2=# insert into baz values(0);
INSERT 0 1

-- T1 returns
(QUERY PLAN)

T1=# select * from bar;
  a
---
(0 rows)


This may be a bit hard to follow, but essentially what happens is that 
in EXPLAIN ANALYZE, the INSERT in the rule does not see the changes made 
by T2 to baz while in the regular execution scenario it does.


Regards,
Marko Tiikkaja