Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 0B3D3633909 for ; Thu, 9 Jul 2009 15:29:12 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 05504-01 for ; Thu, 9 Jul 2009 15:28:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 4DF1C6335B0 for ; Thu, 9 Jul 2009 15:29:01 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id n69ISxaZ004290; Thu, 9 Jul 2009 14:28:59 -0400 (EDT) To: jacob@aers.ca cc: pgsql-sql@postgresql.org Subject: Re: FW: Query length limitation in postgres server > 8.2.9 In-reply-to: <6B5AF6293A289F45826220B17ABE7937FDB1CB@BORON.aers.local> References: <6B5AF6293A289F45826220B17ABE7937FDB16C@BORON.aers.local> <6B5AF6293A289F45826220B17ABE7937FDB1C0@BORON.aers.local> <3795.1247162732@sss.pgh.pa.us> <6B5AF6293A289F45826220B17ABE7937FDB1C6@BORON.aers.local> <3981.1247163226@sss.pgh.pa.us> <6B5AF6293A289F45826220B17ABE7937FDB1CB@BORON.aers.local> Comments: In-reply-to message dated "Thu, 09 Jul 2009 11:16:26 -0700" Date: Thu, 09 Jul 2009 14:28:59 -0400 Message-ID: <4289.1247164139@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.081 tagged_above=0 required=5 tests=AWL=0.081 X-Spam-Level: X-Archive-Number: 200907/47 X-Sequence-Number: 32788 writes: > leaf_category_1 Ah. So you are wishing it would use this index: "search_site1_2009_03_13_leaf_category_1" btree (leaf_category_1, site_id) WHERE leaf_category_1 IS NOT NULL If I were you I'd drop the WHERE clause, which is eliminating no index entries whatsoever (since the column is actually declared not null). What it is doing is forcing the planner to expend many cycles proving that the query's WHERE clause requires leaf_category_1 to be non-null hence the index is potentially usable. The reason recent releases are giving you trouble is that we put a limit on how many cycles we'd expend on such silliness. If you really don't want to change the schema, you could work around the issue by adding a separate "leaf_category_1 IS NOT NULL" test to the query, so that the planner can prove the index is relevant without having to grovel through hundreds of IN-list items to do it. In general, this table schema looks like somebody has drastically overengineered the index definitions with rather little understanding of what they were doing or what the performance consequences would be. I hope the table is read-mostly, because you're paying a *lot* anytime you update those indexes. regards, tom lane