-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitmap.h
More file actions
145 lines (115 loc) · 4.73 KB
/
Copy pathbitmap.h
File metadata and controls
145 lines (115 loc) · 4.73 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef _BITMAP_H_
#define _BITMAP_H_
#include <fmgr.h>
#include <time.h>
#include <common/relpath.h>
#include <access/amapi.h>
#include <access/itup.h>
#include <nodes/pathnodes.h>
#include <nodes/execnodes.h>
#include <access/htup_details.h>
#define BITMAP_MAGIC_NUMBER 0xDABC9876
#define BITMAP_NSTRATEGIES 1
#define BITMAP_EQUAL_PROC 1
#define BITMAP_METAPAGE_BLKNO 0
#define BITMAP_VALPAGE_START_BLKNO 1
#define MAX_DISTINCT ((BLCKSZ \
-MAXALIGN(SizeOfPageHeaderData) \
-MAXALIGN(sizeof(struct BitmapPageSpecData)) \
-MAXALIGN(offsetof(BitmapMetaPageData, startBlk)) \
) / sizeof(BlockNumber))
typedef struct BitmapMetaPageData
{
uint32 magic;
uint32 ndistinct; // number of distinct values, automatically increase until max distinct
BlockNumber startBlk[FLEXIBLE_ARRAY_MEMBER]; // index page by distinct vals index
} BitmapMetaPageData;
#define BitmapPageGetMeta(page) ((BitmapMetaPageData *) PageGetContents(page))
#define BITMAP_PAGE_META 0x01
#define BITMAP_PAGE_VALUE 0x02
#define BITMAP_PAGE_INDEX 0x03
#define BITMAP_PAGE_DELETED 0x01
typedef struct BitmapPageSpecData {
uint16 maxoff;
BlockNumber nextBlk;
uint16 pgtype;
uint16 flags;
} BitmapPageSpecData;
typedef BitmapPageSpecData *BitmapPageOpaque;
#define BitmapPageGetOpaque(page) \
((BitmapPageOpaque)PageGetSpecialPointer(page))
#define BitmapPageSetDeleted(page) (BitmapPageGetOpaque(page)->flags |= BITMAP_PAGE_DELETED)
#define BitmapPageDeleted(page) (BitmapPageGetOpaque(page)->flags & BITMAP_PAGE_DELETED)
typedef struct BitmapOptions {} BitmapOptions;
// at most 226 tule can be stored in 8K page
#define MAX_HEAP_TUPLE_PER_PAGE 226
#define MAX_BITS_32 (MAX_HEAP_TUPLE_PER_PAGE/32 + 1)
typedef struct BitmapTuple {
BlockNumber heapblk;
bits32 bm[MAX_BITS_32];
} BitmapTuple;
#define BitmapPageGetTuple(page, offset) \
((BitmapTuple *)(PageGetContents(page) + sizeof(struct BitmapTuple) * (offset - 1)))
typedef struct BitmapState
{
uint32 ndistinct;
BlockNumber startBlk;
BlockNumber *blocks;
MemoryContext tmpCxt;
} BitmapState;
typedef struct BitmapBuildState
{
int64 indtuples;
uint32 ndistinct;
BlockNumber *startBlks;
BlockNumber *prevBlks;
MemoryContext tmpCtx;
PGAlignedBlock **blocks;
} BitmapBuildState;
typedef struct BitmapScanOpaqueData
{
int32 keyIndex;
Page curPage;
BlockNumber curBlk;
OffsetNumber offset;
OffsetNumber maxoffset;
int32 htupidx;
} BitmapScanOpaqueData;
typedef BitmapScanOpaqueData *BitmapScanOpaque;
extern bytea *bmoptions(Datum reloptions, bool validate);
extern bool bminsert(Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid,
Relation heapRel, IndexUniqueCheck checkUnique,
bool indexUnchanged, IndexInfo *indexInfo);
extern IndexBuildResult *bmbuild(Relation heap, Relation index,
IndexInfo *indexInfo);
extern void bmbuildempty(Relation index);
extern bool bmvalidate(Oid opclassoid);
extern IndexScanDesc bmbeginscan(Relation r, int nkeys, int norderbys);
extern void bmrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
ScanKey orderbys, int norderbys);
extern void bmendscan(IndexScanDesc scan);
extern bool bmgettuple(IndexScanDesc scan, ScanDirection dir);
extern int64 bmgetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
extern void bmcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
Cost *indexStartupCost, Cost *indexTotalCost,
Selectivity *indexSelectivity, double *indexCorrelation,
double *indexPages);
extern IndexBulkDeleteResult *bmbulkdelete(IndexVacuumInfo *info,
IndexBulkDeleteResult *stats,
IndexBulkDeleteCallback callback,
void *callback_state);
extern IndexBulkDeleteResult *bmvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats);
extern bool bm_page_add_tup(Page page, BitmapTuple *tuple, bool *inserted);
extern int bm_insert_val(Relation index, Datum *values, bool *isnull);
extern int bm_get_val_index(Relation index, Datum *values, bool *isnull);
extern Buffer bm_newbuffer_locked(Relation index);
extern void bm_init_page(Page page, uint16 pgtype);
extern void bm_init_metapage(Relation index, ForkNumber fork);
extern void bm_init_valuepage(Relation index, ForkNumber fork);
extern void bm_flush_cached(Relation index, BitmapBuildState *state);
extern BitmapMetaPageData* bm_get_meta(Relation index);
extern BitmapTuple *bitmap_form_tuple(ItemPointer ctid);
extern bool bm_vals_equal(Relation index, Datum *cmpVals, bool *cmpIsnull, IndexTuple itup);
extern int bm_tuple_to_tids(BitmapTuple *tup, ItemPointer tids);
extern int bm_tuple_next_htpid(BitmapTuple *tup, ItemPointer tid, int start);
#endif