pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Wille <a2om6sy02@sneakemail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Query planner plans very inefficient plans
Date: Mon, 30 Jun 2003 15:05:26 -0400
Message-ID: <16644.1056999926@sss.pgh.pa.us> (raw)
In-Reply-To: <032101c33f31$0d239910$2264a8c0@zucchini>
References: <032101c33f31$0d239910$2264a8c0@zucchini>

"Robert Wille" <a2om6sy02@sneakemail.com> writes:
> select * from image natural join ancestry where ancestorid=1000000 and
> (state & 7::bigint) = 0::bigint;

The planner is not going to have any statistics that allow it to predict
the number of rows satisfying that &-condition, and so it's unsurprising
if its off-the-cuff guess has little to do with reality.

I'd recommend skipping any cute tricks with bit-packing, and storing the
state (and any other values you query frequently) as its own column, so
that the query looks like 

select * from image natural join ancestry where ancestorid=1000000 and
state = 0;

ANALYZE should be able to do a reasonable job with a column that has 8
or fewer distinct values ...

			regards, tom lane



view thread (3+ messages)  latest in thread

Message-ID: <16644.1056999926@sss.pgh.pa.us>
Permalink:  ../16644.1056999926@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16644.1056999926@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, a2om6sy02@sneakemail.com
  Subject: Re: Query planner plans very inefficient plans
  In-Reply-To: <16644.1056999926@sss.pgh.pa.us>
  References: <032101c33f31$0d239910$2264a8c0@zucchini> <16644.1056999926@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