X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3F3AC52940 for ; Tue, 26 Jul 2005 15:47:00 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13410-09 for ; Tue, 26 Jul 2005 18:46:57 +0000 (GMT) Received: from mail.Mi8.com (mail.mi8.com [63.240.6.50]) by svr1.postgresql.org (Postfix) with ESMTP id CD9D352C90 for ; Tue, 26 Jul 2005 15:46:54 -0300 (ADT) Received: from 172.16.1.110 by mail.Mi8.com with ESMTP (- GW05 Welcome to Mi8 Corporation www.Mi8.com); Tue, 26 Jul 2005 14:46:33 -0400 X-Server-Uuid: E0C866E6-C6CD-48B5-AE61-E57E73CF3CC7 Received: from MI8NYCMAIL06.Mi8.com ([172.16.1.175]) by D01SMTP01.Mi8.com with Microsoft SMTPSVC(6.0.3790.211); Tue, 26 Jul 2005 14:46:34 -0400 Received: from 67.103.45.218 ([67.103.45.218]) by MI8NYCMAIL06.Mi8.com ( [172.16.1.219]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.104]) with Microsoft Exchange Server HTTP-DAV ; Tue, 26 Jul 2005 14:46:33 -0500 User-Agent: Microsoft-Entourage/11.1.0.040913 Date: Tue, 26 Jul 2005 11:46:33 -0700 Subject: Re: faster INSERT with possible pre-existing row? From: "Luke Lonergan" To: "John A Meinel" , "Dan Harris" Cc: pgsql-performance@postgresql.org, "bizgres-general" Message-ID: In-Reply-To: <42E66B30.3030108@arbash-meinel.com> MIME-Version: 1.0 X-OriginalArrivalTime: 26 Jul 2005 18:46:34.0256 (UTC) FILETIME=[588BF100:01C59212] X-WSS-ID: 6EF85A831M813479194-01-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.578 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, RCVD_NUMERIC_HELO X-Spam-Level: * X-Archive-Number: 200507/396 X-Sequence-Number: 13637 John, On 7/26/05 9:56 AM, "John A Meinel" wrote: > You could insert all of your data into a temporary table, and then do: > > INSERT INTO final_table SELECT * FROM temp_table WHERE NOT EXISTS > (SELECT info FROM final_table WHERE id=id, path=path, y=y); > > Or you could load it into the temporary table, and then: > DELETE FROM temp_table WHERE EXISTS (SELECT FROM final_table WHERE id...); > > And then do a plain INSERT INTO. > > I can't say what the specific performance increases would be, but > temp_table could certainly be an actual TEMP table (meaning it only > exists during the connection), and you could easily do a COPY into that > table to load it up quickly, without having to check any constraints. Yah - that's a typical approach, and it would be excellent if the COPY bypassed WAL for the temp table load. This is something we discussed in bizgres development a while back. I think we should do this for sure - would nearly double the temp table load rate, and the subsequent temp table delete *should* be fast enough (?) Any performance tests you've done on that delete/subselect operation? - Luke