Skip to content

Commit 3334c6e

Browse files
author
Arseny Kositsyn
committed
[PGPRO-11599] TIDBitmap added to rum.
Static functions from TIDBitmap were added to RUM as RumTIDBitmap. A function has been added to search for tid inside RumTIDBitmap. Tags: rum
1 parent 958a7a5 commit 3334c6e

File tree

9 files changed

+9544
-2
lines changed

9 files changed

+9544
-2
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ EXTENSION = rum
55
EXTVERSION = 1.3
66
PGFILEDESC = "RUM index access method"
77

8-
OBJS = src/rumsort.o src/rum_ts_utils.o src/rumtsquery.o \
8+
OBJS = src/rumtidbitmap.o src/rumsort.o src/rum_ts_utils.o src/rumtsquery.o \
99
src/rumbtree.o src/rumbulk.o src/rumdatapage.o \
1010
src/rumentrypage.o src/rumget.o src/ruminsert.o \
1111
src/rumscan.o src/rumutil.o src/rumvacuum.o src/rumvalidate.o \
@@ -16,7 +16,7 @@ DATA_updates = rum--1.0--1.1.sql rum--1.1--1.2.sql \
1616

1717
DATA_built = $(EXTENSION)--$(EXTVERSION).sql
1818

19-
INCLUDES = rum.h rumsort.h
19+
INCLUDES = rum.h rumsort.h rumtidbitmap.h
2020
RELATIVE_INCLUDES = $(addprefix src/, $(INCLUDES))
2121

2222
LDFLAGS_SL += $(filter -lm, $(LIBS))

src/rumtidbitmap.c

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* rumtidbitmap.c
4+
* PostgreSQL tuple-id (TID) bitmap package
5+
*
6+
* This module contains copies of static functions from
7+
* src/backend/nodes/tidbitmap.c, which are needed to store
8+
* and quickly search for tids.
9+
*
10+
* Portions Copyright (c) 2025, Postgres Professional
11+
*
12+
*-------------------------------------------------------------------------
13+
*/
14+
15+
#include "rumtidbitmap.h"
16+
17+
#if PG_VERSION_NUM >= 170000
18+
#include "tidbitmap17.c"
19+
#elif PG_VERSION_NUM >= 160000
20+
#include "tidbitmap16.c"
21+
#elif PG_VERSION_NUM >= 150000
22+
#include "tidbitmap15.c"
23+
#elif PG_VERSION_NUM >= 140000
24+
#include "tidbitmap14.c"
25+
#elif PG_VERSION_NUM >= 130000
26+
#include "tidbitmap13.c"
27+
#elif PG_VERSION_NUM >= 120000
28+
#include "tidbitmap12.c"
29+
#endif
30+
31+
RumTIDBitmap *
32+
rum_tbm_create(long maxbytes, dsa_area *dsa)
33+
{
34+
return tbm_create(maxbytes, dsa);
35+
}
36+
37+
void
38+
rum_tbm_free(RumTIDBitmap *tbm)
39+
{
40+
tbm_free(tbm);
41+
}
42+
43+
void
44+
rum_tbm_add_tuples(RumTIDBitmap *tbm,
45+
const ItemPointer tids,
46+
int ntids, bool recheck)
47+
{
48+
tbm_add_tuples(tbm, tids, ntids, recheck);
49+
}
50+
51+
void
52+
rum_tbm_add_page(RumTIDBitmap *tbm, BlockNumber pageno)
53+
{
54+
tbm_add_page(tbm, pageno);
55+
}
56+
57+
void
58+
rum_tbm_union(RumTIDBitmap *a, const RumTIDBitmap *b)
59+
{
60+
tbm_union(a, b);
61+
}
62+
63+
void rum_tbm_intersect(RumTIDBitmap *a, const RumTIDBitmap *b)
64+
{
65+
tbm_intersect(a, b);
66+
}
67+
68+
bool
69+
rum_tbm_is_empty(const RumTIDBitmap *tbm)
70+
{
71+
return tbm_is_empty(tbm);
72+
}
73+
74+
RumTBMIterator *
75+
rum_tbm_begin_iterate(RumTIDBitmap *tbm)
76+
{
77+
return tbm_begin_iterate(tbm);
78+
}
79+
80+
RumTBMIterateResult *
81+
rum_tbm_iterate(RumTBMIterator *iterator)
82+
{
83+
return tbm_iterate(iterator);
84+
}
85+
86+
void
87+
rum_tbm_end_iterate(RumTBMIterator *iterator)
88+
{
89+
tbm_end_iterate(iterator);
90+
}
91+
92+
long
93+
rum_tbm_calculate_entries(double maxbytes)
94+
{
95+
return tbm_calculate_entries(maxbytes);
96+
}
97+
98+
/*
99+
* The function is needed to search for tid inside RumTIDBitmap.
100+
* If the page is marked as lossy, it writes true to *recheck.
101+
*/
102+
bool
103+
rum_tbm_contains_tid(RumTIDBitmap *tbm, ItemPointer tid, bool *recheck)
104+
{
105+
BlockNumber blkn = ItemPointerGetBlockNumber(tid);
106+
OffsetNumber off = ItemPointerGetOffsetNumber(tid);
107+
108+
const PagetableEntry *page = NULL;
109+
110+
*recheck = false;
111+
112+
if (tbm_page_is_lossy(tbm, blkn))
113+
{
114+
*recheck = true;
115+
return true;
116+
}
117+
118+
else if ((page = tbm_find_pageentry(tbm, blkn)) != NULL)
119+
{
120+
int wn = WORDNUM(off - 1);
121+
int bn = BITNUM(off - 1);
122+
return (page->words[wn] & ((bitmapword) 1 << bn)) != 0;
123+
}
124+
125+
else
126+
return false;
127+
}

