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

From: Nikolas Everett <nik9000(at)gmail(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 15:54:13
Message-ID: d4e11e981002030754id1e3b2em7fa3e7a7ac0daef3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Tue, Feb 2, 2010 at 7:14 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> "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?)
>
> regards, tom lane

If you don't have a constant expression then you can either explicitly loop
in the calling code or a function or you could index the key in all the
subtables. The index isn't really optimal but it gets the job done.

Nik

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Віталій Тимчишин 2010-02-03 16:10:46 Re: Queries within a function
Previous Message Leo Mannhart 2010-02-03 15:16:30 Re: some problems when i use postgresql 8.4.2 in my projects .