Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X9LXK-0001cF-Jp for pgsql-performance@arkaria.postgresql.org; Mon, 21 Jul 2014 21:54:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X9LXK-0004qE-2N for pgsql-performance@arkaria.postgresql.org; Mon, 21 Jul 2014 21:54:22 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X9LXI-0004nB-1r for pgsql-performance@postgresql.org; Mon, 21 Jul 2014 21:54:20 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1X9LXA-0000Bz-N9 for pgsql-performance@postgresql.org; Mon, 21 Jul 2014 21:54:18 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1X9LX9-0006hh-H0 for pgsql-performance@postgresql.org; Mon, 21 Jul 2014 14:54:11 -0700 Date: Mon, 21 Jul 2014 14:54:11 -0700 (PDT) From: David G Johnston To: pgsql-performance@postgresql.org Message-ID: <1405979651518-5812289.post@n5.nabble.com> In-Reply-To: References: <1405978279538-5812285.post@n5.nabble.com> Subject: Re: Slow query with indexed ORDER BY and LIMIT when using OR'd conditions MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 3.5 (+++) 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 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-conditions-tp5812282p5812289.html 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