From: Tom Lane <tgl@sss.pgh.pa.us>
To: johno <jan.suchal@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Slow query with indexed ORDER BY and LIMIT when using OR'd conditions
Date: Tue, 22 Jul 2014 02:15:29 -0400
Message-ID: <11612.1406009729@sss.pgh.pa.us> (raw)
In-Reply-To: <CACuOPqCHEAK93Q5LqfdC6EDqfP57=S2pq68Gn4=S3B1usz-GUA@mail.gmail.com>
References: <CACuOPqC9h6vK5rniezSOm2fu44PNp0NrB8kdtapT=xqNzQgidA@mail.gmail.com>
<4381.1405997581@sss.pgh.pa.us>
<CACuOPqCHEAK93Q5LqfdC6EDqfP57=S2pq68Gn4=S3B1usz-GUA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>
johno <jan.suchal@gmail.com> writes:
> On Tue, Jul 22, 2014 at 4:53 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> johno <jan.suchal@gmail.com> writes:
>>> The obvious query is
>>> SELECT * FROM register_uz_accounting_entities
>>> WHERE effective_on > '2014-07-11' OR (effective_on = '2014-07-11' AND
>>> id > 1459)
>>> ORDER BY effective_on, id
>>> LIMIT 100
>> A more readily optimizable query is
>> SELECT * FROM register_uz_accounting_entities
>> WHERE (effective_on, id) > ('2014-07-11'::date, 1459)
>> ORDER BY effective_on, id
>> LIMIT 100
> Yes, but that query has completely different semantics - I can't change
> that.
No, it doesn't. Read it again ... or read up on row comparisons,
if you're unfamiliar with that notation. The above queries are
exactly equivalent per spec.
regards, tom lane
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
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: tgl@sss.pgh.pa.us, jan.suchal@gmail.com
Subject: Re: Slow query with indexed ORDER BY and LIMIT when using OR'd conditions
In-Reply-To: <11612.1406009729@sss.pgh.pa.us>
* 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