Re: indexes are not used

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: dev Rp <dev_rp(at)hotmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: indexes are not used
Date: 2002-06-11 12:18:00
Message-ID: 20020611221759.E4804@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jun 11, 2002 at 12:10:40PM +0000, dev Rp wrote:
> Hi,
> I have a table with 60,000 rows and integer as primary key. When I use
> select max(userid) from users;
> it is doing for sequential scan on users table, so that it is taking 40
> seconds to get the result.
> So I have set the sequential scan to off by using follwing option.
> set enable_seqscan to 'off'.
> still it is going for sequentail scan.
> Postgresql is installed on Solaris 5.8 on P3 500 mhz processor having 256 mb
> ram.
> Is there is any other way to force to use index or do I have to tune the
> database to reduce query time.

Perhaps you're looking for:

select userid from users order by userid desc limit 1;

And before you ask why that isn't done automatically, that's a FAQ and is
probably listed there somewhere.

--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> There are 10 kinds of people in the world, those that can do binary
> arithmetic and those that can't.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vincent Stoessel 2002-06-11 13:59:00 Re: Checking that Pg is running from a shell script
Previous Message dev Rp 2002-06-11 12:10:40 indexes are not used