aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/rmgrdesc/brindesc.c
blob: 39135bf52e7225ff55e2fc35b7627bb10a9a3751 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*-------------------------------------------------------------------------
 *
 * brindesc.c
 *	  rmgr descriptor routines for BRIN indexes
 *
 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *	  src/backend/access/rmgrdesc/brindesc.c
 *
 *-------------------------------------------------------------------------
 */
#include "postgres.h"

#include "access/brin_xlog.h"

void
brin_desc(StringInfo buf, XLogRecord *record)
{
	char	   *rec = XLogRecGetData(record);
	uint8		info = record->xl_info & ~XLR_INFO_MASK;

	info &= XLOG_BRIN_OPMASK;
	if (info == XLOG_BRIN_CREATE_INDEX)
	{
		xl_brin_createidx *xlrec = (xl_brin_createidx *) rec;

		appendStringInfo(buf, "v%d pagesPerRange %u rel %u/%u/%u",
						 xlrec->version, xlrec->pagesPerRange,
						 xlrec->node.spcNode, xlrec->node.dbNode,
						 xlrec->node.relNode);
	}
	else if (info == XLOG_BRIN_INSERT)
	{
		xl_brin_insert *xlrec = (xl_brin_insert *) rec;

		appendStringInfo(buf, "rel %u/%u/%u heapBlk %u revmapBlk %u pagesPerRange %u TID (%u,%u)",
						 xlrec->node.spcNode, xlrec->node.dbNode,
						 xlrec->node.relNode,
						 xlrec->heapBlk, xlrec->revmapBlk,
						 xlrec->pagesPerRange,
						 ItemPointerGetBlockNumber(&xlrec->tid),
						 ItemPointerGetOffsetNumber(&xlrec->tid));
	}
	else if (info == XLOG_BRIN_UPDATE)
	{
		xl_brin_update *xlrec = (xl_brin_update *) rec;

		appendStringInfo(buf, "rel %u/%u/%u heapBlk %u revmapBlk %u pagesPerRange %u old TID (%u,%u) TID (%u,%u)",
						 xlrec->new.node.spcNode, xlrec->new.node.dbNode,
						 xlrec->new.node.relNode,
						 xlrec->new.heapBlk, xlrec->new.revmapBlk,
						 xlrec->new.pagesPerRange,
						 ItemPointerGetBlockNumber(&xlrec->oldtid),
						 ItemPointerGetOffsetNumber(&xlrec->oldtid),
						 ItemPointerGetBlockNumber(&xlrec->new.tid),
						 ItemPointerGetOffsetNumber(&xlrec->new.tid));
	}
	else if (info == XLOG_BRIN_SAMEPAGE_UPDATE)
	{
		xl_brin_samepage_update *xlrec = (xl_brin_samepage_update *) rec;

		appendStringInfo(buf, "rel %u/%u/%u TID (%u,%u)",
						 xlrec->node.spcNode, xlrec->node.dbNode,
						 xlrec->node.relNode,
						 ItemPointerGetBlockNumber(&xlrec->tid),
						 ItemPointerGetOffsetNumber(&xlrec->tid));
	}
	else if (info == XLOG_BRIN_REVMAP_EXTEND)
	{
		xl_brin_revmap_extend *xlrec = (xl_brin_revmap_extend *) rec;

		appendStringInfo(buf, "rel %u/%u/%u targetBlk %u",
						 xlrec->node.spcNode, xlrec->node.dbNode,
						 xlrec->node.relNode, xlrec->targetBlk);
	}
}

const char *
brin_identify(uint8 info)
{
	const char *id = NULL;

	switch (info & ~XLR_INFO_MASK)
	{
		case XLOG_BRIN_CREATE_INDEX:
			id = "CREATE_INDEX";
			break;
		case XLOG_BRIN_INSERT:
			id = "INSERT";
			break;
		case XLOG_BRIN_INSERT | XLOG_BRIN_INIT_PAGE:
			id = "INSERT+INIT";
			break;
		case XLOG_BRIN_UPDATE:
			id = "UPDATE";
			break;
		case XLOG_BRIN_UPDATE | XLOG_BRIN_INIT_PAGE:
			id = "UPDATE+INIT";
			break;
		case XLOG_BRIN_SAMEPAGE_UPDATE:
			id = "SAMEPAGE_UPDATE";
			break;
		case XLOG_BRIN_REVMAP_EXTEND:
			id = "REVMAP_EXTEND";
			break;
	}

	return id;
}