Re: hashed subplan 5000x slower than two sequential operations

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

 



2010/12/8 Tom Lane <tgl@xxxxxxxxxxxxx>:
> Shrirang Chitnis <Shrirang.Chitnis@xxxxxxxxxxxxxxx> writes:
>> Bryce,
>> The two queries are different:
>
> I suspect the second one is a typo and not what he really wanted.
>
>> WHERE (contexts.parent_key = 392210
>> Â Â Â OR contexts.context_key IN
>> Â Â Â Â Â(SELECT collection_data.context_key
>> Â Â Â Â ÂFROM collection_data
>> Â Â Â Â Â WHERE collection_data.collection_context_key = 392210)
>
> The only really effective way the planner knows to optimize an
> "IN (sub-SELECT)" is to turn it into a semi-join, which is not possible
> here because of the unrelated OR clause. ÂYou might consider replacing
> this with a UNION of two scans of "contexts". Â(And yes, I know it'd be
> nicer if the planner did that for you.)

I remeber a similar case - 9 years ago.

slow variant:

WHERE pk = C1 OR pk IN (SELECT .. FROM .. WHERE some = C2)

I had to rewrite to form

WHERE pk IN (SELECT .. FROM WHERE some = C2 UNION ALL SELECT C1)

Regards

Pavel Stehule


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

-- 
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