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 1hsz8d-0004Gq-J9 for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Aug 2019 00:40: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 1hsz8c-0001ay-Dg for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Aug 2019 00:40:10 +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 1hsz8a-0001TD-GP for pgsql-bugs@lists.postgresql.org; Thu, 01 Aug 2019 00:40:10 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hsz8X-0007ks-KE for pgsql-bugs@lists.postgresql.org; Thu, 01 Aug 2019 00:40:07 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id C0E9E223F5; Wed, 31 Jul 2019 20:40:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 31 Jul 2019 20:40:04 -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=e15WOYisvypoZWQqcVUsEyF9K9I 3D8s0EAZZVrmYUG4=; b=Gpou/3I3/xmrWlq6sipgyhELebvucsefydPdrueahBg NiWDR3ga3QGkOrOl3r39tEB7bY2uUJA8pI4/j9vao/a3UU/QK7h2EuNKm0sQZhpG mHDBkZyKWEET4RTv4bODpoZN02ZzotGfj+IHgUzoh1c3ZDhd7WPj8aj/JB4vPzZa nFiwdrhlz0B6BMASEjLo4Tpl0ctis8lk/jq0izZA5D/NZeG3zfNw4Cq1xNxbDcWR s1M/01a5a9XHNcUGSB2aLhhvlfJQKkjazpZjPVZvdDPKVLuSs/QZ9yV3SMXdXoum OSstdT7LyNWxpxqvw+xVTciwM8hSvgcfxVAvZKOks6w== 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=e15WOY isvypoZWQqcVUsEyF9K9I3D8s0EAZZVrmYUG4=; b=m9pD6+3jmmL1kN4q8tIBPx DXr1/2RaPCK6mG/qpxr6jaPQBQ4MZ4m5I4o8/1MOY8lib1XHntJNgIsDlD5Jxijw 8gELHlm3wuc4X8+ZtDhs1ZYUP2zbl1Sbd11MZmPuczTt9TByNmtWodE4bwYnfkDH 2D0xgSg/GkOiMZs2cHjJNGJNOlK2gb/9PhU8/yXfvJd64jdRhN0KOKUn31jc855q E/KnDA7f5jxovuvga1EEyiG7z8zmLN2sGtGo7IThAqIj7YVn5lPbGOqdsyd6i8Ew NPJOeBv0ty6Yton94XhR+YCn0r+IUGBNi3qnBih4SbxZUoGl2qTGbJzQX8KxG72A == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrleeigdefhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehttdertd dttddvnecuhfhrohhmpeetnhgurhgvshcuhfhrvghunhguuceorghnughrvghssegrnhgr rhgriigvlhdruggvqeenucfkphepieejrdduiedtrddvudekrddvfeejnecurfgrrhgrmh epmhgrihhlfhhrohhmpegrnhgurhgvshesrghnrghrrgiivghlrdguvgenucevlhhushht vghrufhiiigvpedt 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 C8FD180059; Wed, 31 Jul 2019 20:40:03 -0400 (EDT) Date: Wed, 31 Jul 2019 17:40:00 -0700 From: Andres Freund To: Tom Lane Cc: yi huang , pgsql-bugs@lists.postgresql.org Subject: Re: PostgreSQL12 crash bug report Message-ID: <20190801004000.3xis75ulpun4ha3p@alap3.anarazel.de> References: <20811.1564344681@sss.pgh.pa.us> <28807.1564614449@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <28807.1564614449@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2019-07-31 19:07:29 -0400, Tom Lane wrote: > I wrote: > > yi huang writes: > >> [ crashes with ] > >> $ pgbench -h 127.0.0.1 -p 5432 -U exchange exchange -T 2 -c 4 -f /tmp/test.sql > > > As per the stack trace, we're trying to build a new tuple for the output > > of a ValuesScan node, but the targetlist for that seems completely insane: > > After digging through this, it seems clear that it's the fault of > ad0bda5d2, specifically this code in EvalPlanQualSlot: > > *slot = ExecAllocTableSlot(&epqstate->estate->es_tupleTable, > epqstate->origslot->tts_tupleDescriptor, > &TTSOpsVirtual); > > It's setting up an es_epqTupleSlot[] entry on the assumption that it > should have the same tupdesc as the output tuple that's to be rechecked. > This might accidentally fail to malfunction in single-table cases, > but it's quite broken for any join case --- in particular, for the > given test case, the scan tuple for the VALUES node surely doesn't have > the same tupdesc as the join result. :( We really need to improve the test coverage for EPQ :(. I tried to add a few cases, but it's still one of the least tested complicated areas in PG. To make sure I understand - the problem isn't the slot that we've created in nodeModifyTable.c via EvalPlanQualSlot(), right? It's the one we create in EvalPlanQualFetchRowMarks(), because we don't have a proper tuple type handy to create the slot with? And then ExecScanFetch() (on behalf of ValueScan in this case) expects something with the correct format in that slot, which causes the backtrace you show. And this problem occurs "only" for ROW_MARK_COPY, because for everything else we have an associated relation. Previously we simply didn't need to know the type during EPQ setup, because we only stored a HeapTuple anyway. And we'd know the appropriate tupledesc at the places that access the tuple. Right? > I think we need to change the API of EvalPlanQualSlot, because it > cannot determine the correct tupdesc when it's not handed a Relation. > I'm not entirely sure that its immediate callers can either :-( so > this might propagate out a ways. Or perhaps we should move the > slot-making someplace else. I think we'll probably have to split EvalPlanQualSlot() into two functions. One for nodeModifyTable.c and nodeLockRows.c, and the !ROW_MARK_COPY cases in EvalPlanQualFetchRowMarks(). One bigger change - but possibly one worth it - would be to basically move the work done in EvalPlanQualFetchRowMarks() to be done on-demand, at least for ROW_MARK_COPY. We don't need to do /* fetch the whole-row Var for the relation */ datum = ExecGetJunkAttribute(epqstate->origslot, aerm->wholeAttNo, &isNull); /* non-locked rels could be on the inside of outer joins */ if (isNull) continue; that early in the query. We could call EvalPlanQualFetchRowMark() (note the singular) from ExecScanFetch(), that ought to currently be the only place that accesses ROW_MARK_COPY type rowmarks? We could do the same for the other types of rowmarks, but I think that'd be semantically somewhat murkier. That would have the advantage that we'd not unnecessarily put row marks we might never need into slots. There's probably not that many cases where that matters, though. Or we could keep enough information for ROW_MARK_COPY RowMarks around to create the necessary tupledesc (there's a number of variants as to how - don't zap the information in add_rte_to_flat_rtable, have setrefs.c somehow keep maintain rti indexed pointers to Plan nodes, ...). Not sure yet what's best here. Greetings, Andres Freund