Skip site navigation (1) Skip section navigation (2)

Re: SELECT * FROM <table> LIMIT 1; is really slow

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Blasby <dblasby(at)refractions(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: SELECT * FROM <table> LIMIT 1; is really slow
Date: 2004-05-27 02:21:19
Message-ID: 5660.1085624479@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackers
David Blasby <dblasby(at)refractions(dot)net> writes:
> I have another copy of this table in another database - vacuum analyse 
> verbose says its "only" 1,500,000 pages (vs 2,800,000).

Hmm ... this is consistent with the idea that you did an UPDATE
affecting every row of the table.  That would generate N new rows which
would all get added to the end of the table, if there were no dead space
available within the table.  After commit you have a lot of pages worth
of dead tuples followed by a lot of pages worth of live tuples.  Plain
VACUUM cannot do much to fix this since it doesn't move rows around.
VACUUM FULL will fix it, but its index-update overhead is high enough
that CLUSTER is a better deal.

See followup message discussing ALTER TABLE as another alternative.

			regards, tom lane

In response to

Responses

pgsql-hackers by date

Next:From: James RobinsonDate: 2004-05-27 03:43:19
Subject: Re: tablespaces and DB administration
Previous:From: Tom LaneDate: 2004-05-27 02:06:13
Subject: Re: SELECT * FROM <table> LIMIT 1; is really slow

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group