Re: Problem with slow query with WHERE conditions with OR clause on primary keys

From: Andreas Karlsson <andreas(at)proxel(dot)se>
To: Krzysztof Olszewski <kolszew73(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Problem with slow query with WHERE conditions with OR clause on primary keys
Date: 2013-12-19 01:32:38
Message-ID: 52B24CB6.6060507@proxel.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 12/11/2013 12:30 AM, Krzysztof Olszewski wrote:
> select g.gd_index, gd.full_name
> from gd g join gd_data gd on (g.id_gd = gd.id_gd)
> where gd.id_gd_data = 1111 OR g.id_gd = 1111;

Have you tried writing the query to filter on gd.id_gd rather than
g.id_gd? I am not sure if the query planner will realize that it can
replace g.id_gd with gd.id_gd in the where clause.

select g.gd_index, gd.full_name
from gd g join gd_data gd on (g.id_gd = gd.id_gd)
where gd.id_gd_data = 1111 OR gd.id_gd = 1111;

--
Andreas Karlsson

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Johann Spies 2013-12-19 13:06:21 query not using index
Previous Message David Johnston 2013-12-18 20:12:29 Re: Problem with slow query with WHERE conditions with OR clause on primary keys