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 1hqT19-0000Dj-4u for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Jul 2019 01:58:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hqT17-0000w4-NQ for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Jul 2019 01:58:01 +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 1hqSy7-0005NQ-BS for pgsql-bugs@lists.postgresql.org; Thu, 25 Jul 2019 01:54:56 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hqSy4-0006IU-6K for pgsql-bugs@lists.postgresql.org; Thu, 25 Jul 2019 01:54:54 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 460BE21F4C; Wed, 24 Jul 2019 21:54:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 24 Jul 2019 21:54:51 -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:content-transfer-encoding:in-reply-to; s=fm2; bh=Z zKWelyK7Tw+PWF6nXEXJZfbM6BEt4khz9NRsGaLUvM=; b=BCWXfAYC6tbZgEr9d nvzyFB8K7ET+cd9SgWA6mv/gD61o1+xV47F6Ih90KUaiM6ae5S7o56UUCnOCcUYS DoQdvx55QMGOFK6JsZsTRQsQu2mkrYRrQq3vfBufTFO3Kz3cNzW3qkSdhHiwzRkE OzwjSuOfZeEWU777SHSi/W2acDUHOWJ2RueCkTsTIOzigVTQBfkSuC+VH6ysleIs xZEvafpdcPzEaAFKu1/XQCbLa541PxC8ll0YxPiiX1LHYkNE8ZdfPhtahoOp4lOw 8li092Czq+fW2aXush6u+QmnDL/TCzMdci5GBGS5vroWbTYkHlLqyH3Ga1y2HcNo lb8+w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=ZzKWelyK7Tw+PWF6nXEXJZfbM6BEt4khz9NRsGaLU vM=; b=pVS+wwZ1NEGqTjfTyZgogq6csAHdGocFh08dE+4d+PpFNiRIgxiiH7ufV e2bE1jvZXJDsHea3p7cB1BmtOqsq3usDIzNU7ylmhG+jpOwvmGjS9WVshT5e3jK8 VLlhLtymNmKccYOVSf1oVe0VmymLV6EFgEJdcX7kAujvtcWBmdfhn4J95hv8Lf88 RXw7Ci+Z8ZyhQG8E5s0MEdqghHp4Ime1YoRu1nfHgxlE8hcisnVDMAIRTfl2vkz/ 4Fb5PPRnfp6+k8E6IcWaGHRBEDIbOjHiVt7mblpRgUi7k6CzAOL8ldP7KjiI9tqV FcLIRRiU04cM3l1XrZXEhkcQv58ww== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrkedugdegjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucffohhmrg hinhepphhoshhtghhrvghsqhhlrdhorhhgpdhnohguvghmohguihhfhihtrggslhgvrdgt fienucfkphepieejrdduiedtrddvudekrddvfeejnecurfgrrhgrmhepmhgrihhlfhhroh hmpegrnhgurhgvshesrghnrghrrgiivghlrdguvgenucevlhhushhtvghrufhiiigvpedt 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 465668005A; Wed, 24 Jul 2019 21:54:50 -0400 (EDT) Date: Wed, 24 Jul 2019 18:54:48 -0700 From: Andres Freund To: Jeff Janes , Roby Cc: pgsql-bugs@lists.postgresql.org Subject: Re: ERROR: virtual tuple table slot does not have system attributes Message-ID: <20190725015448.e5a3rwa22kpnzfe3@alap3.anarazel.de> References: <73436355-6432-49B1-92ED-1FE4F7E7E100@finefun.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2019-06-29 17:50:03 -0700, Andres Freund wrote: > On June 29, 2019 5:47:18 PM PDT, Jeff Janes wrote: > >On Fri, Jun 28, 2019 at 5:38 AM Roby wrote: > > > >> Hi, > >> > >> Thank you all very much for your work on Postgres. > >> > >> I have encountered the following error in 12b2 in code that has been > >> working fine for a while in version 11. FWIW, this approach to detect whether ON CONFLICT has performed an update or a delete is quite unreliable - it only works because of an issue that's somewhere between a missed optimization and a bug. See https://www.postgresql.org/message-id/20190724232439.lpxzjw2jg3ukgcqn%40alap3.anarazel.de Normally the result of an UPDATE will not have an xmax set (unless there's concurrent FOR KEY SHARE lockers), it's really just an accident that it does so here. And we'll hopefully fix that. It will also certainly not work the same for future additional table access methods. I suggest writing an email to -hackers or such presenting as to why you'd a proper way to diagnose this. Shouldn't be too hard to add. > >> A test script is attached, the output of which follows. Here's a simpler reproducer: prep: DROP TABLE IF EXISTS upserttest; CREATE TABLE upserttest(key text primary key, data text); postgres[29156][1]=# INSERT INTO upserttest VALUES('1', '1') ON CONFLICT (key) DO UPDATE SET data = 'orig: '||upserttest.data || ' excluded: '||EXCLUDED.data RETURNING xmax; ┌──────┐ │ xmax │ ├──────┤ │ 0 │ └──────┘ (1 row) INSERT 0 1 postgres[29156][1]=# INSERT INTO upserttest VALUES('1', '1') ON CONFLICT (key) DO UPDATE SET data = 'orig: '||upserttest.data || ' excluded: '||EXCLUDED.data RETURNING xmax; ERROR: XX000: virtual tuple table slot does not have system attributes LOCATION: tts_virtual_getsysattr, execTuples.c:138 Time: 0.715 ms The fix for this is trivial, just need to use the table's slot type. I/We just didn't recognize that was necessary. diff --git i/src/backend/executor/nodeModifyTable.c w/src/backend/executor/nodeModifyTable.c index d8b695d897f..b299a246850 100644 --- i/src/backend/executor/nodeModifyTable.c +++ w/src/backend/executor/nodeModifyTable.c @@ -2546,7 +2546,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags) tupDesc = ExecTypeFromTL((List *) node->onConflictSet); resultRelInfo->ri_onConflict->oc_ProjSlot = ExecInitExtraTupleSlot(mtstate->ps.state, tupDesc, - &TTSOpsVirtual); + table_slot_callbacks(resultRelInfo->ri_RelationDesc)); /* build UPDATE SET projection state */ resultRelInfo->ri_onConflict->oc_ProjInfo = (plus comments and tests, of course) I pushed a fix. Thanks Roby for the report, and Jeff for the bisecting! Greetings, Andres Freund