Re: Allowing join removals for more join types

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Dilip kumar <dilip(dot)kumar(at)huawei(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Allowing join removals for more join types
Date: 2014-05-21 10:11:03
Message-ID: CAApHDvoCcgN4jK_wsJXoM9SZEGK2ZH7ywjO6jQX0hz=3HW5OBg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, May 20, 2014 at 11:22 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> David Rowley <dgrowleyml(at)gmail(dot)com> writes:
> > I'm also now wondering if I need to do some extra tests in the existing
> > code to ensure that the subquery would have had no side affects.
>
> You should probably at least refuse the optimization if the subquery's
> tlist contains volatile functions.
>
> Functions that return sets might be problematic too [ experiments... ]
> Yeah, they are. This behavior is actually a bit odd:
>
>
...

>
> regression=# select q1,unnest(array[1,2]) as u from int8_tbl group by 1;
> q1 | u
> ------------------+---
> 4567890123456789 | 1
> 4567890123456789 | 2
> 123 | 1
> 123 | 2
> (4 rows)
>
> EXPLAIN shows that the reason the last case behaves like that is that
> the SRF is expanded *after* the grouping step. I'm not entirely sure if
> that's a bug --- given the lack of complaints, perhaps not. But it shows
> you can't apply this optimization without changing the existing behavior.
>
> I doubt you should drop a subquery containing FOR UPDATE, either.
> That's a side effect, just as much as a volatile function would be.
>
> regards, tom lane
>

Yeah that is strange indeed.
I've made some updates to the patch to add some extra checks for any
volatile functions in the target list and set returning functions.
The FOR UPDATE currently does not really need an explicit check as I'm
currently only supporting removals of sub queries that have either GROUP BY
or DISTINCT clauses, none of which allow FOR UPDATE anyway.

Regards

David Rowley

Attachment Content-Type Size
subquery_leftjoin_removal_v0.6.patch application/octet-stream 16.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2014-05-21 11:29:53 replication protocol documentation inconsistencies
Previous Message Michael Paquier 2014-05-21 06:33:16 Re: 9.4 checksum error in recovery with btree index