Skip to content

Commit 4c7cf69

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 4c7cf69

File tree

4 files changed

+1726
-2
lines changed

4 files changed

+1726
-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: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
#include "tidbitmap.c"
17+
18+
RumTIDBitmap *
19+
rum_tbm_create(long maxbytes, dsa_area *dsa)
20+
{
21+
return tbm_create(maxbytes, dsa);
22+
}
23+
24+
void
25+
rum_tbm_free(RumTIDBitmap *tbm)
26+
{
27+
tbm_free(tbm);
28+
}
29+
30+
void
31+
rum_tbm_add_tuples(RumTIDBitmap *tbm,
32+
const ItemPointer tids,
33+
int ntids, bool recheck)
34+
{
35+
tbm_add_tuples(tbm, tids, ntids, recheck);
36+
}
37+
38+
void
39+
rum_tbm_add_page(RumTIDBitmap *tbm, BlockNumber pageno)
40+
{
41+
tbm_add_page(tbm, pageno);
42+
}
43+
44+
void
45+
rum_tbm_union(RumTIDBitmap *a, const RumTIDBitmap *b)
46+
{
47+
tbm_union(a, b);
48+
}
49+
50+
void rum_tbm_intersect(RumTIDBitmap *a, const RumTIDBitmap *b)
51+
{
52+
tbm_intersect(a, b);
53+
}
54+
55+
bool
56+
rum_tbm_is_empty(const RumTIDBitmap *tbm)
57+
{
58+
return tbm_is_empty(tbm);
59+
}
60+
61+
RumTBMIterator *
62+
rum_tbm_begin_iterate(RumTIDBitmap *tbm)
63+
{
64+
return tbm_begin_iterate(tbm);
65+
}
66+
67+
RumTBMIterateResult *
68+
rum_tbm_iterate(RumTBMIterator *iterator)
69+
{
70+
return tbm_iterate(iterator);
71+
}
72+
73+
void
74+
rum_tbm_end_iterate(RumTBMIterator *iterator)
75+
{
76+
tbm_end_iterate(iterator);
77+
}
78+
79+
long
80+
rum_tbm_calculate_entries(double maxbytes)
81+
{
82+
return tbm_calculate_entries(maxbytes);
83+
}
84+
85+
/*
86+
* The function is needed to search for tid inside RumTIDBitmap.
87+
* If the page is marked as lossy, it writes true to *recheck.
88+
*/
89+
bool
90+
rum_tbm_contains_tid(RumTIDBitmap *tbm, ItemPointer tid, bool *recheck)
91+
{
92+
BlockNumber blkn = ItemPointerGetBlockNumber(tid);
93+
OffsetNumber off = ItemPointerGetOffsetNumber(tid);
94+
95+
const PagetableEntry *page = NULL;
96+
97+
*recheck = false;
98+
99+
if (tbm_page_is_lossy(tbm, blkn))
100+
{
101+
*recheck = true;
102+
return true;
103+
}
104+
105+
else if ((page = tbm_find_pageentry(tbm, blkn)) != NULL)
106+
{
107+
int wn = WORDNUM(off - 1);
108+
int bn = BITNUM(off - 1);
109+
return (page->words[wn] & ((bitmapword) 1 << bn)) != 0;
110+
}
111+
112+
else
113+
return false;
114+
}

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)