2424#include "access/nbtree.h"
2525#include "access/reloptions.h"
2626#include "access/spgist_private.h"
27+ #include "access/tableam.h"
2728#include "catalog/pg_type.h"
2829#include "commands/defrem.h"
2930#include "commands/tablespace.h"
4445 * value, upper and lower bounds (if applicable); for strings, consider a
4546 * validation routine.
4647 * (ii) add a record below (or use add_<type>_reloption).
47- * (iii) add it to the appropriate options struct (perhaps StdRdOptions )
48+ * (iii) add it to the appropriate options struct (perhaps HeapRdOptions )
4849 * (iv) add it to the appropriate handling routine (perhaps
4950 * default_reloptions)
5051 * (v) make sure the lock level is set correctly for that operation
@@ -1374,10 +1375,16 @@ untransformRelOptions(Datum options)
13741375 * tupdesc is pg_class' tuple descriptor. amoptions is a pointer to the index
13751376 * AM's options parser function in the case of a tuple corresponding to an
13761377 * index, or NULL otherwise.
1378+ *
1379+ * If common pointer is provided, then the corresponding struct will be
1380+ * filled with options that table AM exposes for external usage. That must
1381+ * be filled with defaults before passing here.
13771382 */
1383+
13781384bytea *
13791385extractRelOptions (HeapTuple tuple , TupleDesc tupdesc ,
1380- amoptions_function amoptions )
1386+ const TableAmRoutine * tableam , amoptions_function amoptions ,
1387+ CommonRdOptions * common )
13811388{
13821389 bytea * options ;
13831390 bool isnull ;
@@ -1399,7 +1406,8 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
13991406 case RELKIND_RELATION :
14001407 case RELKIND_TOASTVALUE :
14011408 case RELKIND_MATVIEW :
1402- options = heap_reloptions (classForm -> relkind , datum , false);
1409+ options = tableam_reloptions (tableam , classForm -> relkind ,
1410+ datum , common , false);
14031411 break ;
14041412 case RELKIND_PARTITIONED_TABLE :
14051413 options = partitioned_table_reloptions (datum , false);
@@ -1695,7 +1703,7 @@ parse_one_reloption(relopt_value *option, char *text_str, int text_len,
16951703 * Given the result from parseRelOptions, allocate a struct that's of the
16961704 * specified base size plus any extra space that's needed for string variables.
16971705 *
1698- * "base" should be sizeof(struct) of the reloptions struct (StdRdOptions or
1706+ * "base" should be sizeof(struct) of the reloptions struct (HeapRdOptions or
16991707 * equivalent).
17001708 */
17011709static void *
@@ -1832,59 +1840,95 @@ fillRelOptions(void *rdopts, Size basesize,
18321840
18331841
18341842/*
1835- * Option parser for anything that uses StdRdOptions .
1843+ * Option parser for anything that uses HeapRdOptions .
18361844 */
1837- bytea *
1845+ static bytea *
18381846default_reloptions (Datum reloptions , bool validate , relopt_kind kind )
18391847{
18401848 static const relopt_parse_elt tab [] = {
1841- {"fillfactor" , RELOPT_TYPE_INT , offsetof(StdRdOptions , fillfactor )},
1849+ {"fillfactor" , RELOPT_TYPE_INT , offsetof(HeapRdOptions , fillfactor )},
18421850 {"autovacuum_enabled" , RELOPT_TYPE_BOOL ,
1843- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , enabled )},
1851+ offsetof(HeapRdOptions , common ) +
1852+ offsetof(CommonRdOptions , autovacuum ) +
1853+ offsetof(AutoVacOpts , enabled )},
18441854 {"autovacuum_vacuum_threshold" , RELOPT_TYPE_INT ,
1845- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , vacuum_threshold )},
1855+ offsetof(HeapRdOptions , common ) +
1856+ offsetof(CommonRdOptions , autovacuum ) +
1857+ offsetof(AutoVacOpts , vacuum_threshold )},
18461858 {"autovacuum_vacuum_insert_threshold" , RELOPT_TYPE_INT ,
1847- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , vacuum_ins_threshold )},
1859+ offsetof(HeapRdOptions , common ) +
1860+ offsetof(CommonRdOptions , autovacuum ) +
1861+ offsetof(AutoVacOpts , vacuum_ins_threshold )},
18481862 {"autovacuum_analyze_threshold" , RELOPT_TYPE_INT ,
1849- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , analyze_threshold )},
1863+ offsetof(HeapRdOptions , common ) +
1864+ offsetof(CommonRdOptions , autovacuum ) +
1865+ offsetof(AutoVacOpts , analyze_threshold )},
18501866 {"autovacuum_vacuum_cost_limit" , RELOPT_TYPE_INT ,
1851- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , vacuum_cost_limit )},
1867+ offsetof(HeapRdOptions , common ) +
1868+ offsetof(CommonRdOptions , autovacuum ) +
1869+ offsetof(AutoVacOpts , vacuum_cost_limit )},
18521870 {"autovacuum_freeze_min_age" , RELOPT_TYPE_INT ,
1853- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , freeze_min_age )},
1871+ offsetof(HeapRdOptions , common ) +
1872+ offsetof(CommonRdOptions , autovacuum ) +
1873+ offsetof(AutoVacOpts , freeze_min_age )},
18541874 {"autovacuum_freeze_max_age" , RELOPT_TYPE_INT ,
1855- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , freeze_max_age )},
1875+ offsetof(HeapRdOptions , common ) +
1876+ offsetof(CommonRdOptions , autovacuum ) +
1877+ offsetof(AutoVacOpts , freeze_max_age )},
18561878 {"autovacuum_freeze_table_age" , RELOPT_TYPE_INT ,
1857- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , freeze_table_age )},
1879+ offsetof(HeapRdOptions , common ) +
1880+ offsetof(CommonRdOptions , autovacuum ) +
1881+ offsetof(AutoVacOpts , freeze_table_age )},
18581882 {"autovacuum_multixact_freeze_min_age" , RELOPT_TYPE_INT ,
1859- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , multixact_freeze_min_age )},
1883+ offsetof(HeapRdOptions , common ) +
1884+ offsetof(CommonRdOptions , autovacuum ) +
1885+ offsetof(AutoVacOpts , multixact_freeze_min_age )},
18601886 {"autovacuum_multixact_freeze_max_age" , RELOPT_TYPE_INT ,
1861- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , multixact_freeze_max_age )},
1887+ offsetof(HeapRdOptions , common ) +
1888+ offsetof(CommonRdOptions , autovacuum ) +
1889+ offsetof(AutoVacOpts , multixact_freeze_max_age )},
18621890 {"autovacuum_multixact_freeze_table_age" , RELOPT_TYPE_INT ,
1863- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , multixact_freeze_table_age )},
1891+ offsetof(HeapRdOptions , common ) +
1892+ offsetof(CommonRdOptions , autovacuum ) +
1893+ offsetof(AutoVacOpts , multixact_freeze_table_age )},
18641894 {"log_autovacuum_min_duration" , RELOPT_TYPE_INT ,
1865- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , log_min_duration )},
1895+ offsetof(HeapRdOptions , common ) +
1896+ offsetof(CommonRdOptions , autovacuum ) +
1897+ offsetof(AutoVacOpts , log_min_duration )},
18661898 {"toast_tuple_target" , RELOPT_TYPE_INT ,
1867- offsetof(StdRdOptions , toast_tuple_target )},
1899+ offsetof(HeapRdOptions , toast_tuple_target )},
18681900 {"autovacuum_vacuum_cost_delay" , RELOPT_TYPE_REAL ,
1869- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , vacuum_cost_delay )},
1901+ offsetof(HeapRdOptions , common ) +
1902+ offsetof(CommonRdOptions , autovacuum ) +
1903+ offsetof(AutoVacOpts , vacuum_cost_delay )},
18701904 {"autovacuum_vacuum_scale_factor" , RELOPT_TYPE_REAL ,
1871- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , vacuum_scale_factor )},
1905+ offsetof(HeapRdOptions , common ) +
1906+ offsetof(CommonRdOptions , autovacuum ) +
1907+ offsetof(AutoVacOpts , vacuum_scale_factor )},
18721908 {"autovacuum_vacuum_insert_scale_factor" , RELOPT_TYPE_REAL ,
1873- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , vacuum_ins_scale_factor )},
1909+ offsetof(HeapRdOptions , common ) +
1910+ offsetof(CommonRdOptions , autovacuum ) +
1911+ offsetof(AutoVacOpts , vacuum_ins_scale_factor )},
18741912 {"autovacuum_analyze_scale_factor" , RELOPT_TYPE_REAL ,
1875- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , analyze_scale_factor )},
1913+ offsetof(HeapRdOptions , common ) +
1914+ offsetof(CommonRdOptions , autovacuum ) +
1915+ offsetof(AutoVacOpts , analyze_scale_factor )},
18761916 {"user_catalog_table" , RELOPT_TYPE_BOOL ,
1877- offsetof(StdRdOptions , user_catalog_table )},
1917+ offsetof(HeapRdOptions , common ) +
1918+ offsetof(CommonRdOptions , user_catalog_table )},
18781919 {"parallel_workers" , RELOPT_TYPE_INT ,
1879- offsetof(StdRdOptions , parallel_workers )},
1920+ offsetof(HeapRdOptions , common ) +
1921+ offsetof(CommonRdOptions , parallel_workers )},
18801922 {"vacuum_index_cleanup" , RELOPT_TYPE_ENUM ,
1881- offsetof(StdRdOptions , vacuum_index_cleanup )},
1923+ offsetof(HeapRdOptions , common ) +
1924+ offsetof(CommonRdOptions , vacuum_index_cleanup )},
18821925 {"vacuum_truncate" , RELOPT_TYPE_BOOL ,
1883- offsetof(StdRdOptions , vacuum_truncate )}
1926+ offsetof(HeapRdOptions , common ) +
1927+ offsetof(CommonRdOptions , vacuum_truncate )}
18841928 };
18851929
18861930 return (bytea * ) build_reloptions (reloptions , validate , kind ,
1887- sizeof (StdRdOptions ),
1931+ sizeof (HeapRdOptions ),
18881932 tab , lengthof (tab ));
18891933}
18901934
@@ -2016,26 +2060,33 @@ view_reloptions(Datum reloptions, bool validate)
20162060 * Parse options for heaps, views and toast tables.
20172061 */
20182062bytea *
2019- heap_reloptions (char relkind , Datum reloptions , bool validate )
2063+ heap_reloptions (char relkind , Datum reloptions ,
2064+ CommonRdOptions * common , bool validate )
20202065{
2021- StdRdOptions * rdopts ;
2066+ HeapRdOptions * rdopts ;
20222067
20232068 switch (relkind )
20242069 {
20252070 case RELKIND_TOASTVALUE :
2026- rdopts = (StdRdOptions * )
2071+ rdopts = (HeapRdOptions * )
20272072 default_reloptions (reloptions , validate , RELOPT_KIND_TOAST );
20282073 if (rdopts != NULL )
20292074 {
20302075 /* adjust default-only parameters for TOAST relations */
20312076 rdopts -> fillfactor = 100 ;
2032- rdopts -> autovacuum .analyze_threshold = -1 ;
2033- rdopts -> autovacuum .analyze_scale_factor = -1 ;
2077+ rdopts -> common . autovacuum .analyze_threshold = -1 ;
2078+ rdopts -> common . autovacuum .analyze_scale_factor = -1 ;
20342079 }
2080+ if (rdopts != NULL && common != NULL )
2081+ * common = rdopts -> common ;
20352082 return (bytea * ) rdopts ;
20362083 case RELKIND_RELATION :
20372084 case RELKIND_MATVIEW :
2038- return default_reloptions (reloptions , validate , RELOPT_KIND_HEAP );
2085+ rdopts = (HeapRdOptions * )
2086+ default_reloptions (reloptions , validate , RELOPT_KIND_HEAP );
2087+ if (rdopts != NULL && common != NULL )
2088+ * common = rdopts -> common ;
2089+ return (bytea * ) rdopts ;
20392090 default :
20402091 /* other relkinds are not supported */
20412092 return NULL ;
0 commit comments