Re: Why is it not using an index?

From: Dmitry Tkach <dmitry(at)openratings(dot)com>
To: Gregory Wood <gregw(at)com-stock(dot)com>
Cc: PostgreSQL-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why is it not using an index?
Date: 2002-03-15 20:01:17
Message-ID: 3C92530D.2050005@openratings.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

<!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>
  -&gt;  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>

Attachment Content-Type Size
unknown_filename text/html 1.2 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2002-03-15 20:12:14 Re: Why is it not using an index?
Previous Message Gregory Wood 2002-03-15 19:20:11 Re: Why is it not using an index?

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2002-03-15 20:12:14 Re: Why is it not using an index?
Previous Message Dmitry Tkach 2002-03-15 19:31:44 Re: Btree index extension question