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 1hCq9R-0003bx-76 for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Apr 2019 18:34:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hCq9P-0006ZQ-KI for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Apr 2019 18:34:47 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hCq9P-0006ZJ-Bp for pgsql-hackers@lists.postgresql.org; Sat, 06 Apr 2019 18:34:47 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hCq9I-0001SD-1P for pgsql-hackers@lists.postgresql.org; Sat, 06 Apr 2019 18:34:46 +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 x36IYYbr019907; Sat, 6 Apr 2019 14:34:34 -0400 From: Tom Lane To: Andres Freund cc: pgsql-hackers@lists.postgresql.org, Hadi Moshayedi Subject: Re: tableam scan-API patch broke foreign key validation In-reply-to: <20190406182258.pvk5zkqdc6dobfg7@alap3.anarazel.de> References: <19030.1554574075@sss.pgh.pa.us> <19246.1554574409@sss.pgh.pa.us> <20190406182258.pvk5zkqdc6dobfg7@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Sat, 06 Apr 2019 11:22:58 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19905.1554575674.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 06 Apr 2019 14:34:34 -0400 Message-ID: <19906.1554575674@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andres Freund writes: > The relevant thread is: > https://www.postgresql.org/message-id/20190325180405.jytoehuzkeozggxx%40= alap3.anarazel.de Yeah, I just found that --- would have seen it sooner if David had not elected to make it a new thread. > Wonder if you have an opinion on: >> I've also noticed that we should free the tuple - that doesn't matter >> for heap, but it sure does for other callers. Why should this code need to free anything? That'd be the responsibility of the slot code, no? >> But uh, is it actually ok >> to validate an entire table's worth of foreign keys without a memory >> context reset? I.e. shouldn't we have a memory context that we reset >> after each iteration? >> Also, why's there no CHECK_FOR_INTERRUPTS()? heap has some internally o= n >> a page level, but that doesn't seem all that granular? These are good questions. Just eyeing RI_FKey_check(), I think that it might not have any significant leaks because most of the work is done in an SPI context, but obviously that's pretty fragile. The memory-context stuff in your WIP patch seems wrong, btw; the second or later iteration of the loop would trash oldcxt. But clearly we need a test case here. I'll adjust Hadi's example so that there's more than one tuple to check, and push it. regards, tom lane