Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4cb658a

Browse files
committed
Refactor reloption handling for index AMs in-core
This reworks the reloption parsing and build of a couple of index AMs bycreating new structures for each index AM's options. This split wasalready done for BRIN, GIN and GiST (which actually has a fillfactorparameter), but not for hash, B-tree and SPGiST which relied onStdRdOptions due to an overlap with the default option set.This saves a couple of bytes for rd_options in each relcache entry withindexes making use of relation options, and brings more consistencybetween all index AMs. While on it, add a couple of AssertMacro() callsto make sure that utility macros to grab values of reloptions are usedwith the expected index AM.Author: Nikolay ShaplovReviewed-by: Amit Langote, Michael Paquier, Álvaro Herrera, Dent JohnDiscussion:https://postgr.es/m/4127670.gFlpRb6XCm@x200m
1 parent114541d commit4cb658a

File tree

16 files changed

+110
-24
lines changed

16 files changed

+110
-24
lines changed

‎src/backend/access/common/reloptions.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include"access/htup_details.h"
2424
#include"access/nbtree.h"
2525
#include"access/reloptions.h"
26-
#include"access/spgist.h"
26+
#include"access/spgist_private.h"
2727
#include"catalog/pg_type.h"
2828
#include"commands/defrem.h"
2929
#include"commands/tablespace.h"
@@ -1521,8 +1521,6 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
15211521
offsetof(StdRdOptions,user_catalog_table)},
15221522
{"parallel_workers",RELOPT_TYPE_INT,
15231523
offsetof(StdRdOptions,parallel_workers)},
1524-
{"vacuum_cleanup_index_scale_factor",RELOPT_TYPE_REAL,
1525-
offsetof(StdRdOptions,vacuum_cleanup_index_scale_factor)},
15261524
{"vacuum_index_cleanup",RELOPT_TYPE_BOOL,
15271525
offsetof(StdRdOptions,vacuum_index_cleanup)},
15281526
{"vacuum_truncate",RELOPT_TYPE_BOOL,

‎src/backend/access/hash/hashpage.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ _hash_init(Relation rel, double num_tuples, ForkNumber forkNum)
358358
data_width=sizeof(uint32);
359359
item_width=MAXALIGN(sizeof(IndexTupleData))+MAXALIGN(data_width)+
360360
sizeof(ItemIdData);/* include the line pointer */
361-
ffactor=RelationGetTargetPageUsage(rel,HASH_DEFAULT_FILLFACTOR) /item_width;
361+
ffactor=HashGetTargetPageUsage(rel) /item_width;
362362
/* keep to a sane range */
363363
if (ffactor<10)
364364
ffactor=10;

‎src/backend/access/hash/hashutil.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,14 @@ _hash_checkpage(Relation rel, Buffer buf, int flags)
289289
bytea*
290290
hashoptions(Datumreloptions,boolvalidate)
291291
{
292-
returndefault_reloptions(reloptions,validate,RELOPT_KIND_HASH);
292+
staticconstrelopt_parse_elttab[]= {
293+
{"fillfactor",RELOPT_TYPE_INT, offsetof(HashOptions,fillfactor)},
294+
};
295+
296+
return (bytea*)build_reloptions(reloptions,validate,
297+
RELOPT_KIND_HASH,
298+
sizeof(HashOptions),
299+
tab,lengthof(tab));
293300
}
294301

295302
/*

‎src/backend/access/nbtree/nbtree.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ _bt_vacuum_needs_cleanup(IndexVacuumInfo *info)
816816
}
817817
else
818818
{
819-
StdRdOptions*relopts;
819+
BTOptions*relopts;
820820
float8cleanup_scale_factor;
821821
float8prev_num_heap_tuples;
822822

@@ -827,7 +827,7 @@ _bt_vacuum_needs_cleanup(IndexVacuumInfo *info)
827827
* tuples exceeds vacuum_cleanup_index_scale_factor fraction of
828828
* original tuples count.
829829
*/
830-
relopts= (StdRdOptions*)info->index->rd_options;
830+
relopts= (BTOptions*)info->index->rd_options;
831831
cleanup_scale_factor= (relopts&&
832832
relopts->vacuum_cleanup_index_scale_factor >=0)
833833
?relopts->vacuum_cleanup_index_scale_factor

‎src/backend/access/nbtree/nbtsort.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,8 @@ _bt_pagestate(BTWriteState *wstate, uint32 level)
716716
if (level>0)
717717
state->btps_full= (BLCKSZ* (100-BTREE_NONLEAF_FILLFACTOR) /100);
718718
else
719-
state->btps_full=RelationGetTargetPageFreeSpace(wstate->index,
720-
BTREE_DEFAULT_FILLFACTOR);
719+
state->btps_full=BTGetTargetPageFreeSpace(wstate->index);
720+
721721
/* no parent level, yet */
722722
state->btps_next=NULL;
723723

‎src/backend/access/nbtree/nbtsplitloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ _bt_findsplitloc(Relation rel,
167167

168168
/* Count up total space in data items before actually scanning 'em */
169169
olddataitemstotal=rightspace- (int)PageGetExactFreeSpace(page);
170-
leaffillfactor=RelationGetFillFactor(rel,BTREE_DEFAULT_FILLFACTOR);
170+
leaffillfactor=BTGetFillFactor(rel);
171171

172172
/* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
173173
newitemsz+=sizeof(ItemIdData);

‎src/backend/access/nbtree/nbtutils.c‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,18 @@ BTreeShmemInit(void)
20142014
bytea*
20152015
btoptions(Datumreloptions,boolvalidate)
20162016
{
2017-
returndefault_reloptions(reloptions,validate,RELOPT_KIND_BTREE);
2017+
staticconstrelopt_parse_elttab[]= {
2018+
{"fillfactor",RELOPT_TYPE_INT, offsetof(BTOptions,fillfactor)},
2019+
{"vacuum_cleanup_index_scale_factor",RELOPT_TYPE_REAL,
2020+
offsetof(BTOptions,vacuum_cleanup_index_scale_factor)}
2021+
2022+
};
2023+
2024+
return (bytea*)build_reloptions(reloptions,validate,
2025+
RELOPT_KIND_BTREE,
2026+
sizeof(BTOptions),
2027+
tab,lengthof(tab));
2028+
20182029
}
20192030

20202031
/*

‎src/backend/access/spgist/spgutils.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,7 @@ SpGistGetBuffer(Relation index, int flags, int needSpace, bool *isNew)
408408
* related to the ones already on it. But fillfactor mustn't cause an
409409
* error for requests that would otherwise be legal.
410410
*/
411-
needSpace+=RelationGetTargetPageFreeSpace(index,
412-
SPGIST_DEFAULT_FILLFACTOR);
411+
needSpace+=SpGistGetTargetPageFreeSpace(index);
413412
needSpace=Min(needSpace,SPGIST_PAGE_CAPACITY);
414413

415414
/* Get the cache entry for this flags setting */
@@ -586,7 +585,15 @@ SpGistInitMetapage(Page page)
586585
bytea*
587586
spgoptions(Datumreloptions,boolvalidate)
588587
{
589-
returndefault_reloptions(reloptions,validate,RELOPT_KIND_SPGIST);
588+
staticconstrelopt_parse_elttab[]= {
589+
{"fillfactor",RELOPT_TYPE_INT, offsetof(SpGistOptions,fillfactor)},
590+
};
591+
592+
return (bytea*)build_reloptions(reloptions,validate,
593+
RELOPT_KIND_SPGIST,
594+
sizeof(SpGistOptions),
595+
tab,lengthof(tab));
596+
590597
}
591598

592599
/*

‎src/include/access/brin.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ typedef struct BrinStatsData
3737

3838
#defineBRIN_DEFAULT_PAGES_PER_RANGE128
3939
#defineBrinGetPagesPerRange(relation) \
40-
((relation)->rd_options ? \
40+
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
41+
relation->rd_rel->relam == BRIN_AM_OID), \
42+
(relation)->rd_options ? \
4143
((BrinOptions *) (relation)->rd_options)->pagesPerRange : \
4244
BRIN_DEFAULT_PAGES_PER_RANGE)
4345
#defineBrinGetAutoSummarize(relation) \
44-
((relation)->rd_options ? \
46+
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
47+
relation->rd_rel->relam == BRIN_AM_OID), \
48+
(relation)->rd_options ? \
4549
((BrinOptions *) (relation)->rd_options)->autosummarize : \
4650
false)
4751

‎src/include/access/gin_private.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include"access/gin.h"
1515
#include"access/ginblock.h"
1616
#include"access/itup.h"
17+
#include"catalog/pg_am_d.h"
1718
#include"fmgr.h"
1819
#include"storage/bufmgr.h"
1920
#include"lib/rbtree.h"
@@ -30,10 +31,14 @@ typedef struct GinOptions
3031

3132
#defineGIN_DEFAULT_USE_FASTUPDATEtrue
3233
#defineGinGetUseFastUpdate(relation) \
33-
((relation)->rd_options ? \
34+
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
35+
relation->rd_rel->relam == GIN_AM_OID), \
36+
(relation)->rd_options ? \
3437
((GinOptions *) (relation)->rd_options)->useFastUpdate : GIN_DEFAULT_USE_FASTUPDATE)
3538
#defineGinGetPendingListCleanupSize(relation) \
36-
((relation)->rd_options && \
39+
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
40+
relation->rd_rel->relam == GIN_AM_OID), \
41+
(relation)->rd_options && \
3742
((GinOptions *) (relation)->rd_options)->pendingListCleanupSize != -1 ? \
3843
((GinOptions *) (relation)->rd_options)->pendingListCleanupSize : \
3944
gin_pending_list_limit)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp