Re: Impact of foreign keys on a simple count(*) ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "C(dot) Bensend" <benny(at)bennyvision(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Impact of foreign keys on a simple count(*) ?
Date: 2004-10-09 03:49:23
Message-ID: 23596.1097293763@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"C. Bensend" <benny(at)bennyvision(dot)com> writes:
> Is it the addition of the multiple foreign keys that is slowing this
> down so much?

Foreign keys have zero, nada, zilch to do with the performance of
count(*). The only plausible theory I can think of for the performance
difference is that in your "new" database the table has been through
several mass updates, leading to a whole lot of dead rows and a much
larger physical table size to scan through. I'd suggest a VACUUM
VERBOSE on both old and new copies of the table to get an idea of the
relative physical sizes. You might need a VACUUM FULL to get the new
table back down to a reasonable size...

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message C. Bensend 2004-10-09 04:13:02 Re: Impact of foreign keys on a simple count(*) ?
Previous Message C. Bensend 2004-10-09 03:37:33 Impact of foreign keys on a simple count(*) ?