Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VtSTc-00046a-E3 for pgsql-performance@arkaria.postgresql.org; Thu, 19 Dec 2013 01:32:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VtSTb-0005Cm-ML for pgsql-performance@arkaria.postgresql.org; Thu, 19 Dec 2013 01:32:35 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VtSTZ-0005Cd-FS for pgsql-performance@postgresql.org; Thu, 19 Dec 2013 01:32:33 +0000 Received: from kilimanjaro.scorpionshops.com ([82.118.24.202]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VtSTV-0000Hw-Mk for pgsql-performance@postgresql.org; Thu, 19 Dec 2013 01:32:32 +0000 Received: from [92.32.205.123] (92-32-205-123.tn.glocalnet.net [92.32.205.123]) by kilimanjaro.scorpionshops.com (Postfix) with ESMTPSA id 2DAC37BC1DD; Thu, 19 Dec 2013 02:32:28 +0100 (CET) Message-ID: <52B24CB6.6060507@proxel.se> Date: Thu, 19 Dec 2013 02:32:38 +0100 From: Andreas Karlsson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131005 Icedove/17.0.9 MIME-Version: 1.0 To: Krzysztof Olszewski CC: pgsql-performance@postgresql.org Subject: Re: Problem with slow query with WHERE conditions with OR clause on primary keys References: <52A7A428.8070104@gmail.com> In-Reply-To: <52A7A428.8070104@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org 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