Skip to content

Commit 9106904

Browse files
committed
Revert "Drop unnamed portal immediately after execution to completion"
This reverts commit 1fd981f, based on concerns that the logging improvements do not justify the protocol breakage of dropping an unnamed portal once its execution has completed. It seems unlikely that one would try to send an execute or describe message after the portal has been used, but if they do such post-completion messages would not be able to process as the previous versions. Let's revert this change for now so as we keep compatibility and consider a different solution. The tests added by 76bba03 track the pre-1fd981f05369 behavior, and are still valid. Discussion: https://postgr.es/m/CA+TgmoYFJyJNQw3RT7veO3M2BWRE9Aw4hprC5rOcawHZti-f8g@mail.gmail.com
1 parent 8fa6b90 commit 9106904

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

doc/src/sgml/protocol.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,8 +1006,8 @@ SELCT 1/0;<!-- this typo is intentional -->
10061006
<para>
10071007
If successfully created, a named portal object lasts till the end of the
10081008
current transaction, unless explicitly destroyed. An unnamed portal is
1009-
destroyed at the end of the transaction, or as soon as the statement
1010-
specifying the unnamed portal as destination is processed to completion. (Note
1009+
destroyed at the end of the transaction, or as soon as the next Bind
1010+
statement specifying the unnamed portal as destination is issued. (Note
10111011
that a simple Query message also destroys the unnamed portal.) Named
10121012
portals must be explicitly closed before they can be redefined by another
10131013
Bind message, but this is not required for the unnamed portal.

src/backend/tcop/postgres.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,16 +2327,6 @@ exec_execute_message(const char *portal_name, long max_rows)
23272327
* message. The next protocol message will start a fresh timeout.
23282328
*/
23292329
disable_statement_timeout();
2330-
2331-
/*
2332-
* We completed fetching from an unnamed portal. There is no need
2333-
* for it beyond this point, so drop it now rather than wait for
2334-
* the next Bind message to do this cleanup. This ensures that
2335-
* the correct statement is logged when cleaning up temporary file
2336-
* usage.
2337-
*/
2338-
if (portal->name[0] == '\0')
2339-
PortalDrop(portal, false);
23402330
}
23412331

23422332
/* Send appropriate CommandComplete to client */

src/test/modules/test_misc/t/009_log_temp_files.pl

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
INSERT INTO foo(a) SELECT * FROM generate_series(1, 5000);
3030
});
3131

32-
note "unnamed portal: temporary file dropped under first SELECT query";
32+
note "unnamed portal: temporary file dropped under second SELECT query";
3333
my $log_offset = -s $node->logfile;
3434
$node->safe_psql(
3535
"postgres", qq{
@@ -39,23 +39,22 @@
3939
END;
4040
});
4141
ok( $node->log_contains(
42-
qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+SELECT a FROM foo ORDER BY a OFFSET \$1/s,
42+
qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+SELECT 'unnamed portal'/s,
4343
$log_offset),
4444
"unnamed portal");
4545

46-
note
47-
"bind and implicit transaction: temporary file dropped under single query";
46+
note "bind and implicit transaction: temporary file dropped without query";
4847
$log_offset = -s $node->logfile;
4948
$node->safe_psql(
5049
"postgres", qq{
5150
SELECT a FROM foo ORDER BY a OFFSET \$1 \\bind 4991 \\g
5251
});
53-
ok( $node->log_contains(
54-
qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+SELECT a FROM foo ORDER BY a OFFSET \$1/s,
55-
$log_offset),
56-
"bind and implicit transaction");
52+
ok( $node->log_contains(qr/LOG:\s+temporary file:/s, $log_offset),
53+
"bind and implicit transaction, temporary file removed");
54+
ok( !$node->log_contains(qr/STATEMENT:/s, $log_offset),
55+
"bind and implicit transaction, no statement logged");
5756

58-
note "named portal: temporary file dropped under first SELECT query";
57+
note "named portal: temporary file dropped under second SELECT query";
5958
$node->safe_psql(
6059
"postgres", qq{
6160
BEGIN;
@@ -65,11 +64,11 @@
6564
END;
6665
});
6766
ok( $node->log_contains(
68-
qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+SELECT a FROM foo ORDER BY a OFFSET \$1/s,
67+
qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+SELECT 'named portal'/s,
6968
$log_offset),
7069
"named portal");
7170

72-
note "pipelined query: temporary file dropped under first SELECT query";
71+
note "pipelined query: temporary file dropped under second SELECT query";
7372
$log_offset = -s $node->logfile;
7473
$node->safe_psql(
7574
"postgres", qq{
@@ -79,21 +78,21 @@
7978
\\endpipeline
8079
});
8180
ok( $node->log_contains(
82-
qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+SELECT a FROM foo ORDER BY a OFFSET \$1/s,
81+
qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+SELECT 'pipelined query'/s,
8382
$log_offset),
8483
"pipelined query");
8584

86-
note "parse and bind: temporary file dropped under SELECT query";
85+
note "parse and bind: temporary file dropped without query";
8786
$log_offset = -s $node->logfile;
8887
$node->safe_psql(
8988
"postgres", qq{
9089
SELECT a, a, a FROM foo ORDER BY a OFFSET \$1 \\parse p1
9190
\\bind_named p1 4993 \\g
9291
});
93-
ok( $node->log_contains(
94-
qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+SELECT a, a, a FROM foo ORDER BY a OFFSET \$1/s,
95-
$log_offset),
96-
"parse and bind");
92+
ok($node->log_contains(qr/LOG:\s+temporary file:/s, $log_offset),
93+
"parse and bind, temporary file removed");
94+
ok(!$node->log_contains(qr/STATEMENT:/s, $log_offset),
95+
"bind and bind, no statement logged");
9796

9897
note "simple query: temporary file dropped under SELECT query";
9998
$log_offset = -s $node->logfile;

0 commit comments

Comments
 (0)