PostgreSQL Source Code  git master
test_ginpostinglist.c File Reference
#include "postgres.h"
#include "access/gin_private.h"
#include "access/ginblock.h"
#include "access/htup_details.h"
#include "fmgr.h"
Include dependency graph for test_ginpostinglist.c:

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (test_ginpostinglist)
 
static void test_itemptr_pair (BlockNumber blk, OffsetNumber off, int maxsize)
 
Datum test_ginpostinglist (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( test_ginpostinglist  )

◆ test_ginpostinglist()

Datum test_ginpostinglist ( PG_FUNCTION_ARGS  )

Definition at line 88 of file test_ginpostinglist.c.

89 {
90  test_itemptr_pair(0, 2, 14);
94 
96 }
#define MaxBlockNumber
Definition: block.h:35
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define MaxHeapTuplesPerPage
Definition: htup_details.h:572
static void test_itemptr_pair(BlockNumber blk, OffsetNumber off, int maxsize)

References MaxBlockNumber, MaxHeapTuplesPerPage, PG_RETURN_VOID, and test_itemptr_pair().

◆ test_itemptr_pair()

static void test_itemptr_pair ( BlockNumber  blk,
OffsetNumber  off,
int  maxsize 
)
static

Definition at line 41 of file test_ginpostinglist.c.

42 {
43  ItemPointerData orig_itemptrs[2];
44  ItemPointer decoded_itemptrs;
45  GinPostingList *pl;
46  int nwritten;
47  int ndecoded;
48 
49  elog(NOTICE, "testing with (%u, %d), (%u, %d), max %d bytes",
50  0, 1, blk, off, maxsize);
51  ItemPointerSet(&orig_itemptrs[0], 0, 1);
52  ItemPointerSet(&orig_itemptrs[1], blk, off);
53 
54  /* Encode, and decode it back */
55  pl = ginCompressPostingList(orig_itemptrs, 2, maxsize, &nwritten);
56  elog(NOTICE, "encoded %d item pointers to %zu bytes",
57  nwritten, SizeOfGinPostingList(pl));
58 
59  if (SizeOfGinPostingList(pl) > maxsize)
60  elog(ERROR, "overflow: result was %zu bytes, max %d",
61  SizeOfGinPostingList(pl), maxsize);
62 
63  decoded_itemptrs = ginPostingListDecode(pl, &ndecoded);
64  if (nwritten != ndecoded)
65  elog(NOTICE, "encoded %d itemptrs, %d came back", nwritten, ndecoded);
66 
67  /* Check the result */
68  if (!ItemPointerEquals(&orig_itemptrs[0], &decoded_itemptrs[0]))
69  elog(ERROR, "mismatch on first itemptr: (%u, %d) vs (%u, %d)",
70  0, 1,
71  ItemPointerGetBlockNumber(&decoded_itemptrs[0]),
72  ItemPointerGetOffsetNumber(&decoded_itemptrs[0]));
73 
74  if (ndecoded == 2 &&
75  !ItemPointerEquals(&orig_itemptrs[0], &decoded_itemptrs[0]))
76  {
77  elog(ERROR, "mismatch on second itemptr: (%u, %d) vs (%u, %d)",
78  0, 1,
79  ItemPointerGetBlockNumber(&decoded_itemptrs[0]),
80  ItemPointerGetOffsetNumber(&decoded_itemptrs[0]));
81  }
82 }
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define NOTICE
Definition: elog.h:35
#define SizeOfGinPostingList(plist)
Definition: ginblock.h:342
GinPostingList * ginCompressPostingList(const ItemPointer ipd, int nipd, int maxsize, int *nwritten)
ItemPointer ginPostingListDecode(GinPostingList *plist, int *ndecoded_out)
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:35
static void ItemPointerSet(ItemPointerData *pointer, BlockNumber blockNumber, OffsetNumber offNum)
Definition: itemptr.h:135
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
Definition: itemptr.h:124
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
Definition: itemptr.h:103

References elog, ERROR, ginCompressPostingList(), ginPostingListDecode(), ItemPointerEquals(), ItemPointerGetBlockNumber(), ItemPointerGetOffsetNumber(), ItemPointerSet(), NOTICE, and SizeOfGinPostingList.

Referenced by test_ginpostinglist().

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 20 of file test_ginpostinglist.c.