Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 675DA9FB1DD for ; Sat, 28 Jul 2007 17:44:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 12764-08 for ; Sat, 28 Jul 2007 17:44:02 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from pillette.com (adsl-67-119-5-202.dsl.snfc21.pacbell.net [67.119.5.202]) by postgresql.org (Postfix) with ESMTP id 5B5699FB1CC for ; Sat, 28 Jul 2007 17:44:02 -0300 (ADT) Received: (from andrew@localhost) by pillette.com (8.11.6/8.11.6) id l6SKhwP08503; Sat, 28 Jul 2007 13:43:58 -0700 Date: Sat, 28 Jul 2007 13:43:58 -0700 From: andrew@pillette.com Message-Id: <200707282043.l6SKhwP08503@pillette.com> Subject: Re: Slow query with backwards index scan To: Tilmann Singer Cc: andrew@pillette.com, pgsql-performance@postgresql.org X-Originating-IP: 71.135.78.238 X-Mailer: Webmin 0.940 MIME-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.983 tagged_above=0 required=5 tests=AWL=-0.788, BAYES_50=0.001, FH_HOST_EQ_PACBELL_D=1.67, RDNS_DYNAMIC=0.1 X-Spam-Level: Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Archive-Number: 200707/404 X-Sequence-Number: 26088 As other posters have pointed out, you can overcome the ORDER BY/LIMIT restriction on UNIONs with parentheses. I think I misbalanced the parentheses in my original post, which would have caused an error if you just copied and pasted. I don't think the limitation has to do with planning--just parsing the query.