src/rumtidbitmap.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* rumtidbitmap.h
4+
* PostgreSQL tuple-id (TID) bitmap package
5+
*
6+
* This module contains copies of static functions from
7+
* src/backend/nodes/tidbitmap.c, which are needed to store
8+
* and quickly search for tids.
9+
*
10+
* Portions Copyright (c) 2025, Postgres Professional
11+
*
12+
*-------------------------------------------------------------------------
13+
*/
14+
#ifndef RUMTIDBITMAP_H
15+
#define RUMTIDBITMAP_H
16+
17+
#include "postgres.h"
18+
#include "nodes/tidbitmap.h"
19+
20+
typedef struct TIDBitmap RumTIDBitmap;
21+
22+
/* Likewise, RumTIDBitmap is private */
23+
typedef struct TBMIterator RumTBMIterator;
24+
25+
/* Result structure for rum_tbm_iterate */
26+
typedef struct TBMIterateResult RumTBMIterateResult;
27+
28+
/* function prototypes in rumtidbitmap.c */
29+
30+
extern RumTIDBitmap *rum_tbm_create(long maxbytes, dsa_area *dsa);
31+
extern void rum_tbm_free(RumTIDBitmap *tbm);
32+
33+
extern void rum_tbm_add_tuples(RumTIDBitmap *tbm,
34+
const ItemPointer tids, int ntids,
35+
bool recheck);
36+
extern void rum_tbm_add_page(RumTIDBitmap *tbm, BlockNumber pageno);
37+
38+
extern void rum_tbm_union(RumTIDBitmap *a, const RumTIDBitmap *b);
39+
extern void rum_tbm_intersect(RumTIDBitmap *a, const RumTIDBitmap *b);
40+
41+
extern bool rum_tbm_is_empty(const RumTIDBitmap *tbm);
42+
43+
extern RumTBMIterator *rum_tbm_begin_iterate(RumTIDBitmap *tbm);
44+
extern RumTBMIterateResult *rum_tbm_iterate(RumTBMIterator *iterator);
45+
extern void rum_tbm_end_iterate(RumTBMIterator *iterator);
46+
47+
extern long rum_tbm_calculate_entries(double maxbytes);
48+
49+
extern bool
50+
rum_tbm_contains_tid(RumTIDBitmap *tbm, ItemPointer tid, bool *recheck);
51+
52+
#endif /* RUMTIDBITMAP_H */

0 commit comments

Comments
 (0)