pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Barry Lind <blind@xythos.com>
To: Cris <cris@dmcid.net>
Cc: pgsql-admin@postgresql.org, PostgreSQL JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: [JDBC] Index not used,
Date: Wed, 09 Apr 2003 12:00:21 -0700
Message-ID: <3E946DC5.9020304@xythos.com> (raw)
In-Reply-To: <200304091842.h39IgHe21800@cancerberus.com>
References: <200304091842.h39IgHe21800@cancerberus.com>

Cris,

What version are you running and what are the datatypes of your columns?

Prior to 7.3, postgres wouldn't use an index in the following case:

column = 1

if the datatype of the column "column" wasn't integer.  In order to get 
it to use the index you needed a cast, so if for example column was of 
type int8, you would use:

column = 1::int8

so that both sides of the condition were the same datatype.  Then the 
index would be used.

thanks,
--Barry




Cris wrote:
> 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   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="+ id+" AND op=0 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="+ id+" AND op=0 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..




view thread (4+ messages)  latest in thread

Message-ID: <3E946DC5.9020304@xythos.com>
Permalink:  ../3E946DC5.9020304@xythos.com/
Also on:    postgresql.org/message-id/3E946DC5.9020304@xythos.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: blind@xythos.com, cris@dmcid.net, pgsql-jdbc@postgresql.org
  Subject: Re: [JDBC] Index not used,
  In-Reply-To: <3E946DC5.9020304@xythos.com>
  References: <200304091842.h39IgHe21800@cancerberus.com> <3E946DC5.9020304@xythos.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox