pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: JmH <jason.height@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Good/Bad query plans based on text criteria
Date: Wed, 14 Apr 2010 22:42:21 -0400
Message-ID: <21178.1271299341@sss.pgh.pa.us> (raw)
In-Reply-To: <q2naba242eb1004141845je43ba462of5fddfaa8b03d426@mail.gmail.com>
References: <q2naba242eb1004141845je43ba462of5fddfaa8b03d426@mail.gmail.com>

JmH <jason.height@gmail.com> 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



view thread (2+ messages)

Message-ID: <21178.1271299341@sss.pgh.pa.us>
Permalink:  ../21178.1271299341@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21178.1271299341@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, jason.height@gmail.com
  Subject: Re: Good/Bad query plans based on text criteria
  In-Reply-To: <21178.1271299341@sss.pgh.pa.us>

* 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