<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
Gregory Wood wrote:<br>
<blockquote type="cite" cite="mid:002801c1cc4f$25dba980$7889ffcc(at)comstock(dot)com">
<blockquote type="cite">
<pre wrap="">explain select * from a where x=3;<br></pre>
</blockquote>
<pre wrap=""><!----><br>PostgreSQL is treating 3 as an int4 (integer) type, whereas x is an int2<br>(smallint) type. Try casting the constant as a smallint and it 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.04 rows=10110004 width=2)<br>
<br>
Am I missing something here again, or will it just not use an index for aggregation?<br>
<br>
I mean, especially an this case, it looks so weird that it KNOWS the answer
to my query RIGHT AWAY (rows=... in the explain response), yet it takes it
so long to return it...<br>
<br>
<br>
<br>
</body>
</html>