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 D7FF4329DF7 for ; Tue, 14 Sep 2004 15:32:51 +0100 (BST) 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 87445-03 for ; Tue, 14 Sep 2004 14:32:41 +0000 (GMT) Received: from relay.snowman.net (relay.snowman.net [66.92.160.56]) by svr1.postgresql.org (Postfix) with ESMTP id 0DBA8329D9F for ; Tue, 14 Sep 2004 15:32:43 +0100 (BST) Received: from ns.snowman.net (ns.snowman.net [10.10.0.2]) by relay.snowman.net (8.12.11/8.12.11/Debian-5) with ESMTP id i8EEWX7D017963; Tue, 14 Sep 2004 10:32:33 -0400 Received: from ns.snowman.net (localhost [127.0.0.1]) by ns.snowman.net (8.12.11/8.12.11/Debian-5) with ESMTP id i8EEX48a019464; Tue, 14 Sep 2004 10:33:04 -0400 Received: (from sfrost@localhost) by ns.snowman.net (8.12.11/8.12.11/Debian-5) id i8EEX3Ig019462; Tue, 14 Sep 2004 10:33:03 -0400 Date: Tue, 14 Sep 2004 10:33:03 -0400 From: Stephen Frost To: Markus Schaber Cc: PostgreSQL Performance List Subject: Re: Data Warehouse Reevaluation - MySQL vs Postgres -- Message-ID: <20040914143303.GR21419@ns.snowman.net> Mail-Followup-To: Markus Schaber , PostgreSQL Performance List References: <20040912042442.49915.qmail@web41508.mail.yahoo.com> <20040914141452.002e5d4e@kingfisher.intern.logi-track.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="RF5hBp8jldNhGZp7" Content-Disposition: inline In-Reply-To: <20040914141452.002e5d4e@kingfisher.intern.logi-track.com> X-Editor: Vim http://www.vim.org/ X-Info: http://www.snowman.net X-Operating-System: Linux/2.4.24ns.3.0 (i686) X-Uptime: 10:24:11 up 227 days, 9:25, 9 users, load average: 0.11, 0.26, 0.21 User-Agent: Mutt/1.5.5.1+cvs20040105i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/120 X-Sequence-Number: 8248 --RF5hBp8jldNhGZp7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * Markus Schaber (schabios@logi-track.com) wrote: > Generally, what is the fastest way for doing bulk processing of=20 > update-if-primary-key-matches-and-insert-otherwise operations? This is a very good question, and I havn't seen much of an answer to it yet. I'm curious about the answer myself, actually. In the more recent SQL specs, from what I understand, this is essentially what the 'MERGE' command is for. This was recently added and unfortunately is not yet supported in Postgres. Hopefully it will be added soon. Otherwise, what I've done is basically an update followed by an insert using outer joins. If there's something better, I'd love to hear about it. The statements looks something like: update X set colA =3D a.colA, colB =3D a.colB from Y a where keyA =3D a.keyA and keyB =3D a.keyB; insert into X select a.keyA, a.keyB, a.colA, a.colB from Y a left join X b using (keyA, keyB) where b.keyA is NULL and b.keyB is NULL; With the appropriate indexes, this is pretty fast but I think a merge would be much faster. Thanks, Stephen --RF5hBp8jldNhGZp7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFBRwEfrzgMPqB3kigRAo4/AJ9HyzNvLF9BFRzjAs3WEgRy9h1LuACeMQFh Cl9BjMh9bkPnj53iJVWAIys= =P65B -----END PGP SIGNATURE----- --RF5hBp8jldNhGZp7--