Content-Length: 376675 | pFad | http://github.com/postgres/postgres/commit/b64c585fde77206ee54747f31035dde56eee6bf9

DE Fix assertion failure in pg_prewarm() on objects without storage. · postgres/postgres@b64c585 · GitHub
Skip to content

Commit b64c585

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 290e8ab commit b64c585

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
@@ -128,6 +128,14 @@ pg_prewarm(PG_FUNCTION_ARGS)
128128
if (aclresult != ACLCHECK_OK)
129129
aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind), get_rel_name(relOid));
130130

131+
/* Check that the relation has storage. */
132+
if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
133+
ereport(ERROR,
134+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
135+
errmsg("relation \"%s\" does not have storage",
136+
RelationGetRelationName(rel)),
137+
errdetail_relkind_not_supported(rel->rd_rel->relkind)));
138+
131139
/* Check that the fork exists. */
132140
if (!smgrexists(RelationGetSmgr(rel), forkNumber))
133141
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)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgres/postgres/commit/b64c585fde77206ee54747f31035dde56eee6bf9

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy