Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hlNJk-0007Gj-EE for pgsql-bugs@arkaria.postgresql.org; Thu, 11 Jul 2019 00:52:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hlNJh-0001BJ-G3 for pgsql-bugs@arkaria.postgresql.org; Thu, 11 Jul 2019 00:52:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hlNJh-0001BC-50 for pgsql-bugs@lists.postgresql.org; Thu, 11 Jul 2019 00:52:09 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hlNJe-0001I7-9w for pgsql-bugs@lists.postgresql.org; Thu, 11 Jul 2019 00:52:07 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 9909B21B2C; Wed, 10 Jul 2019 20:52:05 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 10 Jul 2019 20:52:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=m7hx8N/ZGezvb+xk0DG7PnWtMt1 x4VebRdgBgb7kmDw=; b=ZtmlrJtKvUJfZahRPUmrSCnTtOb9FvrpKHbk+IKYpEi hP7ebDGCy0yqJuSJRBeJPzY9nxLI1Jci2YUyt++5tF3NlRWGn54CvNfvjI2cog2q x4YFPYQ2Su41CiK/duOfhUfvTWXqOPPSpRqnDSMrOQHcaaRySmdZolyH4PTz4/Gw PAK/HyoIJDJjHiTgFKoHopGHd5z3ySpbZp/R+bAh8wxLYMqZoYgVYcIUsWcYgiNN pCgHpQHZgA8KoQaKt5JBp7rVZnQJ7jgAz0ews1u/Hr9n0QO/UBgkScZB3YbSlL3D 1TS3EafFLpfNank8vZEAcAA/UW/hC+9FWKHTYgxTx2A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=m7hx8N /ZGezvb+xk0DG7PnWtMt1x4VebRdgBgb7kmDw=; b=je/D2JEe+PNFn8BfnAKxOy /kWib+4KJijyC0V9wUSMoslZ70zky6Mn8EAS1Pd7Z7zUbcK6EpUdT7NBMZx6u+rF nl9UxQxpGn89RqX0wCpKfLJutj2imnm97x1U/JoDVXKBduQUt8xgpJRxA0/bCJzW V+WrwyjeAWvIwIOk4FEr9WrRENjGRab7eDeW5PA9Urdqy8ULZ9bq2oVasRRDJpFj KcoF0IX1JPF61csUgi9VL9IoLvxH/HT9nEvpMiMCXmYyQh30OXMHIbYkAn/5G12f w0lJvhTb9Ttr2358sTbK2k3iaRjgVIgwA0OlnJWAl0t2afCXSD5pqUC/wLa60VIQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrgeejgdefkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecukfhppeeije drudeitddrvddukedrvdefjeenucfrrghrrghmpehmrghilhhfrhhomheprghnughrvghs segrnhgrrhgriigvlhdruggvnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from intern.anarazel.de (c-67-160-218-237.hsd1.ca.comcast.net [67.160.218.237]) by mail.messagingengine.com (Postfix) with ESMTPA id 8FD61380083; Wed, 10 Jul 2019 20:52:04 -0400 (EDT) Date: Wed, 10 Jul 2019 17:52:02 -0700 From: Andres Freund To: Tom Lane Cc: Thomas Munro , Alex Aktsipetrov , PostgreSQL mailing lists Subject: Re: BUG #15900: `executor could not find named tuplestore` in triggers with transition table and row locks Message-ID: <20190711005202.nq4hdomsdi7ml4fr@alap3.anarazel.de> References: <15900-bc482754fe8d7415@postgresql.org> <24530.1562686693@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <24530.1562686693@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2019-07-09 11:38:13 -0400, Tom Lane wrote: > Thomas Munro writes: > >> Alex's repro doesn't work on 11 though, > >> because EPQ is not entered at all. Which raises the question: why do > >> we need to enter EPQ after commit ad0bda5d on 12/master, for a row > >> that hasn't been updated by anyone else? > > > Explanation: since ad0bda5d24ea, ExecLockRows() always calls > > EvalPlanQualBegin() which initialises the plan state, and in this case > > ExecInitNamedTuplestoreScan() errors out due to the bug. Before, you > > needed the right concurrency scenario (epq_needed) before we did that, > > as the reporter of bug #15720 discovered. > > I'm quite desperately unhappy about this observation, because > EvalPlanQualBegin is a *large* amount of overhead that is usually > unnecessary, and is now going to be paid for *every locked row* > whether there's any conflict on it or not. I do not find that > acceptable. Why is it necessary to do this before finding that > there's an update conflict? Two main reasons: Previously we referenced tuples from LockRowsState->lr_curtuples, and the management of that was pretty tightly interlinked with EPQ, and only worked for heap tuples.Keeping that scheme would have been somewhat complicated to continue to maintain. Secondly, previously the tuple fetched by heap_lock_tuple() was just stored in a local variable - but now that happens via a slot (as we otherwise cannot reasonably handle things like heap wanting to return a pinned buffer, and others not). As we potentially need to lock rows from multiple tables, we'd need multiple slots suitable to lock/fetch those rows. EPQ already needed similar infrastructure internally - and those tuples were fetched and retained for EPQ's benefit. So it seemed sensible to just use the slots from EPQ. Note that we don't need EvalPlanQualFetch() anymore, as it's work is done inside the AM - obviously there's no AM independent way to perform correct ctid chasing. Which large overhead you mean is going to be paid for "*every locked row*"? EvalPlanQualBegin() ought to be fairly fast for repeated calls in the same node - although I do admit that it'd be a lot nicer if the ExecSetParamPlanMulti() work wouldn't need be redone. I think it might be reasonable to split EvalPlanQualBegin() (and perhaps EvalPlanQualStart()) into two pieces: One to just have a minimal EPQState, with valid slots, and one to get ready to actually run EPQ? Unfortunately I'm going to be unreachable pretty soon till Monday (hiking without any network access), so I won't be immediately able to respond. Greetings, Andres Freund