Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kC4wu-0004rP-Sz for pgsql-bugs@arkaria.postgresql.org; Sat, 29 Aug 2020 17:47:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kC4wt-000753-Hd for pgsql-bugs@arkaria.postgresql.org; Sat, 29 Aug 2020 17:47:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kC4wt-00074w-8u for pgsql-bugs@lists.postgresql.org; Sat, 29 Aug 2020 17:47:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kC4wm-0006bA-NW for pgsql-bugs@lists.postgresql.org; Sat, 29 Aug 2020 17:47:30 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 07THlJEs3568912; Sat, 29 Aug 2020 13:47:19 -0400 From: Tom Lane To: Jehan-Guillaume de Rorthais cc: pgsql-bugs@lists.postgresql.org Subject: Re: [BUG] plpgsql RETURN QUERY with toasted fields -vs- DROP/TRUNCATE In-reply-to: <20200828174342.2ac34e27@firost> References: <20200828174342.2ac34e27@firost> Comments: In-reply-to Jehan-Guillaume de Rorthais message dated "Fri, 28 Aug 2020 17:43:42 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3568910.1598723239.1@sss.pgh.pa.us> Date: Sat, 29 Aug 2020 13:47:19 -0400 Message-ID: <3568911.1598723239@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jehan-Guillaume de Rorthais writes: > We discovered a bug in plpgsql. > When using RETURN QUERY on a relation with some toasted values and when this > relaiton is later dropped or truncated, an error is raised at the end of the > function. This isn't particularly RETURN QUERY's fault; there are any number of ways to produce the same sort of error. I reproduced it with declare r record; ... for r in SELECT str FROM temp_rel loop return next r.str; end loop; as well as declare r record; ... SELECT str INTO r FROM temp_rel LIMIT 1; DROP TABLE temp_rel; --TRUNCATE TABLE temp_rel; return r.str; I guess we could forcibly detoast values in enough places to close all the gaps, but the performance costs might be annoying. I think a case can definitely be made for saying "don't do that". (Another idea, perhaps, might be to detoast only in volatile functions, reasoning that a nonvolatile one can't drop the table.) regards, tom lane