Re: index on numbers not honoured

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Risko Peter <rpetike(at)freemail(dot)hu>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: index on numbers not honoured
Date: 2001-11-16 16:38:13
Message-ID: 20011116083509.J18816-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 16 Nov 2001, Risko Peter wrote:

> On Thu, 15 Nov 2001, Ilker Egilmez wrote:
> > hi risko,
> > try to create your table, then create your index and then insert your values.
> > this time the index will be used - very strange!
> > ilker -)
> I summed it:
>
> show enable_seqscan;
> show enable_indexscan;
> drop index i;
> drop table test;
> create table test(a int4);
> create index i on test(a);
> copy test from stdin;
> 65
> 87
> 23
> \.
> explain select * from test where a=87;
> drop index i;
> explain select * from test where a=87;
> create index i on test (a);
> explain select * from test where a=87;
>
> I experienced it too, first indexed, but then seqscan and seqscan again.
> I think it is because the query optimizer. I advise you to control
> manually in these cases the behavior of it by setting the enable_seqscan
> variable (I often do it :).

Well, you're going to need a vacuum analyze in there between the copy
and first select to get something meaningful. The reason it probably uses
an index on the first one is that the default statistics will choose that.
However, that is almost certainly the *wrong* plan for all three of those
queries. Choosing from a table that's one page should almost certainly
use sequence scan and choosing one row of three should in most cases
as well (see past discussions for details)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2001-11-16 16:48:14 Re: Precision problems with float8
Previous Message Gabriel Fernandez 2001-11-16 16:31:49 Re: Precision problems with float8