Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 3D2A2632757 for ; Wed, 14 Apr 2010 23:42:36 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 24185-03 for ; Thu, 15 Apr 2010 02:42:15 +0000 (UTC) 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 7620F6323EB for ; Wed, 14 Apr 2010 23:42:23 -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 o3F2gLO7021179; Wed, 14 Apr 2010 22:42:21 -0400 (EDT) To: JmH cc: pgsql-performance@postgresql.org Subject: Re: Good/Bad query plans based on text criteria In-reply-to: References: Comments: In-reply-to JmH message dated "Thu, 15 Apr 2010 11:15:45 +0930" Date: Wed, 14 Apr 2010 22:42:21 -0400 Message-ID: <21178.1271299341@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.169 tagged_above=-10 required=5 tests=AWL=-1.158, BAYES_20=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201004/181 X-Sequence-Number: 38431 JmH writes: > I am struggling to understand why for certain criteria that i supply for a > query alters the the query plan. In my "good" case i can see that an index > is used, in my bad case where i only change the text value of the criteria, > but not the criteria itslef (ie change/add the conditions) a hbitmap heap > scan of the table is performed. I think you're jumping to conclusions. The second plan is processing about 100 times as many rows, because the WHERE conditions are much less selective. A change in plan is entirely appropriate. It might be that you need to change planner parameters (particularly random_page_cost/seq_page_cost) to more nearly approximate the operating conditions of your database, but I'd recommend being very cautious about doing so on the basis of a small number of example queries. In particular it's easy to fall into the trap of optimizing for fully-cached scenarios because repeatedly trying the same example results in touching only already-cached data --- but that might or might not be reflective of your whole workload. regards, tom lane