pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David G Johnston <david.g.johnston@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Re: Slow query with indexed ORDER BY and LIMIT when using OR'd conditions
Date: Mon, 21 Jul 2014 14:54:11 -0700 (PDT)
Message-ID: <1405979651518-5812289.post@n5.nabble.com> (raw)
In-Reply-To: <CACuOPqBc7kKiv4JjqQwEJO1PG7iN5XByt9-b9Di2i69k+SV5dA@mail.gmail.com>
References: <CACuOPqC9h6vK5rniezSOm2fu44PNp0NrB8kdtapT=xqNzQgidA@mail.gmail.com>
	<1405978279538-5812285.post@n5.nabble.com>
	<CACuOPqBc7kKiv4JjqQwEJO1PG7iN5XByt9-b9Di2i69k+SV5dA@mail.gmail.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

johno wrote
> Thanks for the quick reply David!
> 
> However I am still unsure how these two queries are not relationally
> equivalent. I am struggling to find a counterexample where the first and
> third query (in email, not in gist) would yield different results. Any
> ideas?

Remove the outer LIMIT 100 from both queries...

The first query would return a maximal number of rows that meet the OR
criteria while the second query would return at most 200 rows since both
sub-queries would still have their own independent LIMIT 100 clauses.

David J.




--
View this message in context: http://postgresql.1045698.n5.nabble.com/Slow-query-with-indexed-ORDER-BY-and-LIMIT-when-using-OR-d-c...
Sent from the PostgreSQL - performance mailing list archive at Nabble.com.


-- 
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 (11+ messages)  latest in thread

Message-ID: <1405979651518-5812289.post@n5.nabble.com>
Permalink:  ../1405979651518-5812289.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1405979651518-5812289.post@n5.nabble.com

 · 

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: david.g.johnston@gmail.com
  Subject: Re: Slow query with indexed ORDER BY and LIMIT when using OR'd conditions
  In-Reply-To: <1405979651518-5812289.post@n5.nabble.com>

* 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