Re: Ok, why isn't it using *this* index?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Paul Tomblin <ptomblin(at)xcski(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Ok, why isn't it using *this* index?
Date: 2001-04-01 23:01:48
Message-ID: 2670.986166108@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Paul Tomblin <ptomblin(at)xcski(dot)com> writes:
> Ok, so if I understand you correctly, the fact that about 90% of the
> records have country='USA' and about 9% of the records have
> country='CANADA' means that it's never going to use the index because it
> on average, a query is going to be for USA, and a sequential scan is going
> to be better.

Actually, 7.0 and later (which you are not using, I gather from your
EXPLAIN display) do know the difference between the most common value
in the column and the rest of 'em. I think that 7.0 would choose an
indexscan in the case where it can see that you are not looking for
'USA'. Which would be the right choice for 'BELIZE', but probably
not the right choice for 'CANADA'.

For 7.2 I am hoping to extend the stored stats to know about the top
three or so common values, not just one, so that we can deal more
effectively with data distributions like this one. But in any case,
most of the respondents in this thread have been assuming that you
were running a reasonably current Postgres. Try upgrading ...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-04-01 23:02:45 Re: Can I get the default value for an attribute (field) ?
Previous Message Joel Burton 2001-04-01 22:55:16 Re: Can I get the default value for an attribute (field) ?