Re: Why is it not using an index?
От | Dmitry Tkach |
---|---|
Тема | Re: Why is it not using an index? |
Дата | |
Msg-id | 3C92530D.2050005@openratings.com обсуждение исходный текст |
Ответ на | Why is it not using an index? (Dmitry Tkach <dmitry@openratings.com>) |
Ответы |
Re: Why is it not using an index?
|
Список | 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 по дате отправления: