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

Commit3534fa2

Browse files
committed
Refactor code building relation options
Historically, the code to build relation options has been shaped thesame way in multiple code paths by using a set of datums in input withthe options parsed with a static table which is then filled with theoption values. This introduces a new common routine in reloptions.c todo most of the legwork for the in-core code paths.Author: Amit LangoteReviewed-by: Michael PaquierDiscussion:https://postgr.es/m/CA+HiwqGsoSn_uTPPYT19WrtR7oYpYtv4CdS0xuedTKiHHWuk_g@mail.gmail.com
1 parent5102f39 commit3534fa2

File tree

7 files changed

+82
-133
lines changed

7 files changed

+82
-133
lines changed

‎contrib/bloom/blutils.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -475,18 +475,18 @@ BloomInitMetapage(Relation index)
475475
bytea*
476476
bloptions(Datumreloptions,boolvalidate)
477477
{
478-
relopt_value*options;
479-
intnumoptions;
480478
BloomOptions*rdopts;
481479

482480
/* Parse the user-given reloptions */
483-
options=parseRelOptions(reloptions,validate,bl_relopt_kind,&numoptions);
484-
rdopts=allocateReloptStruct(sizeof(BloomOptions),options,numoptions);
485-
fillRelOptions((void*)rdopts,sizeof(BloomOptions),options,numoptions,
486-
validate,bl_relopt_tab,lengthof(bl_relopt_tab));
481+
rdopts= (BloomOptions*)build_reloptions(reloptions,validate,
482+
bl_relopt_kind,
483+
sizeof(BloomOptions),
484+
bl_relopt_tab,
485+
lengthof(bl_relopt_tab));
487486

488487
/* Convert signature length from # of bits to # to words, rounding up */
489-
rdopts->bloomLength= (rdopts->bloomLength+SIGNWORDBITS-1) /SIGNWORDBITS;
488+
if (rdopts)
489+
rdopts->bloomLength= (rdopts->bloomLength+SIGNWORDBITS-1) /SIGNWORDBITS;
490490

491491
return (bytea*)rdopts;
492492
}

‎src/backend/access/brin/brin.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -820,29 +820,15 @@ brinvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
820820
bytea*
821821
brinoptions(Datumreloptions,boolvalidate)
822822
{
823-
relopt_value*options;
824-
BrinOptions*rdopts;
825-
intnumoptions;
826823
staticconstrelopt_parse_elttab[]= {
827824
{"pages_per_range",RELOPT_TYPE_INT, offsetof(BrinOptions,pagesPerRange)},
828825
{"autosummarize",RELOPT_TYPE_BOOL, offsetof(BrinOptions,autosummarize)}
829826
};
830827

831-
options=parseRelOptions(reloptions,validate,RELOPT_KIND_BRIN,
832-
&numoptions);
833-
834-
/* if none set, we're done */
835-
if (numoptions==0)
836-
returnNULL;
837-
838-
rdopts=allocateReloptStruct(sizeof(BrinOptions),options,numoptions);
839-
840-
fillRelOptions((void*)rdopts,sizeof(BrinOptions),options,numoptions,
841-
validate,tab,lengthof(tab));
842-
843-
pfree(options);
844-
845-
return (bytea*)rdopts;
828+
return (bytea*)build_reloptions(reloptions,validate,
829+
RELOPT_KIND_BRIN,
830+
sizeof(BrinOptions),
831+
tab,lengthof(tab));
846832
}
847833

848834
/*

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

Lines changed: 54 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,9 +1474,6 @@ fillRelOptions(void *rdopts, Size basesize,
14741474
bytea*
14751475
default_reloptions(Datumreloptions,boolvalidate,relopt_kindkind)
14761476
{
1477-
relopt_value*options;
1478-
StdRdOptions*rdopts;
1479-
intnumoptions;
14801477
staticconstrelopt_parse_elttab[]= {
14811478
{"fillfactor",RELOPT_TYPE_INT, offsetof(StdRdOptions,fillfactor)},
14821479
{"autovacuum_enabled",RELOPT_TYPE_BOOL,
@@ -1521,20 +1518,57 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
15211518
offsetof(StdRdOptions,vacuum_truncate)}
15221519
};
15231520

1521+
return (bytea*)build_reloptions(reloptions,validate,kind,
1522+
sizeof(StdRdOptions),
1523+
tab,lengthof(tab));
1524+
}
1525+
1526+
/*
1527+
* build_reloptions
1528+
*
1529+
* Parses "reloptions" provided by the caller, returning them in a
1530+
* structure containing the parsed options. The parsing is done with
1531+
* the help of a parsing table describing the allowed options, defined
1532+
* by "relopt_elems" of length "num_relopt_elems".
1533+
*
1534+
* "validate" must be true if reloptions value is freshly built by
1535+
* transformRelOptions(), as opposed to being read from the catalog, in which
1536+
* case the values contained in it must already be valid.
1537+
*
1538+
* NULL is returned if the passed-in options did not match any of the options
1539+
* in the parsing table, unless validate is true in which case an error would
1540+
* be reported.
1541+
*/
1542+
void*
1543+
build_reloptions(Datumreloptions,boolvalidate,
1544+
relopt_kindkind,
1545+
Sizerelopt_struct_size,
1546+
constrelopt_parse_elt*relopt_elems,
1547+
intnum_relopt_elems)
1548+
{
1549+
intnumoptions;
1550+
relopt_value*options;
1551+
void*rdopts;
1552+
1553+
/* parse options specific to given relation option kind */
15241554
options=parseRelOptions(reloptions,validate,kind,&numoptions);
1555+
Assert(numoptions <=num_relopt_elems);
15251556

15261557
/* if none set, we're done */
15271558
if (numoptions==0)
1559+
{
1560+
Assert(options==NULL);
15281561
returnNULL;
1562+
}
15291563

1530-
rdopts=allocateReloptStruct(sizeof(StdRdOptions),options,numoptions);
1531-
1532-
fillRelOptions((void*)rdopts,sizeof(StdRdOptions),options,numoptions,
1533-
validate,tab,lengthof(tab));
1564+
/* allocate and fill the structure */
1565+
rdopts=allocateReloptStruct(relopt_struct_size,options,numoptions);
1566+
fillRelOptions(rdopts,relopt_struct_size,options,numoptions,
1567+
validate,relopt_elems,num_relopt_elems);
15341568

15351569
pfree(options);
15361570

1537-
return(bytea*)rdopts;
1571+
returnrdopts;
15381572
}
15391573

15401574
/*
@@ -1543,30 +1577,17 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
15431577
bytea*
15441578
view_reloptions(Datumreloptions,boolvalidate)
15451579
{
1546-
relopt_value*options;
1547-
ViewOptions*vopts;
1548-
intnumoptions;
15491580
staticconstrelopt_parse_elttab[]= {
15501581
{"security_barrier",RELOPT_TYPE_BOOL,
15511582
offsetof(ViewOptions,security_barrier)},
15521583
{"check_option",RELOPT_TYPE_ENUM,
15531584
offsetof(ViewOptions,check_option)}
15541585
};
15551586

1556-
options=parseRelOptions(reloptions,validate,RELOPT_KIND_VIEW,&numoptions);
1557-
1558-
/* if none set, we're done */
1559-
if (numoptions==0)
1560-
returnNULL;
1561-
1562-
vopts=allocateReloptStruct(sizeof(ViewOptions),options,numoptions);
1563-
1564-
fillRelOptions((void*)vopts,sizeof(ViewOptions),options,numoptions,
1565-
validate,tab,lengthof(tab));
1566-
1567-
pfree(options);
1568-
1569-
return (bytea*)vopts;
1587+
return (bytea*)build_reloptions(reloptions,validate,
1588+
RELOPT_KIND_VIEW,
1589+
sizeof(ViewOptions),
1590+
tab,lengthof(tab));
15701591
}
15711592

15721593
/*
@@ -1628,29 +1649,15 @@ index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
16281649
bytea*
16291650
attribute_reloptions(Datumreloptions,boolvalidate)
16301651
{
1631-
relopt_value*options;
1632-
AttributeOpts*aopts;
1633-
intnumoptions;
16341652
staticconstrelopt_parse_elttab[]= {
16351653
{"n_distinct",RELOPT_TYPE_REAL, offsetof(AttributeOpts,n_distinct)},
16361654
{"n_distinct_inherited",RELOPT_TYPE_REAL, offsetof(AttributeOpts,n_distinct_inherited)}
16371655
};
16381656

1639-
options=parseRelOptions(reloptions,validate,RELOPT_KIND_ATTRIBUTE,
1640-
&numoptions);
1641-
1642-
/* if none set, we're done */
1643-
if (numoptions==0)
1644-
returnNULL;
1645-
1646-
aopts=allocateReloptStruct(sizeof(AttributeOpts),options,numoptions);
1647-
1648-
fillRelOptions((void*)aopts,sizeof(AttributeOpts),options,numoptions,
1649-
validate,tab,lengthof(tab));
1650-
1651-
pfree(options);
1652-
1653-
return (bytea*)aopts;
1657+
return (bytea*)build_reloptions(reloptions,validate,
1658+
RELOPT_KIND_ATTRIBUTE,
1659+
sizeof(AttributeOpts),
1660+
tab,lengthof(tab));
16541661
}
16551662

16561663
/*
@@ -1659,30 +1666,16 @@ attribute_reloptions(Datum reloptions, bool validate)
16591666
bytea*
16601667
tablespace_reloptions(Datumreloptions,boolvalidate)
16611668
{
1662-
relopt_value*options;
1663-
TableSpaceOpts*tsopts;
1664-
intnumoptions;
16651669
staticconstrelopt_parse_elttab[]= {
16661670
{"random_page_cost",RELOPT_TYPE_REAL, offsetof(TableSpaceOpts,random_page_cost)},
16671671
{"seq_page_cost",RELOPT_TYPE_REAL, offsetof(TableSpaceOpts,seq_page_cost)},
16681672
{"effective_io_concurrency",RELOPT_TYPE_INT, offsetof(TableSpaceOpts,effective_io_concurrency)}
16691673
};
16701674

1671-
options=parseRelOptions(reloptions,validate,RELOPT_KIND_TABLESPACE,
1672-
&numoptions);
1673-
1674-
/* if none set, we're done */
1675-
if (numoptions==0)
1676-
returnNULL;
1677-
1678-
tsopts=allocateReloptStruct(sizeof(TableSpaceOpts),options,numoptions);
1679-
1680-
fillRelOptions((void*)tsopts,sizeof(TableSpaceOpts),options,numoptions,
1681-
validate,tab,lengthof(tab));
1682-
1683-
pfree(options);
1684-
1685-
return (bytea*)tsopts;
1675+
return (bytea*)build_reloptions(reloptions,validate,
1676+
RELOPT_KIND_TABLESPACE,
1677+
sizeof(TableSpaceOpts),
1678+
tab,lengthof(tab));
16861679
}
16871680

