index and seq scan - Mailing list pgsql-general

From Tina Messmann
Subject index and seq scan
Date
Msg-id 3C3DC64D.5090907@xinux.de
Whole thread Raw
Responses Re: index and seq scan
Re: index and seq scan
Re: index and seq scan
List pgsql-general
Hello List,

i have the following table with an index on appid:

dbl=# \d test
                                     Table "test"
Attribute |           Type           |                    Modifier

-----------+--------------------------+-------------------------------------------------
id        | integer                  | not null default
nextval('"test_id_seq"'::text)
time      | timestamp with time zone |
appid     | integer                  |
Indices: appid_idx,
        test_id_key

dbl=# \d appid_idx
  Index "appid_idx"
Attribute |  Type
-----------+---------
appid     | integer
btree

Ii want this index to be used in my query, but only the seq. scan is
used and i don't know why.
When changing the WHERE expression to 'appid < 10', the index is used
(see EXPLAIN command below).
Could someone please explain this behavior to me and how i can use the
index in the first query?

dbl=# explain select * from test where appid > 10;
NOTICE:  QUERY PLAN:
Seq Scan on test  (cost=0.00..1530.84 rows=81050 width=16)
EXPLAIN

db=# explain select * from test where appid > 10;
NOTICE:  QUERY PLAN:
Index Scan using appid_idx on test  (cost=0.00..70.20 rows=57 width=16)
EXPLAIN

regards
Tina


pgsql-general by date:

Previous
From: "Campano, Troy"
Date:
Subject: Re: duplicating table
Next
From: "Peter Darley"
Date:
Subject: Re: Performance tips