|
| 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 | +} |
0 commit comments