@ -1474,9 +1474,6 @@ fillRelOptions(void *rdopts, Size basesize,
bytea *
default_reloptions ( Datum reloptions , bool validate , relopt_kind kind )
{
relopt_value * options ;
StdRdOptions * rdopts ;
int numoptions ;
static const relopt_parse_elt tab [ ] = {
{ " fillfactor " , RELOPT_TYPE_INT , offsetof ( StdRdOptions , fillfactor ) } ,
{ " autovacuum_enabled " , RELOPT_TYPE_BOOL ,
@ -1521,20 +1518,57 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
offsetof ( StdRdOptions , vacuum_truncate ) }
} ;
return ( bytea * ) build_reloptions ( reloptions , validate , kind ,
sizeof ( StdRdOptions ) ,
tab , lengthof ( tab ) ) ;
}
/*
* build_reloptions
*
* Parses " reloptions " provided by the caller , returning them in a
* structure containing the parsed options . The parsing is done with
* the help of a parsing table describing the allowed options , defined
* by " relopt_elems " of length " num_relopt_elems " .
*
* " validate " must be true if reloptions value is freshly built by
* transformRelOptions ( ) , as opposed to being read from the catalog , in which
* case the values contained in it must already be valid .
*
* NULL is returned if the passed - in options did not match any of the options
* in the parsing table , unless validate is true in which case an error would
* be reported .
*/
void *
build_reloptions ( Datum reloptions , bool validate ,
relopt_kind kind ,
Size relopt_struct_size ,
const relopt_parse_elt * relopt_elems ,
int num_relopt_elems )
{
int numoptions ;
relopt_value * options ;
void * rdopts ;
/* parse options specific to given relation option kind */
options = parseRelOptions ( reloptions , validate , kind , & numoptions ) ;
Assert ( numoptions < = num_relopt_elems ) ;
/* if none set, we're done */
if ( numoptions = = 0 )
{
Assert ( options = = NULL ) ;
return NULL ;
}
rdopts = allocateReloptStruct ( sizeof ( StdRdOptions ) , options , numoptions ) ;
fillRelOptions ( ( void * ) rdopts , sizeof ( StdRdOptions ) , options , numoptions ,
validate , tab , lengthof ( tab ) ) ;
/* allocate and fill the structure */
rdopts = allocateReloptStruct ( relopt_struct_size , options , numoptions ) ;
fillRelOptions ( rdopts , relopt_struct_size , options , numoptions ,
validate , relopt_elems , num_relopt_elems ) ;
pfree ( options ) ;
return ( bytea * ) rdopts ;
return rdopts ;
}
/*
@ -1543,9 +1577,6 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
bytea *
view_reloptions ( Datum reloptions , bool validate )
{
relopt_value * options ;
ViewOptions * vopts ;
int numoptions ;
static const relopt_parse_elt tab [ ] = {
{ " security_barrier " , RELOPT_TYPE_BOOL ,
offsetof ( ViewOptions , security_barrier ) } ,
@ -1553,20 +1584,10 @@ view_reloptions(Datum reloptions, bool validate)
offsetof ( ViewOptions , check_option ) }
} ;
options = parseRelOptions ( reloptions , validate , RELOPT_KIND_VIEW , & numoptions ) ;
/* if none set, we're done */
if ( numoptions = = 0 )
return NULL ;
vopts = allocateReloptStruct ( sizeof ( ViewOptions ) , options , numoptions ) ;
fillRelOptions ( ( void * ) vopts , sizeof ( ViewOptions ) , options , numoptions ,
validate , tab , lengthof ( tab ) ) ;
pfree ( options ) ;
return ( bytea * ) vopts ;
return ( bytea * ) build_reloptions ( reloptions , validate ,
RELOPT_KIND_VIEW ,
sizeof ( ViewOptions ) ,
tab , lengthof ( tab ) ) ;
}
/*
@ -1628,29 +1649,15 @@ index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
bytea *
attribute_reloptions ( Datum reloptions , bool validate )
{
relopt_value * options ;
AttributeOpts * aopts ;
int numoptions ;
static const relopt_parse_elt tab [ ] = {
{ " n_distinct " , RELOPT_TYPE_REAL , offsetof ( AttributeOpts , n_distinct ) } ,
{ " n_distinct_inherited " , RELOPT_TYPE_REAL , offsetof ( AttributeOpts , n_distinct_inherited ) }
} ;
options = parseRelOptions ( reloptions , validate , RELOPT_KIND_ATTRIBUTE ,
& numoptions ) ;
/* if none set, we're done */
if ( numoptions = = 0 )
return NULL ;
aopts = allocateReloptStruct ( sizeof ( AttributeOpts ) , options , numoptions ) ;
fillRelOptions ( ( void * ) aopts , sizeof ( AttributeOpts ) , options , numoptions ,
validate , tab , lengthof ( tab ) ) ;
pfree ( options ) ;
return ( bytea * ) aopts ;
return ( bytea * ) build_reloptions ( reloptions , validate ,
RELOPT_KIND_ATTRIBUTE ,
sizeof ( AttributeOpts ) ,
tab , lengthof ( tab ) ) ;
}
/*
@ -1659,30 +1666,16 @@ attribute_reloptions(Datum reloptions, bool validate)
bytea *
tablespace_reloptions ( Datum reloptions , bool validate )
{
relopt_value * options ;
TableSpaceOpts * tsopts ;
int numoptions ;
static const relopt_parse_elt tab [ ] = {
{ " random_page_cost " , RELOPT_TYPE_REAL , offsetof ( TableSpaceOpts , random_page_cost ) } ,
{ " seq_page_cost " , RELOPT_TYPE_REAL , offsetof ( TableSpaceOpts , seq_page_cost ) } ,
{ " effective_io_concurrency " , RELOPT_TYPE_INT , offsetof ( TableSpaceOpts , effective_io_concurrency ) }
} ;
options = parseRelOptions ( reloptions , validate , RELOPT_KIND_TABLESPACE ,
& numoptions ) ;
/* if none set, we're done */
if ( numoptions = = 0 )
return NULL ;
tsopts = allocateReloptStruct ( sizeof ( TableSpaceOpts ) , options , numoptions ) ;
fillRelOptions ( ( void * ) tsopts , sizeof ( TableSpaceOpts ) , options , numoptions ,
validate , tab , lengthof ( tab ) ) ;
pfree ( options ) ;
return ( bytea * ) tsopts ;
return ( bytea * ) build_reloptions ( reloptions , validate ,
RELOPT_KIND_TABLESPACE ,
sizeof ( TableSpaceOpts ) ,
tab , lengthof ( tab ) ) ;
}
/*