From: | David Rowley <david(dot)rowley(at)2ndquadrant(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Performance improvement for joins where outer side is unique |
Date: | 2017-02-01 11:05:33 |
Message-ID: | CAKJS1f-8ExyTWbGsBQw4b8MTrk73YoLKvXW_pFeZMTAdPX4UxA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 31 January 2017 at 10:43, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> David Rowley <david(dot)rowley(at)2ndquadrant(dot)com> writes:
>> I don't think that's possible. The whole point that the current join
>> removal code retries to remove joins which it already tried to remove,
>> after a successful removal is exactly because it is possible for a
>> join to become provability unique on the removal of another join.
>
> Not seeing that ... example please?
I had a quick look at this again as it had been a while since I noticed that.
The sample case was:
create temp table uniquetbl (f1 text unique);
explain (costs off)
select t1.* from
uniquetbl as t1
left join (select *, '***'::text as d1 from uniquetbl) t2
on t1.f1 = t2.f1
left join uniquetbl t3
on t2.d1 = t3.f1;
However, what it actually fails on depends on if you check for unused
columns or uniqueness first as initially the subquery fails both of
the tests.
I was under the impression it was failing the unique test, as that's
what I was doing first in my patch.
If you test uniqueness first it'll fail on:
/*
* If such a clause actually references the inner rel then join
* removal has to be disallowed. We have to check this despite
* the previous attr_needed checks because of the possibility of
* pushed-down clauses referencing the rel.
*/
if (bms_is_member(innerrelid, restrictinfo->clause_relids))
return false;
but if you test for unused columns first, it'll fail on:
if (bms_is_subset(phinfo->ph_eval_at, innerrel->relids))
return false; /* there isn't any other place to eval PHV */
--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
From | Date | Subject | |
---|---|---|---|
Next Message | Konstantin Knizhnik | 2017-02-01 11:07:56 | Re: Deadlock in XLogInsert at AIX |
Previous Message | Ashutosh Bapat | 2017-02-01 10:29:16 | Re: [Bug fix] PQsendQuery occurs error when target_session_attrs is set to read-write |