pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Karlsson <andreas@proxel.se>
To: Krzysztof Olszewski <kolszew73@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Problem with slow query with WHERE conditions with OR clause on primary keys
Date: Thu, 19 Dec 2013 02:32:38 +0100
Message-ID: <52B24CB6.6060507@proxel.se> (raw)
In-Reply-To: <52A7A428.8070104@gmail.com>
References: <52A7A428.8070104@gmail.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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


-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance



view thread (6+ messages)  latest in thread

Message-ID: <52B24CB6.6060507@proxel.se>
Permalink:  ../52B24CB6.6060507@proxel.se/
Also on:    postgresql.org/message-id/52B24CB6.6060507@proxel.se

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: andreas@proxel.se, kolszew73@gmail.com
  Subject: Re: Problem with slow query with WHERE conditions with OR clause on primary keys
  In-Reply-To: <52B24CB6.6060507@proxel.se>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox