pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mark Halliwell <mark@transportservices.com.au>
Cc: pgsql-performance@postgresql.org
Subject: Re: Query not using the index
Date: Tue, 25 Feb 2003 10:13:26 -0500
Message-ID: <10478.1046186006@sss.pgh.pa.us> (raw)
In-Reply-To: <200302251903.40364.mark@transportservices.com.au>
References: <200302251903.40364.mark@transportservices.com.au>

Mark Halliwell <mark@transportservices.com.au> writes:
> The majority of records (about 6.8 million) have computer = 8 with sequence 
> starting at 2200000 and incrementing by 1.
> There are about 497000 records with computer = 3 with the sequence starting at 
> 1 and also incrementing by 1.
> There are only a few records with other computer numbers.

You aren't going to find any non-kluge solution, because Postgres keeps
no cross-column statistics and thus is quite unaware that there's any
correlation between the computer and sequence fields.  So in a query
like

> select * from replicate where computer = 3 and sequence >= 490000;

the sequence constraint looks extremely unselective to the planner, and
you get a seqscan, even though *in the domain of computer = 3* it's a
reasonably selective constraint.

> that if a specify an upper limit for sequence (a value which I cannot always 
> easily predict), it also uses the index.

I would think that it'd be sufficient to say

  select * from replicate where computer = 3 and sequence >= 490000
  and sequence < 2200000;

If it's not, try increasing the statistics target for the sequence
column so that ANALYZE gathers a finer-grain histogram for that column.

			regards, tom lane



view thread (4+ messages)

Message-ID: <10478.1046186006@sss.pgh.pa.us>
Permalink:  ../10478.1046186006@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/10478.1046186006@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, mark@transportservices.com.au
  Subject: Re: Query not using the index
  In-Reply-To: <10478.1046186006@sss.pgh.pa.us>
  References: <200302251903.40364.mark@transportservices.com.au> <10478.1046186006@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