Re: query plan not optimal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19/12/2013 21:36, Kevin Grittner wrote:
Marc Cousin <cousinmarc@xxxxxxxxx> 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 :)


--
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance




[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux