From 1fd981f05369340a8afa4d013a350b0b2ac6e33e Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 5 Nov 2025 14:35:16 +0900 Subject: Drop unnamed portal immediately after execution to completion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, unnamed portals were kept until the next Bind message or the end of the transaction. This could cause temporary files to persist longer than expected and make logging not reflect the actual SQL responsible for the temporary file. This patch changes exec_execute_message() to drop unnamed portals immediately after execution to completion at the end of an Execute message, making their removal more aggressive. This forces temporary file cleanups to happen at the same time as the completion of the portal execution, with statement logging correctly reflecting to which statements these temporary files were attached to (see the diffs in the TAP test updated by this commit for an idea). The documentation is updated to describe the lifetime of unnamed portals, and test cases are updated to verify temporary file removal and proper statement logging after unnamed portal execution. This changes how unnamed portals are handled in the protocol, hence no backpatch is done. Author: Frédéric Yhuel Co-Authored-by: Sami Imseih Co-Authored-by: Mircea Cadariu Discussion: https://postgr.es/m/CAA5RZ0tTrTUoEr3kDXCuKsvqYGq8OOHiBwoD-dyJocq95uEOTQ%40mail.gmail.com --- doc/src/sgml/protocol.sgml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'doc/src/sgml') diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml index 9d755232873..d1b9af11b07 100644 --- a/doc/src/sgml/protocol.sgml +++ b/doc/src/sgml/protocol.sgml @@ -1006,8 +1006,8 @@ SELCT 1/0; If successfully created, a named portal object lasts till the end of the current transaction, unless explicitly destroyed. An unnamed portal is - destroyed at the end of the transaction, or as soon as the next Bind - statement specifying the unnamed portal as destination is issued. (Note + destroyed at the end of the transaction, or as soon as the statement + specifying the unnamed portal as destination is processed to completion. (Note that a simple Query message also destroys the unnamed portal.) Named portals must be explicitly closed before they can be redefined by another Bind message, but this is not required for the unnamed portal. -- cgit v1.2.3