Not using index - Mailing list pgsql-hackers

From Daniele Orlandi
Subject Not using index
Date
Msg-id 3918D279.538EB935@orlandi.com
Whole thread Raw
Responses Re: Not using index  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hello,

I just installed PG 7.0 and did some testing. I found what I believe is
a strange behaviour:

xtnet=# \d telecom         Table "telecom"Attribute |    Type     | Modifier 
-----------+-------------+----------regione   | varchar(20) | distretto | varchar(20) | settore   | varchar(20) |
descriz  | varchar(60) | cor_x     | float8      | cor_y     | float8      | cod_dis   | varchar(4)  | rete_urb  |
varchar(24)| 
 

xtnet=# create index telecom_regione on telecom ( regione );
CREATE

xtnet=# explain select distinct on (regione) * from telecom;
NOTICE:  QUERY PLAN:

Unique  (cost=0.00..4777.43 rows=3910 width=88) ->  Index Scan using telecom_regione on telecom  (cost=0.00..4679.68
rows=39100 width=88)

EXPLAIN

xtnet=# explain select distinct on (regione) regione from telecom;
NOTICE:  QUERY PLAN:

Unique  (cost=4370.91..4468.66 rows=3910 width=12) ->  Sort  (cost=4370.91..4370.91 rows=39100 width=12)       ->  Seq
Scanon telecom  (cost=0.00..1079.00 rows=39100
 
width=12)

EXPLAIN

xtnet=# explain select distinct on (regione) distretto,regione from
telecom;
NOTICE:  QUERY PLAN:

Unique  (cost=4492.72..4590.47 rows=3910 width=24) ->  Sort  (cost=4492.72..4492.72 rows=39100 width=24)       ->  Seq
Scanon telecom  (cost=0.00..1079.00 rows=39100
 
width=24)

EXPLAIN

It seems like the index is used only if * appears in the target list.
???

Bye!

-- Daniele

-------------------------------------------------------------------------------Daniele Orlandi - Utility Line Italia -
http://www.orlandi.comViaMezzera 29/A - 20030 - Seveso (MI) - Italy
 
-------------------------------------------------------------------------------


pgsql-hackers by date:

Previous
From: The Hermit Hacker
Date:
Subject: Re: [SQL] Mail problems
Next
From: "Hiroshi Inoue"
Date:
Subject: RE: Shouldn't flush dirty buffers at shutdown ?