16881681
/*

‎src/backend/access/gin/ginutil.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -602,30 +602,16 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum,
602602
bytea*
603603
ginoptions(Datumreloptions,boolvalidate)
604604
{
605-
relopt_value*options;
606-
GinOptions*rdopts;
607-
intnumoptions;
608605
staticconstrelopt_parse_elttab[]= {
609606
{"fastupdate",RELOPT_TYPE_BOOL, offsetof(GinOptions,useFastUpdate)},
610607
{"gin_pending_list_limit",RELOPT_TYPE_INT, offsetof(GinOptions,
611608
pendingListCleanupSize)}
612609
};
613610

614-
options=parseRelOptions(reloptions,validate,RELOPT_KIND_GIN,
615-
&numoptions);
616-
617-
/* if none set, we're done */
618-
if (numoptions==0)
619-
returnNULL;
620-
621-
rdopts=allocateReloptStruct(sizeof(GinOptions),options,numoptions);
622-
623-
fillRelOptions((void*)rdopts,sizeof(GinOptions),options,numoptions,
624-
validate,tab,lengthof(tab));
625-
626-
pfree(options);
627-
628-
return (bytea*)rdopts;
611+
return (bytea*)build_reloptions(reloptions,validate,
612+
RELOPT_KIND_GIN,
613+
sizeof(GinOptions),
614+
tab,lengthof(tab));
629615
}
630616

631617
/*

‎src/backend/access/gist/gistutil.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -908,29 +908,15 @@ gistPageRecyclable(Page page)
908908
bytea*
909909
gistoptions(Datumreloptions,boolvalidate)
910910
{
911-
relopt_value*options;
912-
GiSTOptions*rdopts;
913-
intnumoptions;
914911
staticconstrelopt_parse_elttab[]= {
915912
{"fillfactor",RELOPT_TYPE_INT, offsetof(GiSTOptions,fillfactor)},
916913
{"buffering",RELOPT_TYPE_ENUM, offsetof(GiSTOptions,buffering_mode)}
917914
};
918915

919-
options=parseRelOptions(reloptions,validate,RELOPT_KIND_GIST,
920-
&numoptions);
921-
922-
/* if none set, we're done */
923-
if (numoptions==0)
924-
returnNULL;
925-
926-
rdopts=allocateReloptStruct(sizeof(GiSTOptions),options,numoptions);
927-
928-
fillRelOptions((void*)rdopts,sizeof(GiSTOptions),options,numoptions,
929-
validate,tab,lengthof(tab));
930-
931-
pfree(options);
932-
933-
return (bytea*)rdopts;
916+
return (bytea*)build_reloptions(reloptions,validate,
917+
RELOPT_KIND_GIST,
918+
sizeof(GiSTOptions),
919+
tab,lengthof(tab));
934920
}
935921

936922
/*

‎src/include/access/reloptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ extern void fillRelOptions(void *rdopts, Size basesize,
296296
relopt_value*options,intnumoptions,
297297
boolvalidate,
298298
constrelopt_parse_elt*elems,intnelems);
299+
externvoid*build_reloptions(Datumreloptions,boolvalidate,
300+
relopt_kindkind,
301+
Sizerelopt_struct_size,
302+
constrelopt_parse_elt*relopt_elems,
303+
intnum_relopt_elems);
299304

300305
externbytea*default_reloptions(Datumreloptions,boolvalidate,
301306
relopt_kindkind);

‎src/test/modules/dummy_index_am/dummy_index_am.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,10 @@ dicostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
222222
staticbytea*
223223
dioptions(Datumreloptions,boolvalidate)
224224
{
225-
relopt_value*options;
226-
intnumoptions;
227-
DummyIndexOptions*rdopts;
228-
229-
/* Parse the user-given reloptions */
230-
options=parseRelOptions(reloptions,validate,di_relopt_kind,&numoptions);
231-
rdopts=allocateReloptStruct(sizeof(DummyIndexOptions),options,numoptions);
232-
fillRelOptions((void*)rdopts,sizeof(DummyIndexOptions),options,numoptions,
233-
validate,di_relopt_tab,lengthof(di_relopt_tab));
234-
235-
return (bytea*)rdopts;
225+
return (bytea*)build_reloptions(reloptions,validate,
226+
di_relopt_kind,
227+
sizeof(DummyIndexOptions),
228+
di_relopt_tab,lengthof(di_relopt_tab));
236229
}
237230

238231
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp