]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
amcheck: Fix missing allequalimage corruption report
authorFujii Masao <fujii@postgresql.org>
Fri, 12 Jun 2026 00:35:27 +0000 (09:35 +0900)
committerFujii Masao <fujii@postgresql.org>
Fri, 12 Jun 2026 00:39:19 +0000 (09:39 +0900)
When amcheck validates that a B-Tree metapage's allequalimage flag
matches _bt_allequalimage(), it could fail to report corruption
unless one of the index key columns used interval_ops. As a result,
pg_amcheck could silently miss this corruption on other opclasses,
incorrectly reporting the index as valid.

The mistake was that bt_index_check_callback() kept ereport(ERROR)
inside the loop that scans key attributes for INTERVAL_BTREE_FAM_OID,
even though that loop is only needed to decide whether to add
the interval-specific hint. This commit moves ereport() out of the loop
so allequalimage mismatches are always reported, while still emitting
the hint for affected interval indexes.

Back-patch to v18, where d70b17636dd introduced this regression
while moving the check into bt_index_check_callback().

Author: Chao Li <lic@highgo.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/011ACC9C-CB87-4160-ACE7-4ED57AB86E15@gmail.com
Backpatch-through: 18

contrib/amcheck/verify_nbtree.c

index 3de1c06c7cf2cc031a08abc4b3c9ade0997d256f..870954d11b83b5ba300eb860af022e2d6873c826 100644 (file)
@@ -336,14 +336,16 @@ bt_index_check_callback(Relation indrel, Relation heaprel, void *state, bool rea
                        if (indrel->rd_opfamily[i] == INTERVAL_BTREE_FAM_OID)
                        {
                                has_interval_ops = true;
-                               ereport(ERROR,
-                                               (errcode(ERRCODE_INDEX_CORRUPTED),
-                                                errmsg("index \"%s\" metapage incorrectly indicates that deduplication is safe",
-                                                               RelationGetRelationName(indrel)),
-                                                has_interval_ops
-                                                ? errhint("This is known of \"interval\" indexes last built on a version predating 2023-11.")
-                                                : 0));
+                               break;
                        }
+
+               ereport(ERROR,
+                               (errcode(ERRCODE_INDEX_CORRUPTED),
+                                errmsg("index \"%s\" metapage incorrectly indicates that deduplication is safe",
+                                               RelationGetRelationName(indrel)),
+                                has_interval_ops
+                                ? errhint("This is known of \"interval\" indexes last built on a version predating 2023-11.")
+                                : 0));
        }
 
        /* Check index, possibly against table it is an index on */