57 #define MAX_TUPLES_PER_PAGE MaxHeapTuplesPerPage
74 #define PAGES_PER_CHUNK (BLCKSZ / 32)
78 #define WORDNUM(x) ((x) / BITS_PER_BITMAPWORD)
79 #define BITNUM(x) ((x) % BITS_PER_BITMAPWORD)
82 #define WORDS_PER_PAGE ((MAX_TUPLES_PER_PAGE - 1) / BITS_PER_BITMAPWORD + 1)
84 #define WORDS_PER_CHUNK ((PAGES_PER_CHUNK - 1) / BITS_PER_BITMAPWORD + 1)
243 #define SH_USE_NONDEFAULT_ALLOCATOR
244 #define SH_PREFIX pagetable
245 #define SH_ELEMENT_TYPE PagetableEntry
246 #define SH_KEY_TYPE BlockNumber
247 #define SH_KEY blockno
248 #define SH_HASH_KEY(tb, key) murmurhash32(key)
249 #define SH_EQUAL(tb, a, b) a == b
250 #define SH_SCOPE static inline
385 for (
i = 0;
i < ntids;
i++)
394 elog(
ERROR,
"tuple offset out of range: %u", off);
416 wordnum = bitnum = 0;
462 if (
b->nentries == 0)
469 pagetable_iterator
i;
473 pagetable_start_iterate(
b->pagetable, &
i);
474 while ((bpage = pagetable_iterate(
b->pagetable, &
i)) != NULL)
525 apage->
words[wordnum] |= bpage->
words[wordnum];
530 if (
a->nentries >
a->maxentries)
544 if (
a->nentries == 0)
561 pagetable_iterator
i;
565 pagetable_start_iterate(
a->pagetable, &
i);
566 while ((apage = pagetable_iterate(
a->pagetable, &
i)) != NULL)
576 if (!pagetable_delete(
a->pagetable, apage->
blockno))
597 bool candelete =
true;
626 apage->
words[wordnum] = neww;
646 bool candelete =
true;
655 apage->
words[wordnum] &= bpage->
words[wordnum];
656 if (apage->
words[wordnum] != 0)
718 pagetable_iterator
i;
732 npages = nchunks = 0;
734 while ((page = pagetable_iterate(tbm->
pagetable, &
i)) != NULL)
737 tbm->
schunks[nchunks++] = page;
739 tbm->
spages[npages++] = page;
791 pagetable_iterator
i;
804 tbm->
npages *
sizeof(
int));
822 npages = nchunks = 0;
828 while ((page = pagetable_iterate(tbm->
pagetable, &
i)) != NULL)
851 ptpages->
index[0] = 0;
889 if (ptchunks != NULL)
943 int schunkbit = *schunkbitp;
947 int wordnum =
WORDNUM(schunkbit);
948 int bitnum =
BITNUM(schunkbit);
955 *schunkbitp = schunkbit;
1009 chunk_blockno < tbm->spages[iterator->
spageptr]->blockno)
1012 output->blockno = chunk_blockno;
1034 output->ntuples = ntuples;
1057 int *idxpages = NULL;
1058 int *idxchunks = NULL;
1060 if (iterator->
ptbase != NULL)
1062 if (iterator->
ptpages != NULL)
1105 output->blockno = chunk_blockno;
1123 output->ntuples = ntuples;
1185 page = pagetable_lookup(tbm->
pagetable, pageno);
1226 page = pagetable_insert(tbm->
pagetable, pageno, &found);
1232 char oldstatus = page->
status;
1235 page->
status = oldstatus;
1261 chunk_pageno = pageno - bitno;
1263 page = pagetable_lookup(tbm->
pagetable, chunk_pageno);
1265 if (page != NULL && page->
ischunk)
1268 int bitnum =
BITNUM(bitno);
1297 chunk_pageno = pageno - bitno;
1305 if (pagetable_delete(tbm->
pagetable, pageno))
1314 page = pagetable_insert(tbm->
pagetable, chunk_pageno, &found);
1319 char oldstatus = page->
status;
1322 page->
status = oldstatus;
1331 char oldstatus = page->
status;
1335 page->
status = oldstatus;
1357 pagetable_iterator
i;
1373 while ((page = pagetable_iterate(tbm->
pagetable, &
i)) != NULL)
1444 if (lpage->
blockno < rpage->blockno)
1446 else if (lpage->
blockno > rpage->blockno)
1475 iterator->
state = istate;
1493 static inline void *
1499 if (tbm->
dsa == NULL)
1513 return ptbase->ptentry;
1527 if (tbm->
dsa == NULL)
1552 nbuckets = maxbytes /
1554 nbuckets =
Min(nbuckets, INT_MAX - 1);
1555 nbuckets =
Max(nbuckets, 16);
Datum idx(PG_FUNCTION_ARGS)
static uint32 pg_atomic_sub_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static uint32 pg_atomic_add_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
#define BITS_PER_BITMAPWORD
#define InvalidBlockNumber
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
#define MemSet(start, val, len)
dsa_pointer dsa_allocate_extended(dsa_area *area, size_t size, int flags)
void * dsa_get_address(dsa_area *area, dsa_pointer dp)
void dsa_free(dsa_area *area, dsa_pointer dp)
#define dsa_allocate0(area, size)
#define dsa_allocate(area, size)
#define InvalidDsaPointer
#define DsaPointerIsValid(x)
static int pg_cmp_u32(uint32 a, uint32 b)
if(TABLE==NULL||TABLE_index==NULL)
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
void LWLockInitialize(LWLock *lock, int tranche_id)
@ LWTRANCHE_SHARED_TIDBITMAP
void pfree(void *pointer)
void * palloc0(Size size)
void * MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
MemoryContext CurrentMemoryContext
void * MemoryContextAlloc(MemoryContext context, Size size)
void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)
#define qsort(a, b, c, d)
static pg_noinline void Size size
pg_atomic_uint32 refcount
PagetableEntry ptentry[FLEXIBLE_ARRAY_MEMBER]
pg_atomic_uint32 refcount
int index[FLEXIBLE_ARRAY_MEMBER]
bitmapword words[Max(WORDS_PER_PAGE, WORDS_PER_CHUNK)]
TBMSharedIteratorState * state
PTIterationArray * ptchunks
PTIterationArray * ptpages
TBMIteratingState iterating
dsa_pointer dsapagetableold
struct pagetable_hash * pagetable
PagetableEntry ** schunks
void tbm_free(TIDBitmap *tbm)
TBMIterator * tbm_begin_iterate(TIDBitmap *tbm)
struct PTIterationArray PTIterationArray
void tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids, bool recheck)
#define MAX_TUPLES_PER_PAGE
static void tbm_lossify(TIDBitmap *tbm)
bool tbm_is_empty(const TIDBitmap *tbm)
void tbm_end_iterate(TBMIterator *iterator)
static void * pagetable_allocate(pagetable_hash *pagetable, Size size)
long tbm_calculate_entries(double maxbytes)
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
static bool tbm_page_is_lossy(const TIDBitmap *tbm, BlockNumber pageno)
TBMSharedIterator * tbm_attach_shared_iterate(dsa_area *dsa, dsa_pointer dp)
dsa_pointer tbm_prepare_shared_iterate(TIDBitmap *tbm)
void tbm_intersect(TIDBitmap *a, const TIDBitmap *b)
void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp)
static void tbm_mark_page_lossy(TIDBitmap *tbm, BlockNumber pageno)
static void tbm_union_page(TIDBitmap *a, const PagetableEntry *bpage)
static const PagetableEntry * tbm_find_pageentry(const TIDBitmap *tbm, BlockNumber pageno)
void tbm_add_page(TIDBitmap *tbm, BlockNumber pageno)
static void tbm_advance_schunkbit(PagetableEntry *chunk, int *schunkbitp)
static int tbm_shared_comparator(const void *left, const void *right, void *arg)
TIDBitmap * tbm_create(long maxbytes, dsa_area *dsa)
static int tbm_comparator(const void *left, const void *right)
static void tbm_create_pagetable(TIDBitmap *tbm)
void tbm_union(TIDBitmap *a, const TIDBitmap *b)
TBMIterateResult * tbm_shared_iterate(TBMSharedIterator *iterator)
TBMIterateResult * tbm_iterate(TBMIterator *iterator)
struct PagetableEntry PagetableEntry
struct PTEntryArray PTEntryArray
static int tbm_extract_page_tuple(PagetableEntry *page, TBMIterateResult *output)
static bool tbm_intersect_page(TIDBitmap *a, PagetableEntry *apage, const TIDBitmap *b)
struct TBMSharedIteratorState TBMSharedIteratorState
static void pagetable_free(pagetable_hash *pagetable, void *pointer)
static PagetableEntry * tbm_get_pageentry(TIDBitmap *tbm, BlockNumber pageno)