v2-0001-Fix-assertion-failure-when-pg_prewarm-is-run-on-o.patch
text/x-diff
Filename: v2-0001-Fix-assertion-failure-when-pg_prewarm-is-run-on-o.patch
Type: text/x-diff
Part: 1
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v2-0001
Subject: Fix assertion failure when pg_prewarm() is run on objects that don't have storage.
| File | + | − |
|---|---|---|
| contrib/pg_prewarm/pg_prewarm.c | 8 | 0 |
| contrib/pg_prewarm/t/001_basic.pl | 10 | 1 |
From db240142ab4de334ef072f6af59a792701e806c5 Mon Sep 17 00:00:00 2001
From: Masahiro Ikeda <ikedamsh@oss.nttdata.com>
Date: Fri, 16 May 2025 14:35:32 +0900
Subject: [PATCH v2 1/2] Fix assertion failure when pg_prewarm() is run on
objects that don't have storage.
This issue was introduced by commit 049ef33.
Specifying objects that don't have storage as an argument to
pg_prewarm() could trigger an assertion failure:
Failed Assert("RelFileNumberIsValid(rlocator.relNumber)")
This fix ensures that such cases are handled appropriately.
---
contrib/pg_prewarm/pg_prewarm.c | 8 ++++++++
contrib/pg_prewarm/t/001_basic.pl | 11 ++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/contrib/pg_prewarm/pg_prewarm.c b/contrib/pg_prewarm/pg_prewarm.c
index 50808569bd7..1f89c9adc86 100644
--- a/contrib/pg_prewarm/pg_prewarm.c
+++ b/contrib/pg_prewarm/pg_prewarm.c
@@ -112,6 +112,14 @@ pg_prewarm(PG_FUNCTION_ARGS)
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind), get_rel_name(relOid));
+ /* Check that the storage exists. */
+ if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("relation \"%s\" does not have storage",
+ RelationGetRelationName(rel)),
+ errdetail_relkind_not_supported(rel->rd_rel->relkind)));
+
/* Check that the fork exists. */
if (!smgrexists(RelationGetSmgr(rel), forkNumber))
ereport(ERROR,
diff --git a/contrib/pg_prewarm/t/001_basic.pl b/contrib/pg_prewarm/t/001_basic.pl
index 0a8259d3678..f7c31ae60a8 100644
--- a/contrib/pg_prewarm/t/001_basic.pl
+++ b/contrib/pg_prewarm/t/001_basic.pl
@@ -23,7 +23,10 @@ $node->start;
$node->safe_psql("postgres",
"CREATE EXTENSION pg_prewarm;\n"
. "CREATE TABLE test(c1 int);\n"
- . "INSERT INTO test SELECT generate_series(1, 100);");
+ . "INSERT INTO test SELECT generate_series(1, 100);\n"
+ . "CREATE TABLE test_part(c1 int) PARTITION BY RANGE (c1);\n"
+ . "CREATE TABLE test_part1 PARTITION OF test_part FOR VALUES FROM (1) TO (1000);\n"
+ . "INSERT INTO test_part SELECT generate_series(1, 100);");
# test read mode
my $result =
@@ -42,6 +45,12 @@ ok( ( $stdout =~ qr/^[1-9][0-9]*$/
or $stderr =~ qr/prefetch is not supported by this build/),
'prefetch mode succeeded');
+# test partition table
+($cmdret, $stdout, $stderr) =
+ $node->psql("postgres", "SELECT pg_prewarm('test_part', 'buffer');");
+ok( $stderr =~ /relation "test_part" does not have storage/,
+ 'detected storage does not exist');
+
# test autoprewarm_dump_now()
$result = $node->safe_psql("postgres", "SELECT autoprewarm_dump_now();");
like($result, qr/^[1-9][0-9]*$/, 'autoprewarm_dump_now succeeded');
--
2.34.1