v28-0003-DEBUG-Show-index-values-in-pageinspect.patch
application/x-patch
Filename: v28-0003-DEBUG-Show-index-values-in-pageinspect.patch
Type: application/x-patch
Part: 0
Patch
Format: format-patch
Series: patch v28-0003
Subject: DEBUG: Show index values in pageinspect
| File | + | − |
|---|---|---|
| contrib/pageinspect/btreefuncs.c | 46 | 19 |
| contrib/pageinspect/expected/btree.out | 1 | 1 |
From 200899a4dfcdcdacc9a30cf87a1b311c97bd2000 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <pg@bowt.ie>
Date: Mon, 18 Nov 2019 19:35:30 -0800
Subject: [PATCH v28 3/3] DEBUG: Show index values in pageinspect
This is not intended for commit. It is included as a convenience for
reviewers.
---
contrib/pageinspect/btreefuncs.c | 65 ++++++++++++++++++--------
contrib/pageinspect/expected/btree.out | 2 +-
2 files changed, 47 insertions(+), 20 deletions(-)
diff --git a/contrib/pageinspect/btreefuncs.c b/contrib/pageinspect/btreefuncs.c
index 337047ff9d..c51e2b3665 100644
--- a/contrib/pageinspect/btreefuncs.c
+++ b/contrib/pageinspect/btreefuncs.c
@@ -27,6 +27,7 @@
#include "postgres.h"
+#include "access/genam.h"
#include "access/nbtree.h"
#include "access/relation.h"
#include "catalog/namespace.h"
@@ -245,6 +246,7 @@ bt_page_stats(PG_FUNCTION_ARGS)
*/
struct user_args
{
+ Relation rel;
Page page;
OffsetNumber offset;
bool leafpage;
@@ -261,6 +263,7 @@ struct user_args
static Datum
bt_page_print_tuples(FuncCallContext *fctx, struct user_args *uargs)
{
+ Relation rel = uargs->rel;
Page page = uargs->page;
OffsetNumber offset = uargs->offset;
bool leafpage = uargs->leafpage;
@@ -295,26 +298,48 @@ bt_page_print_tuples(FuncCallContext *fctx, struct user_args *uargs)
values[j++] = BoolGetDatum(IndexTupleHasVarwidths(itup));
ptr = (char *) itup + IndexInfoFindDataOffset(itup->t_info);
- dlen = IndexTupleSize(itup) - IndexInfoFindDataOffset(itup->t_info);
-
- /*
- * Make sure that "data" column does not include posting list or pivot
- * tuple representation of heap TID
- */
- if (BTreeTupleIsPosting(itup))
- dlen -= IndexTupleSize(itup) - BTreeTupleGetPostingOffset(itup);
- else if (BTreeTupleIsPivot(itup) && BTreeTupleGetHeapTID(itup) != NULL)
- dlen -= MAXALIGN(sizeof(ItemPointerData));
-
- dump = palloc0(dlen * 3 + 1);
- datacstring = dump;
- for (off = 0; off < dlen; off++)
+ if (rel)
{
- if (off > 0)
- *dump++ = ' ';
- sprintf(dump, "%02x", *(ptr + off) & 0xff);
- dump += 2;
+ TupleDesc itupdesc = RelationGetDescr(rel);
+ Datum datvalues[INDEX_MAX_KEYS];
+ bool isnull[INDEX_MAX_KEYS];
+ int natts;
+ int indnkeyatts = rel->rd_index->indnkeyatts;
+
+ natts = BTreeTupleGetNAtts(itup, rel);
+
+ itupdesc->natts = Min(indnkeyatts, natts);
+ memset(&isnull, 0xFF, sizeof(isnull));
+ index_deform_tuple(itup, itupdesc, datvalues, isnull);
+ rel->rd_index->indnkeyatts = natts;
+ datacstring = BuildIndexValueDescription(rel, datvalues, isnull);
+ itupdesc->natts = IndexRelationGetNumberOfAttributes(rel);
+ rel->rd_index->indnkeyatts = indnkeyatts;
}
+ else
+ {
+ dlen = IndexTupleSize(itup) - IndexInfoFindDataOffset(itup->t_info);
+
+ /*
+ * Make sure that "data" column does not include posting list or pivot
+ * tuple representation of heap TID
+ */
+ if (BTreeTupleIsPosting(itup))
+ dlen -= IndexTupleSize(itup) - BTreeTupleGetPostingOffset(itup);
+ else if (BTreeTupleIsPivot(itup) && BTreeTupleGetHeapTID(itup) != NULL)
+ dlen -= MAXALIGN(sizeof(ItemPointerData));
+
+ dump = palloc0(dlen * 3 + 1);
+ datacstring = dump;
+ for (off = 0; off < dlen; off++)
+ {
+ if (off > 0)
+ *dump++ = ' ';
+ sprintf(dump, "%02x", *(ptr + off) & 0xff);
+ dump += 2;
+ }
+ }
+
values[j++] = CStringGetTextDatum(datacstring);
pfree(datacstring);
@@ -437,11 +462,11 @@ bt_page_items(PG_FUNCTION_ARGS)
uargs = palloc(sizeof(struct user_args));
+ uargs->rel = rel;
uargs->page = palloc(BLCKSZ);
memcpy(uargs->page, BufferGetPage(buffer), BLCKSZ);
UnlockReleaseBuffer(buffer);
- relation_close(rel, AccessShareLock);
uargs->offset = FirstOffsetNumber;
@@ -475,6 +500,7 @@ bt_page_items(PG_FUNCTION_ARGS)
}
else
{
+ relation_close(uargs->rel, AccessShareLock);
pfree(uargs->page);
pfree(uargs);
SRF_RETURN_DONE(fctx);
@@ -522,6 +548,7 @@ bt_page_items_bytea(PG_FUNCTION_ARGS)
uargs = palloc(sizeof(struct user_args));
+ uargs->rel = NULL;
uargs->page = VARDATA(raw_page);
uargs->offset = FirstOffsetNumber;
diff --git a/contrib/pageinspect/expected/btree.out b/contrib/pageinspect/expected/btree.out
index 92d5c59654..fc6794ef65 100644
--- a/contrib/pageinspect/expected/btree.out
+++ b/contrib/pageinspect/expected/btree.out
@@ -41,7 +41,7 @@ ctid | (0,1)
itemlen | 16
nulls | f
vars | f
-data | 01 00 00 00 00 00 00 01
+data | (a)=(72057594037927937)
dead | f
htid | (0,1)
tids |
--
2.17.1