Re: Why is it not using an index? - Mailing list pgsql-general

From Dmitry Tkach
Subject Re: Why is it not using an index?
Date
Msg-id 3C92530D.2050005@openratings.com
Whole thread Raw
In response to Why is it not using an index?  (Dmitry Tkach <dmitry@openratings.com>)
Responses Re: Why is it not using an index?  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-general
Gregory Wood wrote:<br /><blockquote cite="mid:002801c1cc4f$25dba980$7889ffcc@comstock.com" type="cite"><blockquote
type="cite"><prewrap="">explain select * from a where x=3;<br /></pre></blockquote><pre wrap=""><br />PostgreSQL is
treating3 as an int4 (integer) type, whereas x is an int2<br />(smallint) type. Try casting the constant as a smallint
andit should use<br />the index:<br /><br />explain select * from a where x=3::smallint;<br /><br /></pre></blockquote>
Aha! Great! Thanks a lot! That worked!<br /> Now, the next problem:<br /><br /> explain select count (x) from a ;<br
/><br/> Aggregate  (cost=100175934.05..100175934.05 rows=1 width=2)<br />   ->  Seq Scan on a 
(cost=100000000.00..100150659.04rows=10110004 width=2)<br /><br /> Am I missing something here again, or will it just
notuse an index for aggregation?<br /><br /> I mean, especially an this case, it looks so weird that it KNOWS the
answerto my query RIGHT AWAY (rows=... in the explain response), yet it takes it so long to return it...<br /><br /><br
/><br/> 

pgsql-general by date:

Previous
From: "Cornelia Boenigk"
Date:
Subject: How to catch NOTIFY messages with PHP
Next
From: "Jeffrey W. Baker"
Date:
Subject: Re: more about pg_toast growth