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

From: Jason Earl <jason(dot)earl(at)simplot(dot)com>
To: "Robert Wille" <rwille(at)iarchives(dot)com>
Cc: "Neil Conway" <nconway(at)klamath(dot)dyndns(dot)org>, <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
Date: 2002-03-28 22:35:16
Message-ID: 87hen02ue3.fsf@npa01zz001.simplot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


"Robert Wille" <rwille(at)iarchives(dot)com> writes:

> The suggested fixes have helped a lot, but it is still rather
> slow. The time varies and can be upwards of 10 to 20 seconds on a
> ~47M row table. Is this normal? Similar queries on an indexed
> varchar column in Oracle with about 1/2 as many rows execute at
> least a hundred times faster.

I realize that it has taken me quite a while to get back to you, on
this particular case but I have been running some tests on your data
(or 28 million lines of it anyway) and I have some stuff to share.

First of all, your sample data set has the *opposite* problem of most
queries that PostgreSQL users complain about. Most people complain
about queries that do sequential scans when PostgreSQL should be doing
an index scan. Your data, on the other hand, caused PostgreSQL to do
an indexscan when it probably should have been doing a sequential
scan. After all, there are only 1000 (or so) different unique values
of "id" and the instances of each value are spread evenly throughout
the table. Since you are going to touch most pages anyhow consulting
the index is just an extra step. On my limited test machine I
actually saw modest gains on queries like:

SELECT count(*) FROM a WHERE id = 89::bigint;

However, if you cluster the index on id then similar queries started
to return *immediately*. Don't forget to vacuum after clustering.

I hope this was helpful, I sured learned a lot.

Jason

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Matthew Kirkwood 2002-03-28 23:15:24 Re: Performance Tuning Document?
Previous Message Bruce Momjian 2002-03-28 21:37:33 Re: Performance Tuning Document?