Index not used,

From: "Cris" <cris(at)dmcid(dot)net>
To: pgsql-admin(at)postgresql(dot)org
Subject: Index not used,
Date: 2003-04-09 19:42:17
Message-ID: 200304091842.h39IgHe21800@cancerberus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-jdbc

Hi!<BR>I've have this table:<BR><BR>TABLE BB : There isn't any primary key,
and is it more or less order&nbsp; (I mean, tt always is increased in each
row, and id is nearly ordered)<BR>ex:<BR><BR>id, op, atr, tt<BR><BR> 1
&nbsp; 0&nbsp; &nbsp; X,&nbsp;&nbsp; 1 <BR>2&nbsp;&nbsp;
0&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;&nbsp; 3<BR>3&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;
X&nbsp;&nbsp;&nbsp; 5<BR>..........<BR>1&nbsp;&nbsp; 0&nbsp;&nbsp;
X&nbsp;&nbsp; 51<BR>.......<BR>85&nbsp; 1&nbsp;&nbsp;&nbsp; l&nbsp;&nbsp;
150<BR>86&nbsp; 2&nbsp;&nbsp; po 155<BR>2&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;
X&nbsp;&nbsp; 178<BR>87&nbsp; 3&nbsp;&nbsp; 1&nbsp;&nbsp;
189<BR>....<BR><BR>I VACUUM ANALYZE each 10.000 inserts more or less<BR>in
my case op only can have 3 values;<BR>I've created an index on (id,op,tt) to
improve the next query, that is executed very often:<BR>"SELECT * FROM BB
WHERE id="+ id+" AND op=0 order by tt desc;";<BR>(because the only row I
need is the one that has the highest tt)<BR><BR>but, after an
hour&nbsp;running the program (more than 90.000 rows), I stopped it and
<BR>"EXPAIN SELECT * FROM BB WHERE id="+ id+" AND op=0 order by tempst
desc;";<BR>But, my sorprise was that the index wasn't be used. Always do a
Seq Scan.<BR><BR>Have I to define the index in other columns? Have I to
VACUUM ANALYZE&nbsp;more often? <BR><BR>There is other option to avoid the
sort that is done because of ORDER BY?<BR><BR>Thanks a
lot<BR><BR>yours,<BR><BR>Cris..

Attachment Content-Type Size
unknown_filename text/html 1.4 KB

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Robert Treat 2003-04-09 19:56:04 Re: trouble connecting to Postgresql Database via
Previous Message Tom Lane 2003-04-09 19:28:28 Re: Index not used,

Browse pgsql-jdbc by date

  From Date Subject
Next Message Mark French 2003-04-09 20:05:36 Callable Statements
Previous Message Jason Dinger 2003-04-09 19:40:40 tomcat/postgres problem