| 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-2019, 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 "storage/itemptr.h" |
| 26 | #include "utils/dsa.h" |
| 27 | |
| 28 | |
| 29 | /* |
| 30 | * Actual bitmap representation is private to tidbitmap.c. Callers can |
| 31 | * do IsA(x, TIDBitmap) on it, but nothing else. |
| 32 | */ |
| 33 | typedef struct TIDBitmap TIDBitmap; |
| 34 | |
| 35 | /* Likewise, TBMIterator is private */ |
| 36 | typedef struct TBMIterator TBMIterator; |
| 37 | typedef struct TBMSharedIterator TBMSharedIterator; |
| 38 | |
| 39 | /* Result structure for tbm_iterate */ |
| 40 | typedef struct TBMIterateResult |
| 41 | { |
| 42 | BlockNumber blockno; /* page number containing tuples */ |
| 43 | int ntuples; /* -1 indicates lossy result */ |
| 44 | bool recheck; /* should the tuples be rechecked? */ |
| 45 | /* Note: recheck is always true if ntuples < 0 */ |
| 46 | OffsetNumber offsets[FLEXIBLE_ARRAY_MEMBER]; |
| 47 | } TBMIterateResult; |
| 48 | |
| 49 | /* function prototypes in nodes/tidbitmap.c */ |
| 50 | |
| 51 | extern TIDBitmap *tbm_create(long maxbytes, dsa_area *dsa); |
| 52 | extern void tbm_free(TIDBitmap *tbm); |
| 53 | extern void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp); |
| 54 | |
| 55 | extern void tbm_add_tuples(TIDBitmap *tbm, |
| 56 | const ItemPointer tids, int ntids, |
| 57 | bool recheck); |
| 58 | extern void tbm_add_page(TIDBitmap *tbm, BlockNumber pageno); |
| 59 | |
| 60 | extern void tbm_union(TIDBitmap *a, const TIDBitmap *b); |
| 61 | extern void tbm_intersect(TIDBitmap *a, const TIDBitmap *b); |
| 62 | |
| 63 | extern bool tbm_is_empty(const TIDBitmap *tbm); |
| 64 | |
| 65 | extern TBMIterator *tbm_begin_iterate(TIDBitmap *tbm); |
| 66 | extern dsa_pointer tbm_prepare_shared_iterate(TIDBitmap *tbm); |
| 67 | extern TBMIterateResult *tbm_iterate(TBMIterator *iterator); |
| 68 | extern TBMIterateResult *tbm_shared_iterate(TBMSharedIterator *iterator); |
| 69 | extern void tbm_end_iterate(TBMIterator *iterator); |
| 70 | extern void tbm_end_shared_iterate(TBMSharedIterator *iterator); |
| 71 | extern TBMSharedIterator *tbm_attach_shared_iterate(dsa_area *dsa, |
| 72 | dsa_pointer dp); |
| 73 | extern long tbm_calculate_entries(double maxbytes); |
| 74 | |
| 75 | #endif /* TIDBITMAP_H */ |
| 76 | |