PostgreSQL Source Code git master
|
#include "postgres.h"
#include <limits.h>
#include "common/hashfn.h"
#include "common/int.h"
#include "nodes/bitmapset.h"
#include "nodes/tidbitmap.h"
#include "storage/lwlock.h"
#include "utils/dsa.h"
#include "lib/simplehash.h"
Go to the source code of this file.
Data Structures | |
struct | PagetableEntry |
struct | PTEntryArray |
struct | TIDBitmap |
struct | TBMPrivateIterator |
struct | TBMSharedIteratorState |
struct | PTIterationArray |
struct | TBMSharedIterator |
Macros | |
#define | PAGES_PER_CHUNK (BLCKSZ / 32) |
#define | WORDNUM(x) ((x) / BITS_PER_BITMAPWORD) |
#define | BITNUM(x) ((x) % BITS_PER_BITMAPWORD) |
#define | WORDS_PER_PAGE ((TBM_MAX_TUPLES_PER_PAGE - 1) / BITS_PER_BITMAPWORD + 1) |
#define | WORDS_PER_CHUNK ((PAGES_PER_CHUNK - 1) / BITS_PER_BITMAPWORD + 1) |
#define | SH_USE_NONDEFAULT_ALLOCATOR |
#define | SH_PREFIX pagetable |
#define | SH_ELEMENT_TYPE PagetableEntry |
#define | SH_KEY_TYPE BlockNumber |
#define | SH_KEY blockno |
#define | SH_HASH_KEY(tb, key) murmurhash32(key) |
#define | SH_EQUAL(tb, a, b) a == b |
#define | SH_SCOPE static inline |
#define | SH_DEFINE |
#define | SH_DECLARE |
Typedefs | |
typedef struct PagetableEntry | PagetableEntry |
typedef struct PTEntryArray | PTEntryArray |
typedef struct TBMSharedIteratorState | TBMSharedIteratorState |
typedef struct PTIterationArray | PTIterationArray |
Enumerations | |
enum | TBMStatus { TBM_EMPTY , TBM_ONE_PAGE , TBM_HASH } |
enum | TBMIteratingState { TBM_NOT_ITERATING , TBM_ITERATING_PRIVATE , TBM_ITERATING_SHARED } |
#define BITNUM | ( | x | ) | ((x) % BITS_PER_BITMAPWORD) |
Definition at line 70 of file tidbitmap.c.
#define PAGES_PER_CHUNK (BLCKSZ / 32) |
Definition at line 65 of file tidbitmap.c.
#define SH_DECLARE |
Definition at line 241 of file tidbitmap.c.
#define SH_DEFINE |
Definition at line 240 of file tidbitmap.c.
#define SH_ELEMENT_TYPE PagetableEntry |
Definition at line 234 of file tidbitmap.c.
#define SH_HASH_KEY | ( | tb, | |
key | |||
) | murmurhash32(key) |
Definition at line 237 of file tidbitmap.c.
#define SH_KEY blockno |
Definition at line 236 of file tidbitmap.c.
#define SH_KEY_TYPE BlockNumber |
Definition at line 235 of file tidbitmap.c.
#define SH_PREFIX pagetable |
Definition at line 233 of file tidbitmap.c.
#define SH_SCOPE static inline |
Definition at line 239 of file tidbitmap.c.
#define SH_USE_NONDEFAULT_ALLOCATOR |
Definition at line 232 of file tidbitmap.c.
#define WORDNUM | ( | x | ) | ((x) / BITS_PER_BITMAPWORD) |
Definition at line 69 of file tidbitmap.c.
#define WORDS_PER_CHUNK ((PAGES_PER_CHUNK - 1) / BITS_PER_BITMAPWORD + 1) |
Definition at line 75 of file tidbitmap.c.
#define WORDS_PER_PAGE ((TBM_MAX_TUPLES_PER_PAGE - 1) / BITS_PER_BITMAPWORD + 1) |
Definition at line 73 of file tidbitmap.c.
typedef struct PagetableEntry PagetableEntry |
typedef struct PTEntryArray PTEntryArray |
typedef struct PTIterationArray PTIterationArray |
typedef struct TBMSharedIteratorState TBMSharedIteratorState |
enum TBMIteratingState |
Enumerator | |
---|---|
TBM_NOT_ITERATING | |
TBM_ITERATING_PRIVATE | |
TBM_ITERATING_SHARED |
Definition at line 130 of file tidbitmap.c.
enum TBMStatus |
Enumerator | |
---|---|
TBM_EMPTY | |
TBM_ONE_PAGE | |
TBM_HASH |
Definition at line 120 of file tidbitmap.c.
|
inlinestatic |
Definition at line 1497 of file tidbitmap.c.
References TIDBitmap::dsa, DSA_ALLOC_HUGE, DSA_ALLOC_ZERO, dsa_allocate_extended(), dsa_get_address(), TIDBitmap::dsapagetable, TIDBitmap::dsapagetableold, if(), MCXT_ALLOC_HUGE, MCXT_ALLOC_ZERO, and MemoryContextAllocExtended().
|
inlinestatic |
Definition at line 1525 of file tidbitmap.c.
References TIDBitmap::dsa, dsa_free(), TIDBitmap::dsapagetableold, DsaPointerIsValid, if(), InvalidDsaPointer, and pfree().
void tbm_add_page | ( | TIDBitmap * | tbm, |
BlockNumber | pageno | ||
) |
Definition at line 432 of file tidbitmap.c.
References TIDBitmap::maxentries, TIDBitmap::nentries, tbm_lossify(), and tbm_mark_page_lossy().
Referenced by bringetbitmap(), and gingetbitmap().
void tbm_add_tuples | ( | TIDBitmap * | tbm, |
const ItemPointer | tids, | ||
int | ntids, | ||
bool | recheck | ||
) |
Definition at line 366 of file tidbitmap.c.
References Assert(), BITNUM, elog, ERROR, i, InvalidBlockNumber, PagetableEntry::ischunk, ItemPointerGetBlockNumber(), ItemPointerGetOffsetNumber(), TIDBitmap::iterating, TIDBitmap::maxentries, TIDBitmap::nentries, PagetableEntry::recheck, tbm_get_pageentry(), tbm_lossify(), TBM_MAX_TUPLES_PER_PAGE, TBM_NOT_ITERATING, tbm_page_is_lossy(), WORDNUM, and PagetableEntry::words.
Referenced by blgetbitmap(), btgetbitmap(), collectMatchBitmap(), GinDataLeafPageGetItemsToTbm(), gingetbitmap(), ginPostingListDecodeAllSegmentsToTbm(), gistScanPage(), hashgetbitmap(), scanPendingInsert(), and storeBitmap().
|
inlinestatic |
Definition at line 938 of file tidbitmap.c.
References BITNUM, PAGES_PER_CHUNK, WORDNUM, and PagetableEntry::words.
Referenced by tbm_private_iterate(), and tbm_shared_iterate().
TBMSharedIterator * tbm_attach_shared_iterate | ( | dsa_area * | dsa, |
dsa_pointer | dp | ||
) |
Definition at line 1465 of file tidbitmap.c.
References dsa_get_address(), TBMSharedIteratorState::nchunks, TBMSharedIteratorState::npages, TBMSharedIteratorState::pagetable, palloc0(), TBMSharedIterator::ptbase, TBMSharedIterator::ptchunks, TBMSharedIterator::ptpages, TBMSharedIteratorState::schunks, TBMSharedIteratorState::spages, and TBMSharedIterator::state.
Referenced by tbm_begin_iterate().
TBMIterator tbm_begin_iterate | ( | TIDBitmap * | tbm, |
dsa_area * | dsa, | ||
dsa_pointer | dsp | ||
) |
Definition at line 1574 of file tidbitmap.c.
References DsaPointerIsValid, TBMIterator::i, TBMIterator::private_iterator, TBMIterator::shared, TBMIterator::shared_iterator, tbm_attach_shared_iterate(), and tbm_begin_private_iterate().
Referenced by BitmapTableScanSetup().
TBMPrivateIterator * tbm_begin_private_iterate | ( | TIDBitmap * | tbm | ) |
Definition at line 678 of file tidbitmap.c.
References Assert(), i, PagetableEntry::ischunk, TIDBitmap::iterating, TIDBitmap::mcxt, MemoryContextAlloc(), TIDBitmap::nchunks, TIDBitmap::npages, TIDBitmap::pagetable, palloc(), qsort, TBMPrivateIterator::schunkbit, TBMPrivateIterator::schunkptr, TIDBitmap::schunks, TBMPrivateIterator::spageptr, TIDBitmap::spages, TIDBitmap::status, TBMPrivateIterator::tbm, tbm_comparator(), TBM_HASH, TBM_ITERATING_PRIVATE, TBM_ITERATING_SHARED, and TBM_NOT_ITERATING.
Referenced by startScanEntry(), and tbm_begin_iterate().
int tbm_calculate_entries | ( | Size | maxbytes | ) |
Definition at line 1545 of file tidbitmap.c.
Referenced by compute_bitmap_pages(), and tbm_create().
|
static |
Definition at line 1428 of file tidbitmap.c.
References pg_cmp_u32().
Referenced by tbm_begin_private_iterate().
Definition at line 255 of file tidbitmap.c.
References CurrentMemoryContext, TIDBitmap::dsa, TIDBitmap::dsapagetable, TIDBitmap::dsapagetableold, InvalidDsaPointer, TIDBitmap::lossify_start, makeNode, TIDBitmap::maxentries, TIDBitmap::mcxt, TIDBitmap::ptchunks, TIDBitmap::ptpages, TIDBitmap::status, tbm_calculate_entries(), and TBM_EMPTY.
Referenced by collectMatchBitmap(), MultiExecBitmapIndexScan(), and MultiExecBitmapOr().
|
static |
Definition at line 281 of file tidbitmap.c.
References Assert(), PagetableEntry::blockno, TIDBitmap::entry1, TIDBitmap::mcxt, TIDBitmap::pagetable, PagetableEntry::status, TIDBitmap::status, TBM_HASH, and TBM_ONE_PAGE.
Referenced by tbm_get_pageentry(), and tbm_mark_page_lossy().
void tbm_end_iterate | ( | TBMIterator * | iterator | ) |
Definition at line 1597 of file tidbitmap.c.
References Assert(), TBMIterator::i, TBMIterator::private_iterator, TBMIterator::shared, TBMIterator::shared_iterator, tbm_end_private_iterate(), tbm_end_shared_iterate(), and tbm_exhausted().
Referenced by ExecEndBitmapHeapScan(), and ExecReScanBitmapHeapScan().
void tbm_end_private_iterate | ( | TBMPrivateIterator * | iterator | ) |
Definition at line 1150 of file tidbitmap.c.
References pfree().
Referenced by entryGetItem(), ginFreeScanKeys(), startScanEntry(), and tbm_end_iterate().
void tbm_end_shared_iterate | ( | TBMSharedIterator * | iterator | ) |
int tbm_extract_page_tuple | ( | TBMIterateResult * | iteritem, |
OffsetNumber * | offsets, | ||
uint32 | max_offsets | ||
) |
Definition at line 901 of file tidbitmap.c.
References BITS_PER_BITMAPWORD, TBMIterateResult::internal_page, PagetableEntry::words, and WORDS_PER_PAGE.
Referenced by BitmapHeapScanNextBlock(), and entryGetItem().
|
static |
Definition at line 1173 of file tidbitmap.c.
References Assert(), PagetableEntry::blockno, TIDBitmap::entry1, PagetableEntry::ischunk, TIDBitmap::nentries, TIDBitmap::pagetable, TIDBitmap::status, and TBM_ONE_PAGE.
Referenced by tbm_intersect_page().
void tbm_free | ( | TIDBitmap * | tbm | ) |
Definition at line 311 of file tidbitmap.c.
References TIDBitmap::pagetable, pfree(), TIDBitmap::schunks, and TIDBitmap::spages.
Referenced by ExecEndBitmapHeapScan(), ExecReScanBitmapHeapScan(), ginFreeScanKeys(), MultiExecBitmapAnd(), MultiExecBitmapOr(), and startScanEntry().
void tbm_free_shared_area | ( | dsa_area * | dsa, |
dsa_pointer | dp | ||
) |
Definition at line 330 of file tidbitmap.c.
References dsa_free(), dsa_get_address(), DsaPointerIsValid, TBMSharedIteratorState::pagetable, pg_atomic_sub_fetch_u32(), PTEntryArray::refcount, PTIterationArray::refcount, TBMSharedIteratorState::schunks, and TBMSharedIteratorState::spages.
Referenced by ExecBitmapHeapReInitializeDSM().
|
static |
Definition at line 1206 of file tidbitmap.c.
References PagetableEntry::blockno, TIDBitmap::entry1, MemSet, TIDBitmap::nentries, TIDBitmap::npages, TIDBitmap::pagetable, PagetableEntry::status, TIDBitmap::status, tbm_create_pagetable(), TBM_EMPTY, and TBM_ONE_PAGE.
Referenced by tbm_add_tuples(), and tbm_union_page().
Definition at line 529 of file tidbitmap.c.
References a, Assert(), b, PagetableEntry::blockno, elog, ERROR, i, PagetableEntry::ischunk, TBM_EMPTY, TBM_HASH, tbm_intersect_page(), and TBM_ONE_PAGE.
Referenced by MultiExecBitmapAnd().
|
static |
Definition at line 578 of file tidbitmap.c.
References Assert(), b, BITS_PER_BITMAPWORD, PagetableEntry::blockno, PagetableEntry::ischunk, PagetableEntry::recheck, tbm_find_pageentry(), tbm_page_is_lossy(), PagetableEntry::words, WORDS_PER_CHUNK, and WORDS_PER_PAGE.
Referenced by tbm_intersect().
bool tbm_is_empty | ( | const TIDBitmap * | tbm | ) |
Definition at line 659 of file tidbitmap.c.
References TIDBitmap::nentries.
Referenced by MultiExecBitmapAnd(), and startScanEntry().
bool tbm_iterate | ( | TBMIterator * | iterator, |
TBMIterateResult * | tbmres | ||
) |
Definition at line 1617 of file tidbitmap.c.
References Assert(), TBMIterator::i, TBMIterator::private_iterator, TBMIterator::shared, TBMIterator::shared_iterator, tbm_private_iterate(), and tbm_shared_iterate().
Referenced by bitmapheap_stream_read_next().
|
static |
Definition at line 1359 of file tidbitmap.c.
References Assert(), PagetableEntry::blockno, i, PagetableEntry::ischunk, TIDBitmap::iterating, TIDBitmap::lossify_start, TIDBitmap::maxentries, Min, TIDBitmap::nentries, PAGES_PER_CHUNK, TIDBitmap::pagetable, TIDBitmap::status, TBM_HASH, tbm_mark_page_lossy(), and TBM_NOT_ITERATING.
Referenced by tbm_add_page(), tbm_add_tuples(), and tbm_union_page().
|
static |
Definition at line 1287 of file tidbitmap.c.
References BITNUM, PagetableEntry::blockno, PagetableEntry::ischunk, MemSet, TIDBitmap::nchunks, TIDBitmap::nentries, TIDBitmap::npages, PAGES_PER_CHUNK, TIDBitmap::pagetable, PagetableEntry::status, TIDBitmap::status, tbm_create_pagetable(), TBM_HASH, WORDNUM, and PagetableEntry::words.
Referenced by tbm_add_page(), tbm_lossify(), and tbm_union_page().
|
static |
Definition at line 1253 of file tidbitmap.c.
References Assert(), BITNUM, PagetableEntry::ischunk, TIDBitmap::nchunks, PAGES_PER_CHUNK, TIDBitmap::pagetable, TIDBitmap::status, TBM_HASH, WORDNUM, and PagetableEntry::words.
Referenced by tbm_add_tuples(), tbm_intersect_page(), and tbm_union_page().
dsa_pointer tbm_prepare_shared_iterate | ( | TIDBitmap * | tbm | ) |
Definition at line 754 of file tidbitmap.c.
References Assert(), TIDBitmap::dsa, dsa_allocate, dsa_allocate0, dsa_get_address(), TIDBitmap::dsapagetable, TIDBitmap::entry1, i, idx(), PTIterationArray::index, PagetableEntry::ischunk, TIDBitmap::iterating, TBMSharedIteratorState::lock, LWLockInitialize(), LWTRANCHE_SHARED_TIDBITMAP, TIDBitmap::maxentries, TBMSharedIteratorState::maxentries, TIDBitmap::nchunks, TBMSharedIteratorState::nchunks, TIDBitmap::nentries, TBMSharedIteratorState::nentries, TIDBitmap::npages, TBMSharedIteratorState::npages, TIDBitmap::pagetable, TBMSharedIteratorState::pagetable, pg_atomic_add_fetch_u32(), pg_atomic_init_u32(), TIDBitmap::ptchunks, PTEntryArray::ptentry, TIDBitmap::ptpages, qsort_arg(), PTEntryArray::refcount, PTIterationArray::refcount, TBMSharedIteratorState::schunkbit, TBMSharedIteratorState::schunkptr, TBMSharedIteratorState::schunks, TBMSharedIteratorState::spageptr, TBMSharedIteratorState::spages, TIDBitmap::status, TBM_HASH, TBM_ITERATING_PRIVATE, TBM_ITERATING_SHARED, TBM_NOT_ITERATING, TBM_ONE_PAGE, and tbm_shared_comparator().
Referenced by BitmapTableScanSetup().
bool tbm_private_iterate | ( | TBMPrivateIterator * | iterator, |
TBMIterateResult * | tbmres | ||
) |
Definition at line 977 of file tidbitmap.c.
References Assert(), PagetableEntry::blockno, TBMIterateResult::blockno, TIDBitmap::entry1, TBMIterateResult::internal_page, InvalidBlockNumber, TIDBitmap::iterating, TBMIterateResult::lossy, TIDBitmap::nchunks, TIDBitmap::npages, PAGES_PER_CHUNK, PagetableEntry::recheck, TBMIterateResult::recheck, TBMPrivateIterator::schunkbit, TBMPrivateIterator::schunkptr, TIDBitmap::schunks, TBMPrivateIterator::spageptr, TIDBitmap::spages, TIDBitmap::status, TBMPrivateIterator::tbm, tbm_advance_schunkbit(), TBM_ITERATING_PRIVATE, and TBM_ONE_PAGE.
Referenced by entryGetItem(), and tbm_iterate().
|
static |
Definition at line 1442 of file tidbitmap.c.
References arg, and PagetableEntry::blockno.
Referenced by tbm_prepare_shared_iterate().
bool tbm_shared_iterate | ( | TBMSharedIterator * | iterator, |
TBMIterateResult * | tbmres | ||
) |
Definition at line 1057 of file tidbitmap.c.
References PagetableEntry::blockno, TBMIterateResult::blockno, PTIterationArray::index, TBMIterateResult::internal_page, InvalidBlockNumber, TBMSharedIteratorState::lock, TBMIterateResult::lossy, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), TBMSharedIteratorState::nchunks, TBMSharedIteratorState::npages, PAGES_PER_CHUNK, TBMSharedIterator::ptbase, TBMSharedIterator::ptchunks, PTEntryArray::ptentry, TBMSharedIterator::ptpages, PagetableEntry::recheck, TBMIterateResult::recheck, TBMSharedIteratorState::schunkbit, TBMSharedIteratorState::schunkptr, TBMSharedIteratorState::spageptr, TBMSharedIterator::state, and tbm_advance_schunkbit().
Referenced by tbm_iterate().
Definition at line 447 of file tidbitmap.c.
References a, Assert(), b, i, TBM_HASH, TBM_ONE_PAGE, and tbm_union_page().
Referenced by MultiExecBitmapOr().
|
static |
Definition at line 470 of file tidbitmap.c.
References a, BITS_PER_BITMAPWORD, PagetableEntry::blockno, PagetableEntry::ischunk, PagetableEntry::recheck, tbm_get_pageentry(), tbm_lossify(), tbm_mark_page_lossy(), tbm_page_is_lossy(), PagetableEntry::words, WORDS_PER_CHUNK, and WORDS_PER_PAGE.
Referenced by tbm_union().