Re: tricking EXPLAIN?

From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: Wim Bertels <wim(dot)bertels(at)khleuven(dot)be>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: tricking EXPLAIN?
Date: 2011-11-28 12:00:22
Message-ID: CAFjNrYuAgsy0+zzjzYZH0=9-qnUn4CL4HVajQSk2rDp35DbT1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 28 November 2011 12:55, Wim Bertels <wim(dot)bertels(at)khleuven(dot)be> wrote:

> Hallo,
>
> if u compare the 2 queries, then they should be equivalent:
>
> -- normal
> -- EXPLAIN ANALYZE
> SELECT amproc, amprocnum - average AS difference
> FROM pg_amproc,
> (SELECT avg(amprocnum) AS average
> FROM pg_amproc) AS tmp;
>
> -- trying to trick explain with a redundant join
> -- EXPLAIN ANALYZE
> SELECT amproc, amprocnum - average AS difference
> FROM pg_amproc INNER JOIN
> (SELECT avg(amprocnum) AS average
> FROM pg_amproc) AS tmp
> ON pg_amproc.amproc = pg_amproc.amproc;
>
>
> If we look at the output of EXPLAIN ANALYZE,
> then according to the COST the second query is best one,
> but according to the ACTUAL TIME the first query is best
> (which seems logical intuitively).
>
> So explain is being tricked,
> and the reason for this seems the number of rows in de nested loop,
> which are reduced to 1 for explain because of the join.
> http://www.postgresql.org/docs/8.4/static/using-explain.html
>
> Suggestions, comments are always welcome.
>
> mvg,
> Wim Bertels
>
>
>
>
Hi,
could you show us the output of explain analyze?

regards
Szymon

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Wim Bertels 2011-11-28 12:06:01 Re: tricking EXPLAIN?
Previous Message Wim Bertels 2011-11-28 11:55:54 tricking EXPLAIN?