PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
brin.h File Reference
#include "nodes/execnodes.h"
#include "storage/shm_toc.h"
#include "utils/relcache.h"
Include dependency graph for brin.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  BrinOptions
 
struct  BrinStatsData
 

Macros

#define BRIN_DEFAULT_PAGES_PER_RANGE   128
 
#define BrinGetPagesPerRange(relation)
 
#define BrinGetAutoSummarize(relation)
 

Typedefs

typedef struct BrinOptions BrinOptions
 
typedef struct BrinStatsData BrinStatsData
 

Functions

void brinGetStats (Relation index, BrinStatsData *stats)
 
void _brin_parallel_build_main (dsm_segment *seg, shm_toc *toc)
 

Macro Definition Documentation

◆ BRIN_DEFAULT_PAGES_PER_RANGE

#define BRIN_DEFAULT_PAGES_PER_RANGE   128

Definition at line 39 of file brin.h.

◆ BrinGetAutoSummarize

#define BrinGetAutoSummarize (   relation)
Value:
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
relation->rd_rel->relam == BRIN_AM_OID), \
(relation)->rd_options ? \
((BrinOptions *) (relation)->rd_options)->autosummarize : \
false)
#define AssertMacro(condition)
Definition: c.h:830

Definition at line 46 of file brin.h.

◆ BrinGetPagesPerRange

#define BrinGetPagesPerRange (   relation)
Value:
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
relation->rd_rel->relam == BRIN_AM_OID), \
(relation)->rd_options ? \
((BrinOptions *) (relation)->rd_options)->pagesPerRange : \
BRIN_DEFAULT_PAGES_PER_RANGE)

Definition at line 40 of file brin.h.

Typedef Documentation

◆ BrinOptions

typedef struct BrinOptions BrinOptions

◆ BrinStatsData

typedef struct BrinStatsData BrinStatsData

Function Documentation

◆ _brin_parallel_build_main()

void _brin_parallel_build_main ( dsm_segment seg,
shm_toc toc 
)

Definition at line 2863 of file brin.c.

