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