aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/pageinspect/brinfuncs.c17
-rw-r--r--contrib/pageinspect/expected/oldextversions.out14
-rw-r--r--contrib/pageinspect/sql/oldextversions.sql9
3 files changed, 40 insertions, 0 deletions
diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c
index 22621d584fa..6f719352dda 100644
--- a/contrib/pageinspect/brinfuncs.c
+++ b/contrib/pageinspect/brinfuncs.c
@@ -117,6 +117,8 @@ verify_brin_page(bytea *raw_page, uint16 type, const char *strtype)
return page;
}
+/* Number of output arguments (columns) for brin_page_items() */
+#define BRIN_PAGE_ITEMS_V1_12 8
/*
* Extract all item values from a BRIN index page
@@ -145,6 +147,21 @@ brin_page_items(PG_FUNCTION_ARGS)
InitMaterializedSRF(fcinfo, 0);
+ /*
+ * Version 1.12 added a new output column for the empty range flag. But as
+ * it was added in the middle, it may cause crashes with function
+ * definitions from older versions of the extension.
+ *
+ * There is no way to reliably avoid the problems created by the old
+ * function definition at this point, so insist that the user update the
+ * extension.
+ */
+ if (rsinfo->setDesc->natts < BRIN_PAGE_ITEMS_V1_12)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("function has wrong number of declared columns"),
+ errhint("To resolve the problem, update the \"pageinspect\" extension to the latest version.")));
+
indexRel = index_open(indexRelid, AccessShareLock);
if (!IS_BRIN(indexRel))
diff --git a/contrib/pageinspect/expected/oldextversions.out b/contrib/pageinspect/expected/oldextversions.out
index f5c4b61bd79..2910891ece7 100644
--- a/contrib/pageinspect/expected/oldextversions.out
+++ b/contrib/pageinspect/expected/oldextversions.out
@@ -52,5 +52,19 @@ SELECT pagesize, version FROM page_header(get_raw_page('test1', 0));
8192 | 4
(1 row)
+-- brin_page_items() added a new "empty" flag in 1.12, make sure we detect
+-- an old function definition
+ALTER EXTENSION pageinspect UPDATE TO '1.11';
+CREATE INDEX test_1_a_brin_idx ON test1 USING BRIN (a);
+SELECT * FROM brin_page_items(get_raw_page('test_1_a_brin_idx', 2), 'test_1_a_brin_idx');
+ERROR: function has wrong number of declared columns
+HINT: To resolve the problem, update the "pageinspect" extension to the latest version.
+ALTER EXTENSION pageinspect UPDATE TO '1.12';
+SELECT * FROM brin_page_items(get_raw_page('test_1_a_brin_idx', 2), 'test_1_a_brin_idx');
+ itemoffset | blknum | attnum | allnulls | hasnulls | placeholder | empty | value
+------------+--------+--------+----------+----------+-------------+-------+------------------------------------------
+ 1 | 0 | 1 | f | f | f | f | {72057594037927937 .. 72057594037927937}
+(1 row)
+
DROP TABLE test1;
DROP EXTENSION pageinspect;
diff --git a/contrib/pageinspect/sql/oldextversions.sql b/contrib/pageinspect/sql/oldextversions.sql
index 9f953492c23..44f564faec9 100644
--- a/contrib/pageinspect/sql/oldextversions.sql
+++ b/contrib/pageinspect/sql/oldextversions.sql
@@ -22,5 +22,14 @@ ALTER EXTENSION pageinspect UPDATE TO '1.9';
\df page_header
SELECT pagesize, version FROM page_header(get_raw_page('test1', 0));
+-- brin_page_items() added a new "empty" flag in 1.12, make sure we detect
+-- an old function definition
+ALTER EXTENSION pageinspect UPDATE TO '1.11';
+CREATE INDEX test_1_a_brin_idx ON test1 USING BRIN (a);
+SELECT * FROM brin_page_items(get_raw_page('test_1_a_brin_idx', 2), 'test_1_a_brin_idx');
+
+ALTER EXTENSION pageinspect UPDATE TO '1.12';
+SELECT * FROM brin_page_items(get_raw_page('test_1_a_brin_idx', 2), 'test_1_a_brin_idx');
+
DROP TABLE test1;
DROP EXTENSION pageinspect;