Re: Why are selects so slow on large tables, even when

From: Neil Conway <nconway(at)klamath(dot)dyndns(dot)org>
To: Robert Wille <rwille(at)iarchives(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, Russell Black <russell(dot)black(at)iarchives(dot)com>
Subject: Re: Why are selects so slow on large tables, even when
Date: 2002-03-26 23:47:53
Message-ID: 1017186473.6934.226.camel@jiro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2002-03-26 at 18:28, Robert Wille wrote:
> To test PostgreSQL's scalability, I created a table with approximately 76M rows.
> The table had four columns: a bigint, a varchar(32), another bigint
> and a varchar(80).

> select count(*) from a where id < 0; /* returns 0 rows */
> select * from a where id=5; /* returns a handful of rows */
>
> 76M rows is a lot, but it shouldn't be that bad when id is indexed.

A couple things:

(1) You indicated that you ran VACUUM. You'll need to run VACUUM ANALYZE
(or just ANALYZE) to update the planner's statistics. For your
particular situation, this is essential.

(2) There is a long-standing bug with indexes on int8 columns: if you
use a numeric literal as a qualifier, it will be converted to an int4,
so the index won't be used. There is an easy work-around:

select * from a where id = 5; /* won't use index if id is int8 */
select * from a where id = 5::int8; /* will use index, if appropriate */

(3) You can get more information on the decisions Postgres is making
when executing your query through the use of EXPLAIN. In this instance,
it will likely tell you that the index isn't being used at all, and a
sequential scan is being performed.

If you follow suggestions #1 and #2, you should see markedly improved
performance. Let us know the results...

Cheers,

Neil

--
Neil Conway <neilconway(at)rogers(dot)com>
PGP Key ID: DB3C29FC

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message tsmets 2002-03-27 01:19:33 command to Describe RULE
Previous Message Dan Langille 2002-03-26 23:41:15 Re: Why are selects so slow on large tables, even when indexed?