Re: Rewrite, normal execution vs. EXPLAIN ANALYZE - Mailing list pgsql-hackers

From Marko Tiikkaja
Subject Re: Rewrite, normal execution vs. EXPLAIN ANALYZE
Date
Msg-id 4C49EB59.9090308@cs.helsinki.fi
Whole thread Raw
In response to Re: Rewrite, normal execution vs. EXPLAIN ANALYZE  (Marko Tiikkaja <marko.tiikkaja@cs.helsinki.fi>)
Responses Re: Rewrite, normal execution vs. EXPLAIN ANALYZE
List 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


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: reminder... beta4 is coming
Next
From: Robert Haas
Date:
Subject: Re: Rewrite, normal execution vs. EXPLAIN ANALYZE