Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a4f23f9

Browse files
committed
pg_amcheck: Minor test speedups
Freezing the relation N times and fetching the tuples one-by-one isn't that cheap. On my machine this reduces test times by a bit less than one second, on windows CI it's a few seconds. Reviewed-by: Mark Dilger <mark.dilger@enterprisedb.com> Discussion: https://postgr.es/m/20230309001558.b7shzvio645ebdta@awork3.anarazel.de
1 parent 4f5d461 commit a4f23f9

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/bin/pg_amcheck/t/004_verify_heapam.pl

+15-18
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,17 @@ sub write_tuple
217217
my $relpath = "$pgdata/$rel";
218218

219219
# Insert data and freeze public.test
220-
use constant ROWCOUNT => 17;
220+
my $ROWCOUNT = 17;
221221
$node->safe_psql(
222222
'postgres', qq(
223223
INSERT INTO public.test (a, b, c)
224-
VALUES (
224+
SELECT
225225
x'DEADF9F9DEADF9F9'::bigint,
226226
'abcdefg',
227227
repeat('w', 10000)
228-
);
229-
VACUUM FREEZE public.test
230-
)) for (1 .. ROWCOUNT);
228+
FROM generate_series(1, $ROWCOUNT);
229+
VACUUM FREEZE public.test;)
230+
);
231231

232232
my $relfrozenxid = $node->safe_psql('postgres',
233233
q(select relfrozenxid from pg_class where relname = 'test'));
@@ -246,16 +246,13 @@ sub write_tuple
246246
}
247247

248248
# Find where each of the tuples is located on the page.
249-
my @lp_off;
250-
for my $tup (0 .. ROWCOUNT - 1)
251-
{
252-
push(
253-
@lp_off,
254-
$node->safe_psql(
255-
'postgres', qq(
256-
select lp_off from heap_page_items(get_raw_page('test', 'main', 0))
257-
offset $tup limit 1)));
258-
}
249+
my @lp_off = split '\n', $node->safe_psql(
250+
'postgres', qq(
251+
select lp_off from heap_page_items(get_raw_page('test', 'main', 0))
252+
where lp <= $ROWCOUNT
253+
)
254+
);
255+
is(scalar @lp_off, $ROWCOUNT, "acquired row offsets");
259256

260257
# Sanity check that our 'test' table on disk layout matches expectations. If
261258
# this is not so, we will have to skip the test until somebody updates the test
@@ -267,7 +264,7 @@ sub write_tuple
267264
binmode $file;
268265

269266
my $ENDIANNESS;
270-
for (my $tupidx = 0; $tupidx < ROWCOUNT; $tupidx++)
267+
for (my $tupidx = 0; $tupidx < $ROWCOUNT; $tupidx++)
271268
{
272269
my $offnum = $tupidx + 1; # offnum is 1-based, not zero-based
273270
my $offset = $lp_off[$tupidx];
@@ -345,7 +342,7 @@ sub header
345342
or BAIL_OUT("open failed: $!");
346343
binmode $file;
347344

348-
for (my $tupidx = 0; $tupidx < ROWCOUNT; $tupidx++)
345+
for (my $tupidx = 0; $tupidx < $ROWCOUNT; $tupidx++)
349346
{
350347
my $offnum = $tupidx + 1; # offnum is 1-based, not zero-based
351348
my $offset = $lp_off[$tupidx];
@@ -522,7 +519,7 @@ sub header
522519
$tup->{t_infomask} &= ~HEAP_XMIN_INVALID;
523520

524521
push @expected,
525-
qr/${$header}xmin ${xmin} equals or exceeds next valid transaction ID 0:\d+/;
522+
qr/${$header}xmin ${xmin} equals or exceeds next valid transaction ID 0:\d+/;
526523
}
527524
write_tuple($file, $offset, $tup);
528525
}

0 commit comments

Comments
 (0)