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

Commit 3c4d755

Browse files
committed
Fix assertion failure in pg_prewarm() on objects without storage.
An assertion test added in commit 049ef33 could fail when pg_prewarm() was called on objects without storage, such as partitioned tables. This resulted in the following failure in assert-enabled builds: Failed Assert("RelFileNumberIsValid(rlocator.relNumber)") Note that, in non-assert builds, pg_prewarm() just failed with an error in that case, so there was no ill effect in practice. This commit fixes the issue by having pg_prewarm() raise an error early if the specified object has no storage. This approach is similar to the fix in commit 4623d71 for pg_freespacemap. Back-patched to v17, where the issue was introduced. Author: Masahiro Ikeda <ikedamsh@oss.nttdata.com> Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com> Reviewed-by: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Fujii Masao <masao.fujii@gmail.com> Discussion: https://postgr.es/m/e082e6027610fd0a4091ae6d033aa117@oss.nttdata.com Backpatch-through: 17
1 parent c362370 commit 3c4d755

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

contrib/pg_prewarm/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ EXTENSION = pg_prewarm
1010
DATA = pg_prewarm--1.1--1.2.sql pg_prewarm--1.1.sql pg_prewarm--1.0--1.1.sql
1111
PGFILEDESC = "pg_prewarm - preload relation data into system buffer cache"
1212

13+
REGRESS = pg_prewarm
14+
1315
TAP_TESTS = 1
1416

1517
ifdef USE_PGXS
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Test pg_prewarm extension
2+
CREATE EXTENSION pg_prewarm;
3+
-- pg_prewarm() should fail if the target relation has no storage.
4+
CREATE TABLE test (c1 int) PARTITION BY RANGE (c1);
5+
SELECT pg_prewarm('test', 'buffer');
6+
ERROR: relation "test" does not have storage
7+
DETAIL: This operation is not supported for partitioned tables.
8+
-- Cleanup
9+
DROP TABLE test;
10+
DROP EXTENSION pg_prewarm;

contrib/pg_prewarm/meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ tests += {
2929
'name': 'pg_prewarm',
3030
'sd': meson.current_source_dir(),
3131
'bd': meson.current_build_dir(),
32+
'regress': {
33+
'sql': [
34+
'pg_prewarm',
35+
],
36+
},
3237
'tap': {
3338
'tests': [
3439
't/001_basic.pl',

contrib/pg_prewarm/pg_prewarm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ pg_prewarm(PG_FUNCTION_ARGS)
112112
if (aclresult != ACLCHECK_OK)
113113
aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind), get_rel_name(relOid));
114114

115+
/* Check that the relation has storage. */
116+
if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
117+
ereport(ERROR,
118+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
119+
errmsg("relation \"%s\" does not have storage",
120+
RelationGetRelationName(rel)),
121+
errdetail_relkind_not_supported(rel->rd_rel->relkind)));
122+
115123
/* Check that the fork exists. */
116124
if (!smgrexists(RelationGetSmgr(rel), forkNumber))
117125
ereport(ERROR,

contrib/pg_prewarm/sql/pg_prewarm.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Test pg_prewarm extension
2+
CREATE EXTENSION pg_prewarm;
3+
4+
-- pg_prewarm() should fail if the target relation has no storage.
5+
CREATE TABLE test (c1 int) PARTITION BY RANGE (c1);
6+
SELECT pg_prewarm('test', 'buffer');
7+
8+
-- Cleanup
9+
DROP TABLE test;
10+
DROP EXTENSION pg_prewarm;

0 commit comments

Comments
 (0)