Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eiDqg-0004Bk-NK for pgsql-hackers@arkaria.postgresql.org; Sun, 04 Feb 2018 06:32:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eiDqe-0007iI-85 for pgsql-hackers@arkaria.postgresql.org; Sun, 04 Feb 2018 06:32:20 +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 1eiDqd-0007i7-PS for pgsql-hackers@lists.postgresql.org; Sun, 04 Feb 2018 06:32:20 +0000 Received: from mail-vk0-x244.google.com ([2607:f8b0:400c:c05::244]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eiDqW-0007Fh-Cw for pgsql-hackers@postgresql.org; Sun, 04 Feb 2018 06:32:18 +0000 Received: by mail-vk0-x244.google.com with SMTP id h69so15907982vke.7 for ; Sat, 03 Feb 2018 22:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=T6toyFLX0ALVffqOwSCiGLgqGH5nfIyOSsEg2tMdD7o=; b=euEX/QB87vl+JA/1JjNtiZdVEZNvmj1MPWst/8Z3q0K6iNcVSUMyq5r3GeF4EnCOk4 G/8OZd/IPvWAAhTPNr8fEnA5GhpkF3CC8iYQ7FeJ/xGVEkwBqRv+xosXj0h+L4WJK4up W38TGZA64CI+NwhLBReIVPPct0tR3bUSsUNwTN0OUa2ET79IcWFkOF8J4AXXvjlACGmu 1PYeKO1LgItJLkSPj/t7r4nUJDh1cgmhIXJa6fnc71k1MhrC2P46VWAvXKCD7EGhLfSD FDe2r7C6cRSEAwcVQFgD2WJWJKTy1sqDlgVFaO/NHLXrYrXS6/7ELRS1YSNxrgl6i+iQ t/Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=T6toyFLX0ALVffqOwSCiGLgqGH5nfIyOSsEg2tMdD7o=; b=CttoYU9do4cb10VLJp7DxFaY87jDlUTOcYKe+NYsQG05s+HtvQXkYvCC1AVbGaFh3O X9pFznGyxqOXESHn3u+b+ZShPDozrx596xSrTwr5Nc15AAFMV3UZ/xzvXtQ3a81VruuE v1IPwUkEtesKn89pIBxZh1jcjTExx+kMf4txfPZWMfXIX+w6iklTe3riXBTtWGIVtYZb iHtWQap5xw+s+fe9E+WP87E0ZEK3JX1mOZLUYNY/RJly63O+ZR5avdZj9lyVF+Nz8Clu W66lhaigr8oZU/LyZWaSyF88bmEX0yzDW6H6aGRdgwZe1ZC8lxPQdmGFSPSRP8jlUpUJ vWmA== X-Gm-Message-State: AKwxytdjmwQ5/YYU1mcOnq9T4YgiBm6Bjy7IRL/v9/bvF4k98Y7w1/oE OgNrAjavo+Okmf6oCE0RiiphmWsb1NLwhqfwEVs= X-Google-Smtp-Source: AH8x225oCkS82IQxxhTe8UKzABNaAE+tWObHUjhjhUzci/b1k6ST/HaKFZ3v0vizW4HAwz1uKW4NCPaGySd9HK2TSr8= X-Received: by 10.31.177.200 with SMTP id a191mr29817471vkf.170.1517725929956; Sat, 03 Feb 2018 22:32:09 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.102.68 with HTTP; Sat, 3 Feb 2018 22:32:09 -0800 (PST) In-Reply-To: References: <20171027124555.txawx6p6veikx25x@alvherre.pgsql> From: Amit Kapila Date: Sun, 4 Feb 2018 12:02:09 +0530 Message-ID: Subject: Re: [HACKERS] MERGE SQL Statement for PG11 To: Peter Geoghegan Cc: Robert Haas , Simon Riggs , Alvaro Herrera , Andrew Dunstan , Pavan Deolasee , Stephen Frost , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Jan 31, 2018 at 11:37 PM, Peter Geoghegan wrote: > On Wed, Jan 31, 2018 at 7:17 AM, Robert Haas wrote: >> I don't fully grok merge but suppose you have: >> >> WHEN MATCHED AND a = 0 THEN UPDATE ... >> WHEN MATCHED AND a = 1 THEN UPDATE ... >> WHEN NOT MATCHED THEN INSERT ... >> >> Suppose you match a tuple with a = 0 but, upon trying to update it, >> find that it's been updated to a = 1. It seems like there are a few >> possible behaviors: >> >> 1. Throw an error! I guess this is what the patch does now. > > Right. > >> 2. Do absolutely nothing. I think this is what would happen with an >> ordinary UPDATE; the tuple fails the EPQ recheck and so is not >> updated, but that doesn't trigger anything else. > > I think #2 is fine if you're talking about join quals. Which, of > course, you're not. These WHEN quals really do feel like > tuple-at-a-time procedural code, more than set-orientated quals (if > that wasn't true, we'd have to allow cardinality violations, which we > at least try to avoid). Simon said something like "the SQL standard > requires that WHEN quals be evaluated first" at one point, which makes > sense to me. > It is not clear to me what is exactly your concern if we try to follow #2? To me, #2 seems like a natural choice. -- With Regards, Amit Kapila. EnterpriseDB: http://www.enterprisedb.com