Re: Why is it not using an index?

From: Jean-Luc Lachance <jllachan(at)nsd(dot)ca>
To: Gregory Wood <gregw(at)com-stock(dot)com>
Cc: Dmitry Tkach <dmitry(at)openratings(dot)com>, PostgreSQL-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why is it not using an index?
Date: 2002-03-15 20:25:47
Message-ID: 3C9258CB.B22E190A@nsd.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Really, the PostgreSQL interpreter should be smart enough to figure this
out by itself...

Gregory Wood wrote:
>
> > explain select * from a where x=3;
>
> PostgreSQL is treating 3 as an int4 (integer) type, whereas x is an int2
> (smallint) type. Try casting the constant as a smallint and it should use
> the index:
>
> explain select * from a where x=3::smallint;
>
> Greg
>
> ----- Original Message -----
> From: "Dmitry Tkach" <dmitry(at)openratings(dot)com>
> To: <pgsql-general(at)postgresql(dot)org(dot)pgsql-sql@postgresql.org>
> Sent: Friday, March 15, 2002 2:07 PM
> Subject: [GENERAL] Why is it not using an index?
>
> > This must be really simple, but I just can't get it :-(
> > I have a table (a) with a single column (x):
> >
> > Table "a"
> > Attribute | Type | Modifier
> > -----------+----------+----------
> > x | smallint |
> > Index: a_idx
> >
> >
> > Index "a_idx"
> > Attribute | Type
> > -----------+----------
> > x | smallint
> > btree
> >
> > The table has 10000000 rows....
> >
> > Now, how come, when I do:
> >
> > explain select * from a where x=3;
> >
> > it says:
> >
> > Seq Scan on bset (cost=100000000.00..100175934.05 rows=303 width=2)
> >
> > Why is it not using a_idx???
> >
> > I even tried set enable_seqscan to off - makes no difference :-(
> >
> > Any idea what is going on?
> >
> > Thanks a lot!
> >
> > Dima
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 5: Have you checked our extensive FAQ?
> >
> > http://www.postgresql.org/users-lounge/docs/faq.html
> >
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Wood 2002-03-15 20:34:46 Re: Why is it not using an index?
Previous Message Stephan Szabo 2002-03-15 20:12:14 Re: Why is it not using an index?

Browse pgsql-sql by date

  From Date Subject
Next Message Gregory Wood 2002-03-15 20:34:46 Re: Why is it not using an index?
Previous Message Stephan Szabo 2002-03-15 20:12:14 Re: Why is it not using an index?