Re: 2 left joins causes seqscan

From: Willy-Bas Loos <willybas(at)gmail(dot)com>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: 2 left joins causes seqscan
Date: 2014-09-16 16:38:51
Message-ID: CAHnozTg28OBHrGL=KvAcjFYL7YQsuXqfKWhMnG0Nub8Cqz-wPg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Sep 12, 2014 at 11:11 PM, Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:

>
> The equivalent of your first query is to take the result sets from
> these two queries:
>
> select a1.field1, b1.title, b2.title
> from a a1
> join b b1 on b1.id = a1.id and b1.lang = 1
> left join b b2 on (b2.id = a1.id and b2.lang = 2)
> where lower(b1.title) like'abcd%'
> union
> select a2.field1, b4.title, b3.title
> from a a2
> join b b3 on b3.id = a2.id and b3.lang = 2
> left join b b4 on (b4.id = a2.id and b4.lang = 1)
> where lower(b3.title) like'abcd%';
>
>
Thanks for that query, it really helps.

Cheers,

--
Willy-Bas Loos

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Paquier 2014-09-16 17:04:21 Re: Sequences in foreign tables
Previous Message Pavel Stehule 2014-09-16 15:43:08 Re: pg_dump does not include database-level user-defined GUC variables?