Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Copyright (c) 2025-2026, PostgreSQL Global Development Group
 
# Check how temporary file removals and statement queries are associated
# in the server logs for various query sequences with the simple and
# extended query protocols.
 
use strict;
use warnings FATAL => 'all';
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;
 
# Initialize a new PostgreSQL test cluster
my $node = PostgreSQL::Test::Cluster->new('primary');
$node->init();
$node->append_conf(
    'postgresql.conf', qq(
work_mem = 64kB
log_temp_files = 0
debug_parallel_query = off
log_error_verbosity = default
));
$node->start;
 
# Setup table and populate with data
$node->safe_psql(
    "postgres", qq{
CREATE UNLOGGED TABLE foo(a int);
INSERT INTO foo(a) SELECT * FROM generate_series(1, 5000);
});
 
note "unnamed portal: temporary file dropped under second SELECT query";
my $log_offset = -s $node->logfile;
$node->safe_psql(
    "postgres", qq{
BEGIN;
SELECT a FROM foo ORDER BY a OFFSET \$1 \\bind 4990 \\g
SELECT 'unnamed portal';
END;
});
ok( $node->log_contains(
        qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+SELECT 'unnamed portal'/s,
        $log_offset),
    "unnamed portal");
 
note "bind and implicit transaction: temporary file dropped without query";
$log_offset = -s $node->logfile;
$node->safe_psql(
    "postgres", qq{
SELECT a FROM foo ORDER BY a OFFSET \$1 \\bind 4991 \\g
});
ok( $node->log_contains(qr/LOG:\s+temporary file:/s, $log_offset),
    "bind and implicit transaction, temporary file removed");
ok( !$node->log_contains(qr/STATEMENT:/s, $log_offset),
    "bind and implicit transaction, no statement logged");
 
note "named portal: temporary file dropped under second SELECT query";
$node->safe_psql(
    "postgres", qq{
BEGIN;
SELECT a FROM foo ORDER BY a OFFSET \$1 \\parse stmt
\\bind_named stmt 4999 \\g
SELECT 'named portal';
END;
});
ok( $node->log_contains(
        qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+SELECT 'named portal'/s,
        $log_offset),
    "named portal");
 
note "pipelined query: temporary file dropped under second SELECT query";
$log_offset = -s $node->logfile;
$node->safe_psql(
    "postgres", qq{
\\startpipeline
SELECT a FROM foo ORDER BY a OFFSET \$1 \\bind 4992 \\sendpipeline
SELECT 'pipelined query';
\\endpipeline
});
ok( $node->log_contains(
        qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+SELECT 'pipelined query'/s,
        $log_offset),
    "pipelined query");
 
note "parse and bind: temporary file dropped without query";
$log_offset = -s $node->logfile;
$node->safe_psql(
    "postgres", qq{
SELECT a, a, a FROM foo ORDER BY a OFFSET \$1 \\parse p1
\\bind_named p1 4993 \\g
});
ok($node->log_contains(qr/LOG:\s+temporary file:/s, $log_offset),
    "parse and bind, temporary file removed");
ok(!$node->log_contains(qr/STATEMENT:/s, $log_offset),
    "bind and bind, no statement logged");
 
note "simple query: temporary file dropped under SELECT query";
$log_offset = -s $node->logfile;
$node->safe_psql(
    "postgres", qq{
BEGIN;
SELECT a FROM foo ORDER BY a OFFSET 4994;
END;
});
ok( $node->log_contains(
        qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+SELECT a FROM foo ORDER BY a OFFSET 4994;/s,
        $log_offset),
    "simple query");
 
note "cursor: temporary file dropped under CLOSE";
$log_offset = -s $node->logfile;
$node->safe_psql(
    "postgres", qq{
BEGIN;
DECLARE mycur CURSOR FOR SELECT a FROM foo ORDER BY a OFFSET 4995;
FETCH 10 FROM mycur;
SELECT 1;
CLOSE mycur;
END;
});
ok( $node->log_contains(
        qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+CLOSE mycur;/s,
        $log_offset),
    "cursor");
 
note "cursor WITH HOLD: temporary file dropped under COMMIT";
$log_offset = -s $node->logfile;
$node->safe_psql(
    "postgres", qq{
BEGIN;
DECLARE holdcur CURSOR WITH HOLD FOR SELECT a FROM foo ORDER BY a OFFSET 4996;
FETCH 10 FROM holdcur;
COMMIT;
CLOSE holdcur;
});
ok( $node->log_contains(
        qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+COMMIT;/s,
        $log_offset),
    "cursor WITH HOLD");
 
note "prepare/execute: temporary file dropped under EXECUTE";
$log_offset = -s $node->logfile;
$node->safe_psql(
    "postgres", qq{
BEGIN;
PREPARE p1 AS SELECT a FROM foo ORDER BY a OFFSET 4997;
EXECUTE p1;
DEALLOCATE p1;
END;
});
ok( $node->log_contains(
        qr/LOG:\s+temporary file: path.*\n.*\ STATEMENT:\s+EXECUTE p1;/s,
        $log_offset),
    "prepare/execute");
 
$node->stop('fast');
done_testing();