From a54ab438e911773f18409b2e2b951dc518d715e1 Mon Sep 17 00:00:00 2001 From: Pavel Borisov Date: Mon, 8 Feb 2021 11:57:49 +0400 Subject: [PATCH v1 2/2] Ignore unique constraint check on btree insert. Patch for testing unique constraint checking in amcheck. Used to construct btree index with violated unique constraint which is not generally possible. Also increase log level of some debug messages in btree amcheck. XXX Not for merge, testing only !!!! --- contrib/amcheck/verify_nbtree.c | 4 ++-- src/backend/access/nbtree/nbtinsert.c | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c index 8a5809f017e..b4f012f5214 100644 --- a/contrib/amcheck/verify_nbtree.c +++ b/contrib/amcheck/verify_nbtree.c @@ -1729,7 +1729,7 @@ bt_target_page_check(BtreeCheckState *state) */ if (state->indexinfo->ii_Unique && rightkey && P_ISLEAF(topaque)) { - elog(DEBUG2, "check cross page unique condition"); + elog(INFO, "check cross page unique condition"); /* * Make _bt_compare compare only index keys without heap TIDs. @@ -1741,7 +1741,7 @@ bt_target_page_check(BtreeCheckState *state) /* First key on next page is same */ if (_bt_compare(state->rel, rightkey, state->target, max) == 0) { - elog(DEBUG2, "cross page equal keys"); + elog(INFO, "cross page equal keys"); state->target = palloc_btree_page(state, state->targetblock + 1); topaque = (BTPageOpaque) PageGetSpecialPointer(state->target); diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c index e3336039125..ffbbf5c63e0 100644 --- a/src/backend/access/nbtree/nbtinsert.c +++ b/src/backend/access/nbtree/nbtinsert.c @@ -570,10 +570,15 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel, */ if (checkUnique == UNIQUE_CHECK_PARTIAL) { - if (nbuf != InvalidBuffer) - _bt_relbuf(rel, nbuf); - *is_unique = false; - return InvalidTransactionId; + /* FIXME Ugliest crutch to test amcheck */ + if (strcmp(RelationGetRelationName(rel), "idx") != 0) + { + if (nbuf != InvalidBuffer) + _bt_relbuf(rel, nbuf); + + *is_unique = false; + return InvalidTransactionId; + } } /* @@ -616,6 +621,9 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel, SnapshotSelf, NULL)) { /* Normal case --- it's still live */ + /* FIXME Ugliest crutch to test amcheck */ + if (strcmp(RelationGetRelationName(rel), "idx") == 0) + break; } else { -- 2.28.0