2864{
2865 char *sharedquery;
2866 BrinShared *brinshared;
2867 Sharedsort *sharedsort;
2868 BrinBuildState *buildstate;
2869 Relation heapRel;
2870 Relation indexRel;
2871 LOCKMODE heapLockmode;
2872 LOCKMODE indexLockmode;
2873 WalUsage *walusage;
2874 BufferUsage *bufferusage;
2875 int sortmem;
2876
2877 /*
2878 * The only possible status flag that can be set to the parallel worker is
2879 * PROC_IN_SAFE_IC.
2880 */
2881 Assert((MyProc->statusFlags == 0) ||
2883
2884 /* Set debug_query_string for individual workers first */
2885 sharedquery = shm_toc_lookup(toc, PARALLEL_KEY_QUERY_TEXT, true);
2886 debug_query_string = sharedquery;
2887
2888 /* Report the query string from leader */
2890
2891 /* Look up brin shared state */
2892 brinshared = shm_toc_lookup(toc, PARALLEL_KEY_BRIN_SHARED, false);
2893
2894 /* Open relations using lock modes known to be obtained by index.c */
2895 if (!brinshared->isconcurrent)
2896 {
2897 heapLockmode = ShareLock;
2898 indexLockmode = AccessExclusiveLock;
2899 }
2900 else
2901 {
2902 heapLockmode = ShareUpdateExclusiveLock;
2903 indexLockmode = RowExclusiveLock;
2904 }
2905
2906 /* Track query ID */
2907 pgstat_report_query_id(brinshared->queryid, false);
2908
2909 /* Open relations within worker */
2910 heapRel = table_open(brinshared->heaprelid, heapLockmode);
2911 indexRel = index_open(brinshared->indexrelid, indexLockmode);
2912
2913 buildstate = initialize_brin_buildstate(indexRel, NULL,
2914 brinshared->pagesPerRange,
2916
2917 /* Look up shared state private to tuplesort.c */
2918 sharedsort = shm_toc_lookup(toc, PARALLEL_KEY_TUPLESORT, false);
2919 tuplesort_attach_shared(sharedsort, seg);
2920
2921 /* Prepare to track buffer usage during parallel execution */
2923
2924 /*
2925 * Might as well use reliable figure when doling out maintenance_work_mem
2926 * (when requested number of workers were not launched, this will be
2927 * somewhat higher than it is for other workers).
2928 */
2929 sortmem = maintenance_work_mem / brinshared->scantuplesortstates;
2930
2931 _brin_parallel_scan_and_build(buildstate, brinshared, sharedsort,
2932 heapRel, indexRel, sortmem, false);
2933
2934 /* Report WAL/buffer usage during parallel execution */
2935 bufferusage = shm_toc_lookup(toc, PARALLEL_KEY_BUFFER_USAGE, false);
2936 walusage = shm_toc_lookup(toc, PARALLEL_KEY_WAL_USAGE, false);
2938 &walusage[ParallelWorkerNumber]);
2939
2940 index_close(indexRel, indexLockmode);
2941 table_close(heapRel, heapLockmode);
2942}
int ParallelWorkerNumber
Definition: parallel.c:115
void pgstat_report_query_id(uint64 query_id, bool force)
void pgstat_report_activity(BackendState state, const char *cmd_str)
@ STATE_RUNNING
#define InvalidBlockNumber
Definition: block.h:33
#define PARALLEL_KEY_BUFFER_USAGE
Definition: brin.c:51
#define PARALLEL_KEY_BRIN_SHARED
Definition: brin.c:47
static void _brin_parallel_scan_and_build(BrinBuildState *state, BrinShared *brinshared, Sharedsort *sharedsort, Relation heap, Relation index, int sortmem, bool progress)
Definition: brin.c:2806
static BrinBuildState * initialize_brin_buildstate(Relation idxRel, BrinRevmap *revmap, BlockNumber pagesPerRange, BlockNumber tablePages)
Definition: brin.c:1669
#define PARALLEL_KEY_TUPLESORT
Definition: brin.c:48
#define PARALLEL_KEY_QUERY_TEXT
Definition: brin.c:49
#define PARALLEL_KEY_WAL_USAGE
Definition: brin.c:50
int maintenance_work_mem
Definition: globals.c:134
Assert(PointerIsAligned(start, uint64))
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:177
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:133
void InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
Definition: instrument.c:208
void InstrStartParallelQuery(void)
Definition: instrument.c:200
int LOCKMODE
Definition: lockdefs.h:26
#define AccessExclusiveLock
Definition: lockdefs.h:43
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
#define ShareLock
Definition: lockdefs.h:40
#define RowExclusiveLock
Definition: lockdefs.h:38
const char * debug_query_string
Definition: postgres.c:88
#define PROC_IN_SAFE_IC
Definition: proc.h:59
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
PGPROC * MyProc
Definition: proc.c:67
int scantuplesortstates
Definition: brin.c:68
Oid heaprelid
Definition: brin.c:64
BlockNumber pagesPerRange
Definition: brin.c:67
uint64 queryid
Definition: brin.c:71
Oid indexrelid
Definition: brin.c:65
bool isconcurrent
Definition: brin.c:66
uint8 statusFlags
Definition: proc.h:243
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
void tuplesort_attach_shared(Sharedsort *shared, dsm_segment *seg)
Definition: tuplesort.c:2961

References _brin_parallel_scan_and_build(), AccessExclusiveLock, Assert(), debug_query_string, BrinShared::heaprelid, index_close(), index_open(), BrinShared::indexrelid, initialize_brin_buildstate(), InstrEndParallelQuery(), InstrStartParallelQuery(), InvalidBlockNumber, BrinShared::isconcurrent, maintenance_work_mem, MyProc, BrinShared::pagesPerRange, PARALLEL_KEY_BRIN_SHARED, PARALLEL_KEY_BUFFER_USAGE, PARALLEL_KEY_QUERY_TEXT, PARALLEL_KEY_TUPLESORT, PARALLEL_KEY_WAL_USAGE, ParallelWorkerNumber, pgstat_report_activity(), pgstat_report_query_id(), PROC_IN_SAFE_IC, BrinShared::queryid, RowExclusiveLock, BrinShared::scantuplesortstates, ShareLock, ShareUpdateExclusiveLock, shm_toc_lookup(), STATE_RUNNING, PGPROC::statusFlags, table_close(), table_open(), and tuplesort_attach_shared().

◆ brinGetStats()

void brinGetStats ( Relation  index,
BrinStatsData stats 
)

Definition at line 1648 of file brin.c.

1649{
1650 Buffer metabuffer;
1651 Page metapage;
1652 BrinMetaPageData *metadata;
1653
1654 metabuffer = ReadBuffer(index, BRIN_METAPAGE_BLKNO);
1655 LockBuffer(metabuffer, BUFFER_LOCK_SHARE);
1656 metapage = BufferGetPage(metabuffer);
1657 metadata = (BrinMetaPageData *) PageGetContents(metapage);
1658
1659 stats->pagesPerRange = metadata->pagesPerRange;
1660 stats->revmapNumPages = metadata->lastRevmapPage - 1;
1661
1662 UnlockReleaseBuffer(metabuffer);
1663}
#define BRIN_METAPAGE_BLKNO
Definition: brin_page.h:75
int Buffer
Definition: buf.h:23
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:5320
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:5537
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:751
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:197
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:414
static char * PageGetContents(Page page)
Definition: bufpage.h:258
PageData * Page
Definition: bufpage.h:82
BlockNumber lastRevmapPage
Definition: brin_page.h:69
BlockNumber pagesPerRange
Definition: brin_page.h:68
BlockNumber revmapNumPages
Definition: brin.h:35
BlockNumber pagesPerRange
Definition: brin.h:34
Definition: type.h:96

References BRIN_METAPAGE_BLKNO, BUFFER_LOCK_SHARE, BufferGetPage(), BrinMetaPageData::lastRevmapPage, LockBuffer(), PageGetContents(), BrinStatsData::pagesPerRange, BrinMetaPageData::pagesPerRange, ReadBuffer(), BrinStatsData::revmapNumPages, and UnlockReleaseBuffer().

Referenced by brincostestimate().