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 1eu4ym-0005cc-R5 for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Mar 2018 23:29:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eu4yl-0004qr-MP for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Mar 2018 23:29:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eu4yl-0004qh-CD for pgsql-hackers@lists.postgresql.org; Thu, 08 Mar 2018 23:29:43 +0000 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eu4yh-0003gA-MM for pgsql-hackers@postgresql.org; Thu, 08 Mar 2018 23:29:42 +0000 Received: by mail-lf0-x244.google.com with SMTP id z128-v6so4557859lff.2 for ; Thu, 08 Mar 2018 15:29:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=UNeZZjdqe0ybJnP2YrwxRAG6PXEmNMHZDy6/DVF28ss=; b=Cai5hJVbouVGLKqZrYQNaYcXC8XBpfBFwVjGgWwEPMGG+f5tTJwwy2D8EpHOSXHtGR 3dAgTNQnwSVhvpJ2Wcn9mfUiIXNl0eBzWYhs90MR7VEJuVQcLYPU60DVTPsWrfhaWYxI lHA6eD0snxSAZZdyPKoAFLZjDEGetbOu84yVz0ayV/ZvcmLIPw4Tk5v3zn9EGJfZo0iZ 0y2W3LocN3meMoOxrsvBDnq8gv/KD4u4wOI7L4exIVad+QCs4kApvorD0EMgTubZiddQ ssqjHg+u6Xgj8/aDiRrZcsJDh7OYcM5q/14NLT1xch1y0b3nHati7ora1+Kro5oMBGwf tCyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=UNeZZjdqe0ybJnP2YrwxRAG6PXEmNMHZDy6/DVF28ss=; b=QjW2yYAsHyz5w7zV4tUGmZXV8VsB4+GuXchWnZaBAkmF0tS33b3nVUXgHvO3CU5Y+o v8KcIPxo6ssuPCQFNUnwvDvcW1Bfm4z6Aq/JlXgQQvtPBljPeP+ssTEni61ZefC79bBy feXujJ3NGxIxBwDk5crYZw+towML/gNm0j2p2vqahIZa2WCNFecrwusCMmB7oT0/lscq 9vbu/8J7zhadEjMU5l+GkcDMRZKPBxHzXplsv8FJTcAYZA6QjU6R029P3LyRFDRsyZls xeDSzzg3XTozfbNEVTDcp8b9QS4BTc9fhTxNvuV8omwhZcweXDYsmpNgendvic55W1N5 Q+bQ== X-Gm-Message-State: AElRT7FDGud0sPqO0/23OzcdxnD03BldigMMgWk5XRHiwgweP4eno2UV IV6eBTnQyQbbRlF+HyNHNNRSyuSCj+mjvQ2nkE5mV7pQktFGkM0zzpFTRWipuqsVJpNBVtjUBmH oDLrB16O9gz3odoM77Y9yuRJHPnLY7anpUOot7cOWpz9UB+AID6owFNpqmmdbCWcLvBDeXJT3YW H/iBo7DwDw/lelLg== X-Google-Smtp-Source: AG47ELv+gF8pTYPD5CEsqjDTJ0yC8BT6vRgkGD9YfRI9hrPd59WI7lwFwYynEftgMdsqgVCpsU6jXA== X-Received: by 10.25.169.67 with SMTP id s64mr20453052lfe.80.1520551778198; Thu, 08 Mar 2018 15:29:38 -0800 (PST) Received: from [10.137.2.17] (178-78-220-132.customers.ownit.se. [178.78.220.132]) by smtp.gmail.com with ESMTPSA id c19sm4293127lja.37.2018.03.08.15.29.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 15:29:37 -0800 (PST) Subject: Re: [HACKERS] MERGE SQL Statement for PG11 To: Peter Geoghegan , Robert Haas Cc: Pavan Deolasee , Simon Riggs , Alvaro Herrera , Andrew Dunstan , Pavan Deolasee , Stephen Frost , PostgreSQL-development References: From: Tomas Vondra Message-ID: <039bd6c2-eff8-3f3c-6896-fe992f069d1e@2ndquadrant.com> Date: Fri, 9 Mar 2018 00:29:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 03/08/2018 11:46 PM, Peter Geoghegan wrote: > On Thu, Mar 8, 2018 at 6:52 AM, Robert Haas wrote: >>> I removed this code since it was wrong. We might want to add some basic >>> checks for existence of volatile functions in the WHEN or SET clauses. But I >>> agree, it's no different than regular UPDATEs. So may be not a big deal. >> >> I just caught up on this thread. I'm definitely glad to see that code >> go because, wow, that is all kinds of wrong. I don't see a real need >> to add any kind of replacement check, either. Prohibiting volatile >> functions here doesn't seem likely to accomplish anything useful. It >> seems like the most we'd want to do is mention this the documentation >> somehow, and I'm not even sure we really need to do that much. > > Thanks in large part to Pavan's excellent work, the situation in > nodeModifyTable.c is much clearer than it was a few weeks ago. It's > now obvious that MERGE is very similar to UPDATE ... FROM, which > doesn't have any restrictions on volatile functions. > Yeah, I agree Pavan did an excellent work on moving this patch forward. > I don't see any sense in prohibiting volatile functions in either > case, because it should be obvious to users that that's just asking > for trouble. I can believe that someone would make that mistake, just > about, but they'd have to be writing their DML statement on > auto-pilot. > The reason why the patch tried to prevent that is because the SQL standard says this (p. 1176 of SQL 2016): 15) The immediately contained in a , the immediately contained in a , and the immediately contained in a shall not generally contain a whose subject routine is an SQL-invoked routine that possibly modifies SQL-data. I'm not quite sure what is required to be compliant with this rule. For example what does "immediately contained" or "shall not generally contain" mean? Does that mean user are expected not to do that because it's obviously silly, or do we need to implement some protection? That being said the volatility check seems reasonable to me (and i would not expect it to be a huge amount of code). regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services