Re: Slow sub-selects, max and count(*) - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Slow sub-selects, max and count(*)
Date
Msg-id 200402042113.01369.josh@agliodbs.com
Whole thread Raw
In response to Slow sub-selects, max and count(*)  ("Richard Sydney-Smith" <richard@ibisaustralia.com>)
Responses Re: Slow sub-selects, max and count(*)
List pgsql-sql
Richard,

> The issue is with the speed ( or lackof it) that the procedure proceeds. 
Apparently it is the subselects that are the worst issue and I have tried to 
replace these. Also max() and count() refuse to use indexes. 

Max() and Count() cannot use indexes for technical reasons.   Browse through 
the archives of SQL, PERFORM, and HACKERS for about 12,000 discussions on the 
subject.

> Please, I am sure that there is a better way to do this. And 5 to 7 minutes 
to insert a day is really too slow. Each days import table contains about 
3200 records. Total table size for fsechist is about 2.5 million records.

Standard advice:
1) Where possible, use COPY and not INSERT for bulk imports.
2) Where COPY is not possible, group inserts into 1000-statement blocks and 
wrap them in a transaction.
3) Where safe, suspend all triggers, foriegn keys, and constraints on the 
table while inserting and re-apply them afterward.

-- 
-Josh BerkusAglio Database SolutionsSan Francisco



pgsql-sql by date:

Previous
From: "Richard Sydney-Smith"
Date:
Subject: Slow sub-selects, max and count(*)
Next
From: "Iain"
Date:
Subject: Re: Slow sub-selects, max and count(*)