Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eALTI-0006Rc-Jm for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Nov 2017 19:48:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eAL6o-0006yX-Rg for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Nov 2017 19:24:58 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eAKyq-0002uF-6M for pgsql-hackers@postgresql.org; Thu, 02 Nov 2017 19:16:44 +0000 Received: from mail-pg0-x236.google.com ([2607:f8b0:400e:c05::236]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1eAKyn-00076B-2c for pgsql-hackers@postgresql.org; Thu, 02 Nov 2017 19:16:43 +0000 Received: by mail-pg0-x236.google.com with SMTP id y5so443490pgq.7 for ; Thu, 02 Nov 2017 12:16:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bowt-ie.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=DHcbu+yihgXSjXFdoUZFd1ki2Kp6hJvUcTcSMou2bw4=; b=WTjMIfsrxhHdsRdp25NQ4seFKM980EBJ8C9la2HFzedBdOxRxJqnKixnS/EtPEqaRW Hka9POSzHrbx6hKbYmW1CEePYSDaxQT4dwS0mMoH4Qns6UouFnDte9RgZJFwLTiYaWGN x5xZfQAcPgY3o0qbgjB+iVBlHMjYgxFzfyEQCGnMmsbOEm0PWMm9ujxIE+sPNZ9Tm3ul m74tfxnJWHDHNpo4t2TFWVdZwW+kvj+0O9E+UrZcpYiA729SFhJmLzKJpcA+4JvN3c7w 7Bnf7LJI8c3mK0qy1vYF7px89E/k9nVgfiwZTowv4ClIqOFiXbSjS6s2JBk6W51DCoMr H6BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=DHcbu+yihgXSjXFdoUZFd1ki2Kp6hJvUcTcSMou2bw4=; b=GYAhMkwtZ7B6Zx/1CsRywITT5Y2g2+x6qGfclxFN7GfKc8iXNwIQsR6NcYayKA47LF QK6LxX15rX13iGgcKK39JIP/0zwCBADDyQCZfA4fiFQ8lQw8vmoZ2GmYhs5A+rkLJ6lY MNGUQkHpaM5IFSPvAA1yrMPP9uBWrc5pbQYTtevbeCHrFs0WnnQWilUiUAizN0OO0HiD P/43onLQks9RmKGj+bRsLVD9dBxJ+iO/GZ2LfasfWIl7w7biMZKFjTlWDSJj1XggV9fT jVJP604u2jIiki6WL/7+uTiWn16WvHtNEEKdx2bXw0IVY8voqGwL7W+KWxtW4sm1DMwx kqAw== X-Gm-Message-State: AMCzsaXSrI0tBJlUz9cv+WbtZ1xPVOZqW+qB+qMnMJUwmA871lY4pkty KxmitzHKjed/cA/QSG9LBv0UEg== X-Google-Smtp-Source: ABhQp+QT4KroAr5HgMLampdJrKL+gcjlNPXr6Pc8kVUt9AGDL2Gv0gL7TAR2C25npMUaImAhciOd+g== X-Received: by 10.99.95.205 with SMTP id t196mr4742412pgb.442.1509650199394; Thu, 02 Nov 2017 12:16:39 -0700 (PDT) Received: from marmot ([162.217.72.7]) by smtp.gmail.com with ESMTPSA id s4sm7514317pgp.40.2017.11.02.12.16.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Nov 2017 12:16:38 -0700 (PDT) Date: Thu, 2 Nov 2017 12:16:36 -0700 From: Peter Geoghegan To: Simon Riggs Cc: Robert Haas , Michael Paquier , PostgreSQL-development Subject: Re: MERGE SQL Statement for PG11 Message-ID: <20171102191636.GA27644@marmot> References: <20171101182032.GA7104@marmot> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Simon Riggs wrote: >So if I understand you correctly, in your view MERGE should just fail >with an ERROR if it runs concurrently with other DML? That's certainly my opinion on the matter. It seems like that might be the consensus, too. Obviously there are things that you as a user can do about this on your own, like opt to use a higher isolation level, or manually LOCK TABLE. For some use cases, including bulk loading for OLAP, users might just know that there isn't going to be concurrent activity because it's not an OLTP system. If this still seems odd to you, then consider that exactly the same situation exists with UPDATE. A user could want their UPDATE to affect a row where no row version is actually visible to their MVCC snapshot, because they have an idea about reliably updating the latest row. UPDATE doesn't work like that, of course. Is this unacceptable because the user expects that it should work that way? Bear in mind that ON CONFLICT DO UPDATE *can* actually update a row when there is no version of it visible to the snapshot. It can also update a row where there is a concurrent DELETE + INSERT, and the tuples with the relevant unique index values end up not even being part of the same update chain in each case (MVCC-snapshot-visible vs. latest). IOW, you may end up updating a completely different logical row to the row with the conflicting value that is visible to your MVCC snapshot! >i.e. if a race condition between the query and an INSERT runs >concurrently with another INSERT > >We have no interest in making that work? Without meaning to sound glib: we already did make it work for a special, restricted case that is important enough to justify introducing a couple of kludges -- ON CONFLICT DO UPDATE/upsert. I do agree that what I propose for MERGE will probably cause confusion; just look into Oracle's MERGE implementation for examples of this. We ought to go out of our way to make it clear that MERGE doesn't provide these guarantees. -- Peter Geoghegan -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers