From 58793ef42536b9db18b35969ab28584505b0fcf3 Mon Sep 17 00:00:00 2001 From: Peter Geoghegan Date: Mon, 1 Oct 2018 16:09:28 -0700 Subject: [PATCH v6 4/6] DEBUG: Add page split instrumentation. LOGs details on the new left high key in the event of a leaf page split. This is an easy way to directly observe the effectiveness of suffix truncation as it happens, which was useful during development. The macro DEBUG_SPLITS must be defined (uncommented) for the instrumentation to be enabled. This patch is not proposed for inclusion in PostgreSQL; it's included for the convenience of reviewers. --- src/backend/access/nbtree/nbtinsert.c | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c index 2b2f3a0be3..5bfafc0892 100644 --- a/src/backend/access/nbtree/nbtinsert.c +++ b/src/backend/access/nbtree/nbtinsert.c @@ -26,6 +26,11 @@ #include "storage/smgr.h" #include "utils/tqual.h" +/* #define DEBUG_SPLITS */ +#ifdef DEBUG_SPLITS +#include "catalog/catalog.h" +#endif + /* Minimum tree height for application of fastpath optimization */ #define BTREE_FASTPATH_MIN_LEVEL 2 #define STACK_SPLIT_POINTS 15 @@ -1270,9 +1275,64 @@ _bt_split(Relation rel, Buffer buf, Buffer cbuf, OffsetNumber firstright, lefthikey = _bt_suffix_truncate(rel, lastleft, item); itemsz = IndexTupleSize(lefthikey); itemsz = MAXALIGN(itemsz); +#ifdef DEBUG_SPLITS + if (IsNormalProcessingMode() && !IsSystemRelation(rel)) + { + TupleDesc itupdesc = RelationGetDescr(rel); + Datum values[INDEX_MAX_KEYS]; + bool isnull[INDEX_MAX_KEYS]; + char *lastleftstr; + char *firstrightstr; + char *newstr; + + index_deform_tuple(lastleft, itupdesc, values, isnull); + lastleftstr = BuildIndexValueDescription(rel, values, isnull); + index_deform_tuple(item, itupdesc, values, isnull); + firstrightstr = BuildIndexValueDescription(rel, values, isnull); + index_deform_tuple(newitem, itupdesc, values, isnull); + newstr = BuildIndexValueDescription(rel, values, isnull); + + elog(LOG, "\"%s\" leaf block %u " + "last left %s first right %s " + "attributes truncated: %u from %u%s new item %s", + RelationGetRelationName(rel), BufferGetBlockNumber(buf), + lastleftstr, firstrightstr, + IndexRelationGetNumberOfKeyAttributes(rel) - BTreeTupleGetNAtts(lefthikey, rel), + IndexRelationGetNumberOfKeyAttributes(rel), + BTreeTupleGetHeapTID(lefthikey) != NULL ? " (heap TID added back)" : "", + newstr); + } +#endif } else + { lefthikey = item; +#ifdef DEBUG_SPLITS + if (IsNormalProcessingMode() && !IsSystemRelation(rel)) + { + TupleDesc itupdesc = RelationGetDescr(rel); + Datum values[INDEX_MAX_KEYS]; + bool isnull[INDEX_MAX_KEYS]; + char *newhighkey; + char *newstr; + + index_deform_tuple(lefthikey, itupdesc, values, isnull); + newhighkey = BuildIndexValueDescription(rel, values, isnull); + index_deform_tuple(newitem, itupdesc, values, isnull); + newstr = BuildIndexValueDescription(rel, values, isnull); + + elog(LOG, "\"%s\" internal block %u " + "new high key %s " + "attributes truncated: %u from %u%s new item %s", + RelationGetRelationName(rel), BufferGetBlockNumber(buf), + newhighkey, + IndexRelationGetNumberOfKeyAttributes(rel) - BTreeTupleGetNAtts(lefthikey, rel), + IndexRelationGetNumberOfKeyAttributes(rel), + BTreeTupleGetHeapTID(lefthikey) != NULL ? " (heap TID added back)" : "", + newstr); + } +#endif + } Assert(BTreeTupleGetNAtts(lefthikey, rel) > 0); Assert(BTreeTupleGetNAtts(lefthikey, rel) <= -- 2.17.1