Re: queries with subquery constraints on partitioned tables not optimized?

From: Dimitri Fontaine <dfontaine(at)hi-media(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Davor J(dot)" <DavorJ(at)live(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: queries with subquery constraints on partitioned tables not optimized?
Date: 2010-02-03 10:23:58
Message-ID: 87k4uuty69.fsf@hi-media-techno.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> "Davor J." <DavorJ(at)live(dot)com> writes:
>> Now, if one takes a subquery for "1", the optimizer evaluates it first
>> (let's say to "1"), but then searches for it (sequentially) in every
>> partition, which, for large partitions, can be very time-consuming and goes
>> beyond the point of partitioning.
>
> No, the optimizer doesn't "evaluate it first". Subqueries aren't ever
> assumed to reduce to constants. (If you actually do have a constant
> expression, why don't you just leave out the word SELECT?)

It's easy to experience the same problem with a JOIN you'd want to
happen at the partition level that the planner will apply on the Append
Node.

I'm yet to figure out if 8.4 is smarter about this, meanwhile I'm using
array tricks to force the push-down.

WHERE ...
AND service = ANY ((SELECT array_accum(id) FROM services WHERE x=281)
|| (SELECT array_accum(id) FROM services WHERE y=281))

It happens that I need the array concatenation more than the = ANY
operator (as compared to IN), so I also have queries using = ANY
('{}':int[] || (SELECT array_accum(x) ...)) to really force the planner
into doing the join in the partitions rather than after the Append has
taken place.

Regards,
--
dim

PS: If you're interrested into complete examples, I'll be able to
provide for them in private.

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Matthew Wakeling 2010-02-03 11:30:53 Re: System overload / context switching / oom, 8.3
Previous Message J Sisson 2010-02-03 08:31:30 Re: the jokes for pg concurrency write performance