aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Geoghegan <pg@bowt.ie>2020-08-06 15:25:47 -0700
committerPeter Geoghegan <pg@bowt.ie>2020-08-06 15:25:47 -0700
commitbe9bdab983cfc44db1d7f8c06df7d7a7cbcb8128 (patch)
treee27caf037fe75249621dd843bc6b4cbc03d4901b
parent05dfb813245bf3b896b5317570a24a3d66e97a41 (diff)
downloadpostgresql-be9bdab983cfc44db1d7f8c06df7d7a7cbcb8128.tar.gz
postgresql-be9bdab983cfc44db1d7f8c06df7d7a7cbcb8128.zip
amcheck: Sanitize metapage's allequalimage field.
This will be helpful if it ever proves necessary to revoke an opclass's support for deduplication. Backpatch: 13-, where nbtree deduplication was introduced.
-rw-r--r--contrib/amcheck/verify_nbtree.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c
index e4d501a85d1..060600a556a 100644
--- a/contrib/amcheck/verify_nbtree.c
+++ b/contrib/amcheck/verify_nbtree.c
@@ -305,8 +305,20 @@ bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed,
errmsg("index \"%s\" lacks a main relation fork",
RelationGetRelationName(indrel))));
- /* Check index, possibly against table it is an index on */
+ /* Extract metadata from metapage, and sanitize it in passing */
_bt_metaversion(indrel, &heapkeyspace, &allequalimage);
+ if (allequalimage && !heapkeyspace)
+ ereport(ERROR,
+ (errcode(ERRCODE_INDEX_CORRUPTED),
+ errmsg("index \"%s\" metapage has equalimage field set on unsupported nbtree version",
+ RelationGetRelationName(indrel))));
+ if (allequalimage && !_bt_allequalimage(indrel, false))
+ ereport(ERROR,
+ (errcode(ERRCODE_INDEX_CORRUPTED),
+ errmsg("index \"%s\" metapage incorrectly indicates that deduplication is safe",
+ RelationGetRelationName(indrel))));
+
+ /* Check index, possibly against table it is an index on */
bt_check_every_level(indrel, heaprel, heapkeyspace, parentcheck,
heapallindexed, rootdescend);
}