Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g9Z7O-0004YC-5h for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Oct 2018 17:14:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g9Z7K-0008Cn-07 for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Oct 2018 17:14:50 +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 1g9Z7J-0008Cg-PC for pgsql-hackers@lists.postgresql.org; Mon, 08 Oct 2018 17:14:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g9Z7H-0004Dk-PB for pgsql-hackers@postgresql.org; Mon, 08 Oct 2018 17:14:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w98HEYem027415; Mon, 8 Oct 2018 13:14:34 -0400 From: Tom Lane To: Peter Eisentraut cc: Andres Freund , PostgreSQL-development , Alvaro Herrera , Bruce Momjian , Michael Paquier Subject: Re: transction_timestamp() inside of procedures In-reply-to: <38e36919-8bee-c717-be99-91137ad28aaf@2ndquadrant.com> References: <20180926155443.u4zh7jactzflys3z@alvherre.pgsql> <20181002145853.wvhcb7pbrzgjyxns@alap3.anarazel.de> <38e36919-8bee-c717-be99-91137ad28aaf@2ndquadrant.com> Comments: In-reply-to Peter Eisentraut message dated "Fri, 05 Oct 2018 13:28:54 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27413.1539018874.1@sss.pgh.pa.us> Date: Mon, 08 Oct 2018 13:14:34 -0400 Message-ID: <27414.1539018874@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Eisentraut writes: > On 02/10/2018 16:58, Andres Freund wrote: >> It's a bit weird to make this decision based on these two timestamps >> differing. For one, it only indirectly seems to be guaranteed that >> xactStartTimestamp is even set to anything here (to 0 by virtue of being >> a global var). > Maybe but it seems to be the simplest way without doing major surgery to > all this code. This patch doesn't apply over 07ee62ce9. Also, I like the timestamp-comparison approach even less than Andres does: I think it's probably outright broken, especially since it treats the equality case as license to advance xactStartTimestamp. Surely there is some way that we can directly test whether we're inside a procedure or not? I think the logic should be basically if (!IsParallelWorker()) + { + if (!InsideProcedure()) xactStartTimestamp = stmtStartTimestamp; + else + xactStartTimestamp = GetCurrentTimestamp(); + } else Assert(xactStartTimestamp != 0); regards, tom lane