Thread: Why is it not using an index?

Why is it not using an index?

From
Dmitry Tkach
Date:
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


Re: Why is it not using an index? (small correction)

From
Dmitry Tkach
Date:
>
> Seq Scan on bset  (cost=100000000.00..100175934.05 rows=303 width=2)
>

I am sorry - it says "Seq Scan on a...", of course,
not "... on bset ..."

Dima


Re: Why is it not using an index?

From
Stephan Szabo
Date:
On Fri, 15 Mar 2002, Dmitry Tkach wrote:

> 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;

You'll need to cast the 3 into smallint explicitly, either
3::smallint or CAST(3 as smallint) should work.