X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 2BD0F476304; Wed, 9 Apr 2003 14:42:49 -0400 (EDT) Received: from cancerberus.com (cancerberus.com [216.121.191.54]) by postgresql.org (Postfix) with ESMTP id F33E2475ED4; Wed, 9 Apr 2003 14:42:17 -0400 (EDT) Received: from UebiMiau (localhost [127.0.0.1]) by cancerberus.com Dinamail Server with SMTPœ id h39IgHe21800; Wed, 9 Apr 2003 11:42:17 -0700 Message-Id: <200304091842.h39IgHe21800@cancerberus.com> Received: from client 147.83.200.238 for UebiMiau2.7 (webmail client); Wed, 9 Apr 2003 11:42:17 -0800 Date: Wed, 9 Apr 2003 11:42:17 -0800 From: "Cris" To: pgsql-admin@postgresql.org Reply-To: "Cris" Subject: Index not used, X-Priority: 3 X-Mailer: UebiMiau 2.7 X-Original-IP: 147.83.200.238 X-MSMail-Priority: Medium Importance: Medium Content-Type: text/html; charset="iso-8859-1"; MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, hits=-0.4 required=5.0 tests=BAYES_20,HTML_20_30,MIME_HTML_ONLY,MISSING_MIMEOLE, MISSING_OUTLOOK_NAME,MSG_ID_ADDED_BY_MTA_2 version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/156 X-Sequence-Number: 8311 Hi!
I've have this table:

TABLE BB : There isn't any primary key, and is it more or less order  (I mean, tt always is increased in each row, and id is nearly ordered)
ex:

id, op, atr, tt

1   0    X,   1
2   0    A   3
3   0   X    5
..........
1   0  =20 X   51
.......
85  1    l   150
86  2   po 155
2    0   X   178
87  3   1   189
....

I VACUUM ANALYZE each 10.000 inserts more or less
in my case op only can have 3 values;
I've created an index on (id,op,tt) to improve the next query, that is executed very often:
"SELECT * FROM BB WHERE id=3D"+ id+" AND op=3D0 order by tt desc;";
(because the only row I need is the one that has the highest tt)

but, after an hour running the program (more than 90.000 rows), I stopped it and
"EXPAIN SELECT * FROM BB WHERE id=3D"+ id+" AND op=3D0 order by tempst desc;";
But, my sorprise was that the index wasn't be used. Always do a Seq Scan.

Have I to define the index in other columns? Have I to VACUUM ANALYZE more often?

There is other option to avoid the sort that is done because of ORDER BY?

Thanks a lot

yours,

Cris..