Re: Rewrite, normal execution vs. EXPLAIN ANALYZE

From: Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: David Fetter <david(at)fetter(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Rewrite, normal execution vs. EXPLAIN ANALYZE
Date: 2010-07-23 19:19:53
Message-ID: 4C49EB59.9090308@cs.helsinki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2010-07-23 19:30:03 Re: Rewrite, normal execution vs. EXPLAIN ANALYZE
Previous Message Robert Haas 2010-07-23 19:12:06 reminder... beta4 is coming