pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: Index not used,
4+ messages / 4 participants
[nested] [flat]
* Index not used,
@ 2003-04-09 19:42 Cris <cris@dmcid.net>
2003-04-09 18:56 ` Re: Index not used, Stephan Szabo <sszabo@megazone23.bigpanda.com>
2003-04-09 19:00 ` Re: [JDBC] Index not used, Barry Lind <blind@xythos.com>
0 siblings, 2 replies; 4+ messages in thread
From: Cris @ 2003-04-09 19:42 UTC (permalink / raw)
To: pgsql-admin
Hi!<BR>I've have this table:<BR><BR>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)<BR>ex:<BR><BR>id, op, atr, tt<BR><BR> 1
0 X, 1 <BR>2
0 A 3<BR>3 0
X 5<BR>..........<BR>1 0
X 51<BR>.......<BR>85 1 l
150<BR>86 2 po 155<BR>2 0
X 178<BR>87 3 1
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 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 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..
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Index not used,
2003-04-09 19:42 Index not used, Cris <cris@dmcid.net>
@ 2003-04-09 18:56 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2003-04-09 19:28 ` Re: Index not used, Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 4+ messages in thread
From: Stephan Szabo @ 2003-04-09 18:56 UTC (permalink / raw)
To: Cris <cris@dmcid.net>; +Cc: pgsql-admin
On Wed, 9 Apr 2003, Cris wrote:
> 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)
You might want to use limit 1 then to prevent it from getting all the rest
of the rows as well.
> 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.
What is the actual explain output?
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Index not used,
2003-04-09 19:42 Index not used, Cris <cris@dmcid.net>
2003-04-09 18:56 ` Re: Index not used, Stephan Szabo <sszabo@megazone23.bigpanda.com>
@ 2003-04-09 19:28 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 4+ messages in thread
From: Tom Lane @ 2003-04-09 19:28 UTC (permalink / raw)
To: Cris <cris@dmcid.net>; +Cc: pgsql-admin
Stephan Szabo <sszabo@megazone23.bigpanda.com> writes:
> On Wed, 9 Apr 2003, Cris wrote:
>> 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)
> You might want to use limit 1 then to prevent it from getting all the rest
> of the rows as well.
Also, I think you'll need to say "ORDER BY id, op, tt" to get it to
realize that the index matches the required ordering.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [JDBC] Index not used,
2003-04-09 19:42 Index not used, Cris <cris@dmcid.net>
@ 2003-04-09 19:00 ` Barry Lind <blind@xythos.com>
1 sibling, 0 replies; 4+ messages in thread
From: Barry Lind @ 2003-04-09 19:00 UTC (permalink / raw)
To: Cris <cris@dmcid.net>; +Cc: pgsql-admin@postgresql.org, PostgreSQL JDBC <pgsql-jdbc@postgresql.org>
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..
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2003-04-09 19:42 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-04-09 19:42 Index not used, Cris <cris@dmcid.net>
2003-04-09 18:56 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2003-04-09 19:28 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-04-09 19:00 ` Barry Lind <blind@xythos.com>
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