voodoo index usage ;)

D. Duccini <duccini@backpack.com>

From: "D. Duccini" <duccini@backpack.com>
To: Pgsql-novice <pgsql-novice@postgreSQL.org>
Date: 2001-03-17T19:36:55Z
Lists: pgsql-novice
perhaps the db gawds can explain this....

# \d radusage
          Table "radusage"
 Attribute |    Type     | Modifier 
-----------+-------------+----------
 datetime  | timestamp   | not null
 account   | varchar(64) | 
 usage     | integer     | 
 sent      | integer     | 
 recv      | integer     | 
 ip        | bigint      | 
 host      | bigint      | 
 port      | smallint    | 
Indices: idxradaccount,
         idxraddate,
         idxradoid

# \d idxradaccount
  Index "idxradaccount"
 Attribute |    Type     
-----------+-------------
 account   | varchar(64)
btree

# \d idxraddate
  Index "idxraddate"
 Attribute |   Type    
-----------+-----------
 datetime  | timestamp
btree

# explain select * from radusage where account = 'someuser';
NOTICE:  QUERY PLAN:

Seq Scan on radusage  (cost=0.00..13870.80 rows=5674 width=50)

and if i add in datetime (without effectively changing the semantic
meaning of the search)

# explain select * from radusage where account = 'someuser' and datetime >
'1900-01-01';
NOTICE:  QUERY PLAN:

Index Scan using idxradaccount on radusage  (cost=0.00..15295.37 rows=5668
width=50)


first case doesn't use the index, the second does use what would seem to
be the correct index

isn't that wacky????

-duck

-----------------------------------------------------------------------------
david@backpack.com            BackPack Software, Inc.        www.backpack.com
+1 651.645.7550 voice       "Life is an Adventure.    
+1 651.645.9798 fax            Don't forget your BackPack!"   
-----------------------------------------------------------------------------