pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Masahiro Ikeda <ikedamsh@oss.nttdata.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Assertion failure in smgr.c when using pg_prewarm with partitioned tables
Date: Thu, 15 May 2025 17:52:06 +0900
Message-ID: <e082e6027610fd0a4091ae6d033aa117@oss.nttdata.com> (raw)

Hi,

I encountered an assertion failure when a partitioned table is specified
as an argument to pg_prewarm. Below are the steps to reproduce the 
issue:

$ pgbench -i -s 1 --partitions=3
$ psql <<EOF
CREATE EXTENSION pg_prewarm;
SELECT pg_prewarm('pgbench_accounts');
EOF

The following assertion failure occurs:

TRAP: failed Assert("RelFileNumberIsValid(rlocator.relNumber)"), File: 
"smgr.c", Line: 246, PID: 1246282
postgres: ikeda postgres [local] 
SELECT(ExceptionalCondition+0xbb)[0x55edd16725c1]
postgres: ikeda postgres [local] SELECT(smgropen+0x5e)[0x55edd145c1ff]


It looks like this may have been overlooked in commit 049ef33.
What do you think?

Regards,
-- 
Masahiro Ikeda
NTT DATA CORPORATION

Attachments:

v1-0001-Fix-assertion-failure-when-pg_prewarm-is-used-on-.patch (text/x-diff, 2.6K) download From 3c27152719f3bbc84d61dc136584f530a75e6da1 Mon Sep 17 00:00:00 2001 From: Masahiro Ikeda <ikedamsh@oss.nttdata.com> Date: Thu, 15 May 2025 17:26:27 +0900 Subject: [PATCH v1] Fix assertion failure when pg_prewarm is used on a partitioned table This issue was introduced by commit 049ef33. Specifying a partitioned table 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 | 3 ++- contrib/pg_prewarm/t/001_basic.pl | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/contrib/pg_prewarm/pg_prewarm.c b/contrib/pg_prewarm/pg_prewarm.c index 50808569bd7..94a36795130 100644 --- a/contrib/pg_prewarm/pg_prewarm.c +++ b/contrib/pg_prewarm/pg_prewarm.c @@ -113,7 +113,8 @@ pg_prewarm(PG_FUNCTION_ARGS) aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind), get_rel_name(relOid)); /* Check that the fork exists. */ - if (!smgrexists(RelationGetSmgr(rel), forkNumber)) + if (!RelFileNumberIsValid(rel->rd_locator.relNumber) || + !smgrexists(RelationGetSmgr(rel), forkNumber)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("fork \"%s\" does not exist for this relation", diff --git a/contrib/pg_prewarm/t/001_basic.pl b/contrib/pg_prewarm/t/001_basic.pl index 0a8259d3678..57a0134454b 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 =~ /fork "main" does not exist for this relation/, + 'detected the fork 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

view thread (18+ messages)  latest in thread

Message-ID: <e082e6027610fd0a4091ae6d033aa117@oss.nttdata.com>
Permalink:  ../e082e6027610fd0a4091ae6d033aa117@oss.nttdata.com/
Also on:    postgresql.org/message-id/e082e6027610fd0a4091ae6d033aa117@oss.nttdata.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: ikedamsh@oss.nttdata.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: Assertion failure in smgr.c when using pg_prewarm with partitioned tables
  In-Reply-To: <e082e6027610fd0a4091ae6d033aa117@oss.nttdata.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox