X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 9857FD1B55C for ; Thu, 5 Feb 2004 05:13:56 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 08685-10 for ; Thu, 5 Feb 2004 01:13:57 -0400 (AST) Received: from davinci.ethosmedia.com (server228.ethosmedia.com [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id 6172FD1D8AE for ; Thu, 5 Feb 2004 01:13:51 -0400 (AST) Received: from [63.195.55.98] (HELO 192.168.1.29) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 4374148; Wed, 04 Feb 2004 21:14:58 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: "Richard Sydney-Smith" , Subject: Re: Slow sub-selects, max and count(*) Date: Wed, 4 Feb 2004 21:13:01 -0800 User-Agent: KMail/1.5.4 References: <001001c3eb8a$255d6dc0$5801a8c0@athlon2000> In-Reply-To: <001001c3eb8a$255d6dc0$5801a8c0@athlon2000> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200402042113.01369.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/50 X-Sequence-Number: 16741 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 Berkus Aglio Database Solutions San Francisco