Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1fd981f

Browse files
michaelpqsamimseihmcadariu
committed
Drop unnamed portal immediately after execution to completion
Previously, unnamed portals were kept until the next Bind message or theend of the transaction. This could cause temporary files to persistlonger than expected and make logging not reflect the actual SQLresponsible for the temporary file.This patch changes exec_execute_message() to drop unnamed portalsimmediately after execution to completion at the end of an Executemessage, making their removal more aggressive. This forces temporaryfile cleanups to happen at the same time as the completion of the portalexecution, with statement logging correctly reflecting to whichstatements these temporary files were attached to (see the diffs in theTAP test updated by this commit for an idea).The documentation is updated to describe the lifetime of unnamedportals, and test cases are updated to verify temporary file removal andproper statement logging after unnamed portal execution. This changeshow unnamed portals are handled in the protocol, hence no backpatch isdone.Author: Frédéric Yhuel <frederic.yhuel@dalibo.com>Co-Authored-by: Sami Imseih <samimseih@gmail.com>Co-Authored-by: Mircea Cadariu <cadariu.mircea@gmail.com>Discussion:https://postgr.es/m/CAA5RZ0tTrTUoEr3kDXCuKsvqYGq8OOHiBwoD-dyJocq95uEOTQ%40mail.gmail.com
1 parent59dec6c commit1fd981f

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
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 thenext Bind
1010-
statementspecifying the unnamed portal as destination isissued. (Note
1009+
destroyed at the end of the transaction, or as soon as thestatement
1010+
specifying the unnamed portal as destination isprocessed to completion. (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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,16 @@ 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);
23302340
}
23312341

23322342
/* Send appropriate CommandComplete to client */

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

Lines changed: 17 additions & 16 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 undersecond SELECT query";
32+
note"unnamed portal: temporary file dropped underfirst SELECT query";
3333
my$log_offset =-s$node->logfile;
3434
$node->safe_psql(
3535
"postgres",qq{
@@ -39,22 +39,23 @@
3939
END;
4040
});
4141
ok($node->log_contains(
42-
qr/LOG:\s+temporary file: path.*\n.*\STATEMENT:\s+SELECT'unnamed portal'/s,
42+
qr/LOG:\s+temporary file: path.*\n.*\STATEMENT:\s+SELECTa FROM foo ORDER BY a OFFSET\$1/s,
4343
$log_offset),
4444
"unnamed portal");
4545

46-
note"bind and implicit transaction: temporary file dropped without query";
46+
note
47+
"bind and implicit transaction: temporary file dropped under single query";
4748
$log_offset =-s$node->logfile;
4849
$node->safe_psql(
4950
"postgres",qq{
5051
SELECT a FROM foo ORDER BY a OFFSET\$1\\bind 4991\\g
5152
});
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");
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");
5657

57-
note"named portal: temporary file dropped undersecond SELECT query";
58+
note"named portal: temporary file dropped underfirst SELECT query";
5859
$node->safe_psql(
5960
"postgres",qq{
6061
BEGIN;
@@ -64,11 +65,11 @@
6465
END;
6566
});
6667
ok($node->log_contains(
67-
qr/LOG:\s+temporary file: path.*\n.*\STATEMENT:\s+SELECT'named portal'/s,
68+
qr/LOG:\s+temporary file: path.*\n.*\STATEMENT:\s+SELECTa FROM foo ORDER BY a OFFSET\$1/s,
6869
$log_offset),
6970
"named portal");
7071

71-
note"pipelined query: temporary file dropped undersecond SELECT query";
72+
note"pipelined query: temporary file dropped underfirst SELECT query";
7273
$log_offset =-s$node->logfile;
7374
$node->safe_psql(
7475
"postgres",qq{
@@ -78,21 +79,21 @@
7879
\\endpipeline
7980
});
8081
ok($node->log_contains(
81-
qr/LOG:\s+temporary file: path.*\n.*\STATEMENT:\s+SELECT'pipelined query'/s,
82+
qr/LOG:\s+temporary file: path.*\n.*\STATEMENT:\s+SELECTa FROM foo ORDER BY a OFFSET\$1/s,
8283
$log_offset),
8384
"pipelined query");
8485

85-
note"parse and bind: temporary file droppedwithout query";
86+
note"parse and bind: temporary file droppedunder SELECT query";
8687
$log_offset =-s$node->logfile;
8788
$node->safe_psql(
8889
"postgres",qq{
8990
SELECT a, a, a FROM foo ORDER BY a OFFSET\$1\\parse p1
9091
\\bind_named p1 4993\\g
9192
});
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");
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");
9697

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp