Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > select distinct...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 20 Topic 15194 of 17602
Post > Topic >>

select distinct and index usage

by david.t.wilson@[EMAIL PROTECTED] ("David Wilson") Apr 6, 2008 at 07:32 PM

I have a reasonably large table (~75m rows,~18gb) called "vals". It
includes an integer datestamp column with approximately 4000 unique
entries across the rows; there is a normal btree index on the
datestamp column. When I attempt something like "select distinct
datestamp from vals", however, explain tells me it's doing a
sequential scan:

explain select distinct datestamp from vals;
                                      QUERY PLAN
--------------------------------------------------------------------------------------
 Unique  (cost=15003047.47..15380004.83 rows=4263 width=4)
   ->  Sort  (cost=15003047.47..15191526.15 rows=75391472 width=4)
         Sort Key: datestamp
         ->  Seq Scan on vals v  (cost=0.00..1531261.72 rows=75391472
width=4)

On another table in the same database with a much smaller number of
total rows (~15m rows), I have the exact same situation- but in this
case the index on the datestamp column *is* used:

explain select distinct datestamp from sdays;
                                                 QUERY PLAN
-------------------------------------------------------------------------------------------------------------
 Unique  (cost=0.00..974675.99 rows=4254 width=4)
   ->  Index Scan using sdays_datestamp_idx on sdays
(cost=0.00..932822.79 rows=16741280 width=4)

Any help on why the index isn't being used, or how I can set up the
index/query to make use of the index rather than doing an 18gb
sequential scan, would be very much appreciated.

-- 
- David T. Wilson
Princeton Satellite Systems
david.t.wilson@[EMAIL PROTECTED]
 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 20 Posts in Topic:
select distinct and index usage
david.t.wilson@[EMAIL PRO  2008-04-06 19:32:58 
Re: select distinct and index usage
craig@[EMAIL PROTECTED]   2008-04-07 10:20:15 
Re: select distinct and index usage
david.t.wilson@[EMAIL PRO  2008-04-06 22:41:56 
Re: select distinct and index usage
dalroi@[EMAIL PROTECTED]   2008-04-07 08:05:05 
Re: select distinct and index usage
david.t.wilson@[EMAIL PRO  2008-04-07 03:47:17 
Re: select distinct and index usage
dalroi@[EMAIL PROTECTED]   2008-04-07 19:42:02 
Re: select distinct and index usage
Stephen.Denne@[EMAIL PROT  2008-04-08 14:43:37 
Re: select distinct and index usage
jd@[EMAIL PROTECTED] (&q  2008-04-07 10:57:34 
Re: select distinct and index usage
david.t.wilson@[EMAIL PRO  2008-04-07 14:27:42 
Re: select distinct and index usage
tgl@[EMAIL PROTECTED] (T  2008-04-07 22:15:03 
Re: select distinct and index usage
alvherre@[EMAIL PROTECTED  2008-04-07 22:16:58 
Re: select distinct and index usage
tgl@[EMAIL PROTECTED] (T  2008-04-07 22:30:31 
Re: select distinct and index usage
stark@[EMAIL PROTECTED]   2008-04-08 00:57:21 
Re: select distinct and index usage
david.t.wilson@[EMAIL PRO  2008-04-07 20:54:38 
Re: select distinct and index usage
alvherre@[EMAIL PROTECTED  2008-04-07 21:01:24 
Re: select distinct and index usage
Stephen.Denne@[EMAIL PROT  2008-04-08 13:11:50 
Re: select distinct and index usage
kleptog@[EMAIL PROTECTED]  2008-04-08 08:50:30 
Re: select distinct and index usage
david.t.wilson@[EMAIL PRO  2008-04-08 04:23:04 
Re: select distinct and index usage
stark@[EMAIL PROTECTED]   2008-04-08 12:37:29 
Re: select distinct and index usage
alvherre@[EMAIL PROTECTED  2008-04-08 08:48:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 19:39:31 CST 2008.