mirror of
https://github.com/postgres/postgres.git
synced 2025-10-21 02:52:47 +03:00
Refactor reloption handling for index AMs in-core
This reworks the reloption parsing and build of a couple of index AMs by creating new structures for each index AM's options. This split was already done for BRIN, GIN and GiST (which actually has a fillfactor parameter), but not for hash, B-tree and SPGiST which relied on StdRdOptions due to an overlap with the default option set. This saves a couple of bytes for rd_options in each relcache entry with indexes making use of relation options, and brings more consistency between all index AMs. While on it, add a couple of AssertMacro() calls to make sure that utility macros to grab values of reloptions are used with the expected index AM. Author: Nikolay Shaplov Reviewed-by: Amit Langote, Michael Paquier, Álvaro Herrera, Dent John Discussion: https://postgr.es/m/4127670.gFlpRb6XCm@x200m
This commit is contained in:
@@ -37,11 +37,15 @@ typedef struct BrinStatsData
|
||||
|
||||
#define BRIN_DEFAULT_PAGES_PER_RANGE 128
|
||||
#define BrinGetPagesPerRange(relation) \
|
||||
((relation)->rd_options ? \
|
||||
(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)
|
||||
#define BrinGetAutoSummarize(relation) \
|
||||
((relation)->rd_options ? \
|
||||
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
|
||||
relation->rd_rel->relam == BRIN_AM_OID), \
|
||||
(relation)->rd_options ? \
|
||||
((BrinOptions *) (relation)->rd_options)->autosummarize : \
|
||||
false)
|
||||
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include "access/gin.h"
|
||||
#include "access/ginblock.h"
|
||||
#include "access/itup.h"
|
||||
#include "catalog/pg_am_d.h"
|
||||
#include "fmgr.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "lib/rbtree.h"
|
||||
@@ -30,10 +31,14 @@ typedef struct GinOptions
|
||||
|
||||
#define GIN_DEFAULT_USE_FASTUPDATE true
|
||||
#define GinGetUseFastUpdate(relation) \
|
||||
((relation)->rd_options ? \
|
||||
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
|
||||
relation->rd_rel->relam == GIN_AM_OID), \
|
||||
(relation)->rd_options ? \
|
||||
((GinOptions *) (relation)->rd_options)->useFastUpdate : GIN_DEFAULT_USE_FASTUPDATE)
|
||||
#define GinGetPendingListCleanupSize(relation) \
|
||||
((relation)->rd_options && \
|
||||
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
|
||||
relation->rd_rel->relam == GIN_AM_OID), \
|
||||
(relation)->rd_options && \
|
||||
((GinOptions *) (relation)->rd_options)->pendingListCleanupSize != -1 ? \
|
||||
((GinOptions *) (relation)->rd_options)->pendingListCleanupSize : \
|
||||
gin_pending_list_limit)
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include "access/amapi.h"
|
||||
#include "access/itup.h"
|
||||
#include "access/sdir.h"
|
||||
#include "catalog/pg_am_d.h"
|
||||
#include "lib/stringinfo.h"
|
||||
#include "storage/bufmgr.h"
|
||||
#include "storage/lockdefs.h"
|
||||
@@ -263,6 +264,21 @@ typedef struct HashMetaPageData
|
||||
|
||||
typedef HashMetaPageData *HashMetaPage;
|
||||
|
||||
typedef struct HashOptions
|
||||
{
|
||||
int32 varlena_header_; /* varlena header (do not touch directly!) */
|
||||
int fillfactor; /* page fill factor in percent (0..100) */
|
||||
} HashOptions;
|
||||
|
||||
#define HashGetFillFactor(relation) \
|
||||
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
|
||||
relation->rd_rel->relam == HASH_AM_OID), \
|
||||
(relation)->rd_options ? \
|
||||
((HashOptions *) (relation)->rd_options)->fillfactor : \
|
||||
HASH_DEFAULT_FILLFACTOR)
|
||||
#define HashGetTargetPageUsage(relation) \
|
||||
(BLCKSZ * HashGetFillFactor(relation) / 100)
|
||||
|
||||
/*
|
||||
* Maximum size of a hash index item (it's okay to have only one per page)
|
||||
*/
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include "access/itup.h"
|
||||
#include "access/sdir.h"
|
||||
#include "access/xlogreader.h"
|
||||
#include "catalog/pg_am_d.h"
|
||||
#include "catalog/pg_index.h"
|
||||
#include "lib/stringinfo.h"
|
||||
#include "storage/bufmgr.h"
|
||||
@@ -680,6 +681,23 @@ typedef BTScanOpaqueData *BTScanOpaque;
|
||||
#define SK_BT_DESC (INDOPTION_DESC << SK_BT_INDOPTION_SHIFT)
|
||||
#define SK_BT_NULLS_FIRST (INDOPTION_NULLS_FIRST << SK_BT_INDOPTION_SHIFT)
|
||||
|
||||
typedef struct BTOptions
|
||||
{
|
||||
int32 varlena_header_; /* varlena header (do not touch directly!) */
|
||||
int fillfactor; /* page fill factor in percent (0..100) */
|
||||
/* fraction of newly inserted tuples prior to trigger index cleanup */
|
||||
float8 vacuum_cleanup_index_scale_factor;
|
||||
} BTOptions;
|
||||
|
||||
#define BTGetFillFactor(relation) \
|
||||
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
|
||||
relation->rd_rel->relam == BTREE_AM_OID), \
|
||||
(relation)->rd_options ? \
|
||||
((BTOptions *) (relation)->rd_options)->fillfactor : \
|
||||
BTREE_DEFAULT_FILLFACTOR)
|
||||
#define BTGetTargetPageFreeSpace(relation) \
|
||||
(BLCKSZ * (100 - BTGetFillFactor(relation)) / 100)
|
||||
|
||||
/*
|
||||
* Constant definition for progress reporting. Phase numbers must match
|
||||
* btbuildphasename.
|
||||
|
@@ -19,10 +19,6 @@
|
||||
#include "lib/stringinfo.h"
|
||||
|
||||
|
||||
/* reloption parameters */
|
||||
#define SPGIST_MIN_FILLFACTOR 10
|
||||
#define SPGIST_DEFAULT_FILLFACTOR 80
|
||||
|
||||
/* SPGiST opclass support function numbers */
|
||||
#define SPGIST_CONFIG_PROC 1
|
||||
#define SPGIST_CHOOSE_PROC 2
|
||||
|
@@ -16,12 +16,29 @@
|
||||
|
||||
#include "access/itup.h"
|
||||
#include "access/spgist.h"
|
||||
#include "catalog/pg_am_d.h"
|
||||
#include "nodes/tidbitmap.h"
|
||||
#include "storage/buf.h"
|
||||
#include "utils/geo_decls.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
|
||||
typedef struct SpGistOptions
|
||||
{
|
||||
int32 varlena_header_; /* varlena header (do not touch directly!) */
|
||||
int fillfactor; /* page fill factor in percent (0..100) */
|
||||
} SpGistOptions;
|
||||
|
||||
#define SpGistGetFillFactor(relation) \
|
||||
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
|
||||
relation->rd_rel->relam == SPGIST_AM_OID), \
|
||||
(relation)->rd_options ? \
|
||||
((SpGistOptions *) (relation)->rd_options)->fillfactor : \
|
||||
SPGIST_DEFAULT_FILLFACTOR)
|
||||
#define SpGistGetTargetPageFreeSpace(relation) \
|
||||
(BLCKSZ * (100 - SpGistGetFillFactor(relation)) / 100)
|
||||
|
||||
|
||||
/* Page numbers of fixed-location pages */
|
||||
#define SPGIST_METAPAGE_BLKNO (0) /* metapage */
|
||||
#define SPGIST_ROOT_BLKNO (1) /* root for normal entries */
|
||||
@@ -423,6 +440,11 @@ typedef SpGistDeadTupleData *SpGistDeadTuple;
|
||||
#define GBUF_REQ_NULLS(flags) ((flags) & GBUF_NULLS)
|
||||
|
||||
/* spgutils.c */
|
||||
|
||||
/* reloption parameters */
|
||||
#define SPGIST_MIN_FILLFACTOR 10
|
||||
#define SPGIST_DEFAULT_FILLFACTOR 80
|
||||
|
||||
extern SpGistCache *spgGetCache(Relation index);
|
||||
extern void initSpGistState(SpGistState *state, Relation index);
|
||||
extern Buffer SpGistNewBuffer(Relation index);
|
||||
|
Reference in New Issue
Block a user