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)

‎src/include/access/hash.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include"access/amapi.h"
2121
#include"access/itup.h"
2222
#include"access/sdir.h"
23+
#include"catalog/pg_am_d.h"
2324
#include"lib/stringinfo.h"
2425
#include"storage/bufmgr.h"
2526
#include"storage/lockdefs.h"
@@ -263,6 +264,21 @@ typedef struct HashMetaPageData
263264

264265
typedefHashMetaPageData*HashMetaPage;
265266

267+
typedefstructHashOptions
268+
{
269+
int32varlena_header_;/* varlena header (do not touch directly!) */
270+
intfillfactor;/* page fill factor in percent (0..100) */
271+
}HashOptions;
272+
273+
#defineHashGetFillFactor(relation) \
274+
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
275+
relation->rd_rel->relam == HASH_AM_OID), \
276+
(relation)->rd_options ? \
277+
((HashOptions *) (relation)->rd_options)->fillfactor :\
278+
HASH_DEFAULT_FILLFACTOR)
279+
#defineHashGetTargetPageUsage(relation) \
280+
(BLCKSZ * HashGetFillFactor(relation) / 100)
281+
266282
/*
267283
* Maximum size of a hash index item (it's okay to have only one per page)
268284
*/

‎src/include/access/nbtree.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include"access/itup.h"
1919
#include"access/sdir.h"
2020
#include"access/xlogreader.h"
21+
#include"catalog/pg_am_d.h"
2122
#include"catalog/pg_index.h"
2223
#include"lib/stringinfo.h"
2324
#include"storage/bufmgr.h"
@@ -680,6 +681,23 @@ typedef BTScanOpaqueData *BTScanOpaque;
680681
#defineSK_BT_DESC(INDOPTION_DESC << SK_BT_INDOPTION_SHIFT)
681682
#defineSK_BT_NULLS_FIRST(INDOPTION_NULLS_FIRST << SK_BT_INDOPTION_SHIFT)
682683

684+
typedefstructBTOptions
685+
{
686+
int32varlena_header_;/* varlena header (do not touch directly!) */
687+
intfillfactor;/* page fill factor in percent (0..100) */
688+
/* fraction of newly inserted tuples prior to trigger index cleanup */
689+
float8vacuum_cleanup_index_scale_factor;
690+
}BTOptions;
691+
692+
#defineBTGetFillFactor(relation) \
693+
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
694+
relation->rd_rel->relam == BTREE_AM_OID), \
695+
(relation)->rd_options ? \
696+
((BTOptions *) (relation)->rd_options)->fillfactor : \
697+
BTREE_DEFAULT_FILLFACTOR)
698+
#defineBTGetTargetPageFreeSpace(relation) \
699+
(BLCKSZ * (100 - BTGetFillFactor(relation)) / 100)
700+
683701
/*
684702
* Constant definition for progress reporting. Phase numbers must match
685703
* btbuildphasename.

‎src/include/access/spgist.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
#include"lib/stringinfo.h"
2020

2121

22-
/* reloption parameters */
23-
#defineSPGIST_MIN_FILLFACTOR10
24-
#defineSPGIST_DEFAULT_FILLFACTOR80
25-
2622
/* SPGiST opclass support function numbers */
2723
#defineSPGIST_CONFIG_PROC1
2824
#defineSPGIST_CHOOSE_PROC2

‎src/include/access/spgist_private.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,29 @@
1616

1717
#include"access/itup.h"
1818
#include"access/spgist.h"
19+
#include"catalog/pg_am_d.h"
1920
#include"nodes/tidbitmap.h"
2021
#include"storage/buf.h"
2122
#include"utils/geo_decls.h"
2223
#include"utils/relcache.h"
2324

2425

26+
typedefstructSpGistOptions
27+
{
28+
int32varlena_header_;/* varlena header (do not touch directly!) */
29+
intfillfactor;/* page fill factor in percent (0..100) */
30+
}SpGistOptions;
31+
32+
#defineSpGistGetFillFactor(relation) \
33+
(AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
34+
relation->rd_rel->relam == SPGIST_AM_OID), \
35+
(relation)->rd_options ? \
36+
((SpGistOptions *) (relation)->rd_options)->fillfactor : \
37+
SPGIST_DEFAULT_FILLFACTOR)
38+
#defineSpGistGetTargetPageFreeSpace(relation) \
39+
(BLCKSZ * (100 - SpGistGetFillFactor(relation)) / 100)
40+
41+
2542
/* Page numbers of fixed-location pages */
2643
#defineSPGIST_METAPAGE_BLKNO (0)/* metapage */
2744
#defineSPGIST_ROOT_BLKNO (1)/* root for normal entries */
@@ -423,6 +440,11 @@ typedef SpGistDeadTupleData *SpGistDeadTuple;
423440
#defineGBUF_REQ_NULLS(flags)((flags) & GBUF_NULLS)
424441

425442
/* spgutils.c */
443+
444+
/* reloption parameters */
445+
#defineSPGIST_MIN_FILLFACTOR10
446+
#defineSPGIST_DEFAULT_FILLFACTOR80
447+
426448
externSpGistCache*spgGetCache(Relationindex);
427449
externvoidinitSpGistState(SpGistState*state,Relationindex);
428450
externBufferSpGistNewBuffer(Relationindex);

‎src/include/utils/rel.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ typedef struct ForeignKeyCacheInfo
235235

236236
/*
237237
* StdRdOptions
238-
*Standard contents of rd_options for heaps and generic indexes.
238+
*Standard contents of rd_options for heaps.
239239
*
240240
* RelationGetFillFactor() and RelationGetTargetPageFreeSpace() can only
241241
* be applied to relations that use this format or a superset for
@@ -265,7 +265,6 @@ typedef struct StdRdOptions
265265
int32vl_len_;/* varlena header (do not touch directly!) */
266266
intfillfactor;/* page fill factor in percent (0..100) */
267267
/* fraction of newly inserted tuples prior to trigger index cleanup */
268-
float8vacuum_cleanup_index_scale_factor;
269268
inttoast_tuple_target;/* target for tuple toasting */
270269
AutoVacOptsautovacuum;/* autovacuum-related options */
271270
booluser_catalog_table;/* use as an additional catalog relation */

‎src/tools/pgindent/typedefs.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ BTInsertStateData
171171
BTLeader
172172
BTMetaPageData
173173
BTOneVacInfo
174+
BTOptions
174175
BTPS_State
175176
BTPageOpaque
176177
BTPageOpaqueData
@@ -978,6 +979,7 @@ HashJoinTuple
978979
HashMemoryChunk
979980
HashMetaPage
980981
HashMetaPageData
982+
HashOptions
981983
HashPageOpaque
982984
HashPageOpaqueData
983985
HashPageStat
@@ -2270,6 +2272,7 @@ SpGistLeafTupleData
22702272
SpGistMetaPageData
22712273
SpGistNodeTuple
22722274
SpGistNodeTupleData
2275+
SpGistOptions
22732276
SpGistPageOpaque
22742277
SpGistPageOpaqueData
22752278
SpGistScanOpaque

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp