On 05/30/2011 08:08 PM, Jarrod Chesney wrote:
My database uses joined table inheritance and my server version is 9.0
I have about 120,000 records in the table that everything else inherits from, if i truncate-cascaded this table it happens almost instantly. If i run 30,000 prepared "DELETE FROM xxx WHERE "ID" = ?" commands it takes close to 10 minutes.
My foreign keys to the base table are all set with "ON DELETE CASCADE".
You may also want to make them DEFERRABLE and then use "SET CONSTRAINTS
ALL DEFERRABLE" so that the constraint checking all happens at one
time. This will cause more memory to be used, but all the constraint
related work will happen in a batch.
You mentioned inheritance. That can cause some unexpected problems
sometimes. You might want to do:
EXPLAIN DELETE FROM ...
To see how this is executing. EXPLAIN works fine on DELETE statements,
too, and it may highlight something strange about how the deletion is
happening. If you can, use EXPLAIN ANALYZE, but note that this will
actually execute the statement--the deletion will happen, it's not just
a test.
There may be a problem with the query plan for the deletion that's
actually causing the issue here, such as missing the right indexes. If
you have trouble reading it, http://explain.depesz.com/ is a good web
resources to help break down where the time is going.
--
Greg Smith 2ndQuadrant US greg@xxxxxxxxxxxxxxx Baltimore, MD
PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us
"PostgreSQL 9.0 High Performance": http://www.2ndQuadrant.com/books
--
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance