Re: query plan not optimal

From: Marc Cousin <cousinmarc(at)gmail(dot)com>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: query plan not optimal
Date: 2013-12-20 06:05:35
Message-ID: 52B3DE2F.10203@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 19/12/2013 21:36, Kevin Grittner wrote:
> Marc Cousin <cousinmarc(at)gmail(dot)com> wrote:
>
>> Then we insert missing paths. This is one of the plans that fail
>> insert into path (path)
>> select path from batch
>> where not exists
>> (select 1 from path where path.path=batch.path)
>> group by path;
> I know you said you wanted to focus on a different query, but this
> one can easily be optimized. Right now it is checking for an
> existing row in path for each row in batch; and it only needs to
> check once for each path. One way to write it would be:
>
> insert into path (path)
> select path from (select distinct path from batch) b
> where not exists
> (select 1 from path p where p.path = b.path);
Yeah, I know, that's why I said I didn't want to focus on this one… we
already do this optimization :)

Thanks anyway :)

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Shaun Thomas 2013-12-20 14:10:32 Re: Unexpected pgbench result
Previous Message Scott Marlowe 2013-12-20 00:37:19 Re: Regarding Hardware Tuning