PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tidbitmap.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * tidbitmap.h
4 * PostgreSQL tuple-id (TID) bitmap package
5 *
6 * This module provides bitmap data structures that are spiritually
7 * similar to Bitmapsets, but are specially adapted to store sets of
8 * tuple identifiers (TIDs), or ItemPointers. In particular, the division
9 * of an ItemPointer into BlockNumber and OffsetNumber is catered for.
10 * Also, since we wish to be able to store very large tuple sets in
11 * memory with this data structure, we support "lossy" storage, in which
12 * we no longer remember individual tuple offsets on a page but only the
13 * fact that a particular page needs to be visited.
14 *
15 *
16 * Copyright (c) 2003-2025, PostgreSQL Global Development Group
17 *
18 * src/include/nodes/tidbitmap.h
19 *
20 *-------------------------------------------------------------------------
21 */
22#ifndef TIDBITMAP_H
23#define TIDBITMAP_H
24
25#include "access/htup_details.h"
26#include "storage/itemptr.h"
27#include "utils/dsa.h"
28
29/*
30 * The maximum number of tuples per page is not large (typically 256 with
31 * 8K pages, or 1024 with 32K pages). So there's not much point in making
32 * the per-page bitmaps variable size. We just legislate that the size
33 * is this:
34 */
35#define TBM_MAX_TUPLES_PER_PAGE MaxHeapTuplesPerPage
36
37/*
38 * Actual bitmap representation is private to tidbitmap.c. Callers can
39 * do IsA(x, TIDBitmap) on it, but nothing else.
40 */
41typedef struct TIDBitmap TIDBitmap;
42
43/* Likewise, TBMPrivateIterator is private */
46
47/*
48 * Callers with both private and shared implementations can use this unified
49 * API.
50 */
51typedef struct TBMIterator
52{
53 bool shared;
54 union
55 {
58 } i;
60
61/* Result structure for tbm_iterate */
62typedef struct TBMIterateResult
63{
64 BlockNumber blockno; /* block number containing tuples */
65
66 bool lossy;
67
68 /*
69 * Whether or not the tuples should be rechecked. This is always true if
70 * the page is lossy but may also be true if the query requires recheck.
71 */
72 bool recheck;
73
74 /*
75 * Pointer to the page containing the bitmap for this block. It is a void *
76 * to avoid exposing the details of the tidbitmap PagetableEntry to API
77 * users.
78 */
81
82/* function prototypes in nodes/tidbitmap.c */
83
84extern TIDBitmap *tbm_create(Size maxbytes, dsa_area *dsa);
85extern void tbm_free(TIDBitmap *tbm);
86extern void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp);
87
88extern void tbm_add_tuples(TIDBitmap *tbm,
89 const ItemPointer tids, int ntids,
90 bool recheck);
91extern void tbm_add_page(TIDBitmap *tbm, BlockNumber pageno);
92
93extern void tbm_union(TIDBitmap *a, const TIDBitmap *b);
94extern void tbm_intersect(TIDBitmap *a, const TIDBitmap *b);
95
96extern int tbm_extract_page_tuple(TBMIterateResult *iteritem,
97 OffsetNumber *offsets,
98 uint32 max_offsets);
99
100extern bool tbm_is_empty(const TIDBitmap *tbm);
101
104extern bool tbm_private_iterate(TBMPrivateIterator *iterator, TBMIterateResult *tbmres);
105extern bool tbm_shared_iterate(TBMSharedIterator *iterator, TBMIterateResult *tbmres);
106extern void tbm_end_private_iterate(TBMPrivateIterator *iterator);
107extern void tbm_end_shared_iterate(TBMSharedIterator *iterator);
109 dsa_pointer dp);
110extern int tbm_calculate_entries(Size maxbytes);
111
113 dsa_area *dsa, dsa_pointer dsp);
114extern void tbm_end_iterate(TBMIterator *iterator);
115
116extern bool tbm_iterate(TBMIterator *iterator, TBMIterateResult *tbmres);
117
118static inline bool
120{
121 /*
122 * It doesn't matter if we check the private or shared iterator here. If
123 * tbm_end_iterate() was called, they will be NULL
124 */
125 return !iterator->i.private_iterator;
126}
127
128#endif /* TIDBITMAP_H */
uint32 BlockNumber
Definition: block.h:31
uint32_t uint32
Definition: c.h:502
size_t Size
Definition: c.h:576
uint64 dsa_pointer
Definition: dsa.h:62
int b
Definition: isn.c:74
int a
Definition: isn.c:73
uint16 OffsetNumber
Definition: off.h:24
void * internal_page
Definition: tidbitmap.h:79
BlockNumber blockno
Definition: tidbitmap.h:64
union TBMIterator::@109 i
TBMSharedIterator * shared_iterator
Definition: tidbitmap.h:57
TBMPrivateIterator * private_iterator
Definition: tidbitmap.h:56
bool shared
Definition: tidbitmap.h:53
Definition: dsa.c:348
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:311
struct TBMIterateResult TBMIterateResult
bool tbm_iterate(TBMIterator *iterator, TBMIterateResult *tbmres)
Definition: tidbitmap.c:1617
bool tbm_shared_iterate(TBMSharedIterator *iterator, TBMIterateResult *tbmres)
Definition: tidbitmap.c:1057
void tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids, bool recheck)
Definition: tidbitmap.c:366
bool tbm_is_empty(const TIDBitmap *tbm)
Definition: tidbitmap.c:659
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1597
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1162
struct TBMIterator TBMIterator
dsa_pointer tbm_prepare_shared_iterate(TIDBitmap *tbm)
Definition: tidbitmap.c:754
void tbm_intersect(TIDBitmap *a, const TIDBitmap *b)
Definition: tidbitmap.c:529
void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp)
Definition: tidbitmap.c:330
bool tbm_private_iterate(TBMPrivateIterator *iterator, TBMIterateResult *tbmres)
Definition: tidbitmap.c:977
void tbm_add_page(TIDBitmap *tbm, BlockNumber pageno)
Definition: tidbitmap.c:432
TBMSharedIterator * tbm_attach_shared_iterate(dsa_area *dsa, dsa_pointer dp)
Definition: tidbitmap.c:1465
TBMIterator tbm_begin_iterate(TIDBitmap *tbm, dsa_area *dsa, dsa_pointer dsp)
Definition: tidbitmap.c:1574
int tbm_extract_page_tuple(TBMIterateResult *iteritem, OffsetNumber *offsets, uint32 max_offsets)
Definition: tidbitmap.c:901
void tbm_union(TIDBitmap *a, const TIDBitmap *b)
Definition: tidbitmap.c:447
void tbm_end_private_iterate(TBMPrivateIterator *iterator)
Definition: tidbitmap.c:1150
TIDBitmap * tbm_create(Size maxbytes, dsa_area *dsa)
Definition: tidbitmap.c:255
TBMPrivateIterator * tbm_begin_private_iterate(TIDBitmap *tbm)
Definition: tidbitmap.c:678
int tbm_calculate_entries(Size maxbytes)
Definition: tidbitmap.c:1545
static bool tbm_exhausted(TBMIterator *iterator)
Definition: tidbitmap.h:119