24
24
#include "access/nbtree.h"
25
25
#include "access/reloptions.h"
26
26
#include "access/spgist_private.h"
27
+ #include "access/tableam.h"
27
28
#include "catalog/pg_type.h"
28
29
#include "commands/defrem.h"
29
30
#include "commands/tablespace.h"
44
45
* value, upper and lower bounds (if applicable); for strings, consider a
45
46
* validation routine.
46
47
* (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 )
48
49
* (iv) add it to the appropriate handling routine (perhaps
49
50
* default_reloptions)
50
51
* (v) make sure the lock level is set correctly for that operation
@@ -1374,10 +1375,16 @@ untransformRelOptions(Datum options)
1374
1375
* tupdesc is pg_class' tuple descriptor. amoptions is a pointer to the index
1375
1376
* AM's options parser function in the case of a tuple corresponding to an
1376
1377
* 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.
1377
1382
*/
1383
+
1378
1384
bytea *
1379
1385
extractRelOptions (HeapTuple tuple , TupleDesc tupdesc ,
1380
- amoptions_function amoptions )
1386
+ const TableAmRoutine * tableam , amoptions_function amoptions ,
1387
+ CommonRdOptions * common )
1381
1388
{
1382
1389
bytea * options ;
1383
1390
bool isnull ;
@@ -1399,7 +1406,8 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
1399
1406
case RELKIND_RELATION :
1400
1407
case RELKIND_TOASTVALUE :
1401
1408
case RELKIND_MATVIEW :
1402
- options = heap_reloptions (classForm -> relkind , datum , false);
1409
+ options = tableam_reloptions (tableam , classForm -> relkind ,
1410
+ datum , common , false);
1403
1411
break ;
1404
1412
case RELKIND_PARTITIONED_TABLE :
1405
1413
options = partitioned_table_reloptions (datum , false);
@@ -1695,7 +1703,7 @@ parse_one_reloption(relopt_value *option, char *text_str, int text_len,
1695
1703
* Given the result from parseRelOptions, allocate a struct that's of the
1696
1704
* specified base size plus any extra space that's needed for string variables.
1697
1705
*
1698
- * "base" should be sizeof(struct) of the reloptions struct (StdRdOptions or
1706
+ * "base" should be sizeof(struct) of the reloptions struct (HeapRdOptions or
1699
1707
* equivalent).
1700
1708
*/
1701
1709
static void *
@@ -1832,59 +1840,95 @@ fillRelOptions(void *rdopts, Size basesize,
1832
1840
1833
1841
1834
1842
/*
1835
- * Option parser for anything that uses StdRdOptions .
1843
+ * Option parser for anything that uses HeapRdOptions .
1836
1844
*/
1837
- bytea *
1845
+ static bytea *
1838
1846
default_reloptions (Datum reloptions , bool validate , relopt_kind kind )
1839
1847
{
1840
1848
static const relopt_parse_elt tab [] = {
1841
- {"fillfactor" , RELOPT_TYPE_INT , offsetof(StdRdOptions , fillfactor )},
1849
+ {"fillfactor" , RELOPT_TYPE_INT , offsetof(HeapRdOptions , fillfactor )},
1842
1850
{"autovacuum_enabled" , RELOPT_TYPE_BOOL ,
1843
- offsetof(StdRdOptions , autovacuum ) + offsetof(AutoVacOpts , enabled )},
1851
+ offsetof(HeapRdOptions , common ) +
1852
+ offsetof(CommonRdOptions , autovacuum ) +
1853
+ offsetof(AutoVacOpts , enabled )},
1844
1854
{"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 )},
1846
1858
{"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 )},
1848
1862
{"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 )},
1850
1866
{"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 )},
1852
1870
{"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 )},
1854
1874
{"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 )},
1856
1878
{"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 )},
1858
1882
{"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 )},
1860
1886
{"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 )},
1862
1890
{"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 )},
1864
1894
{"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 )},
1866
1898
{"toast_tuple_target" , RELOPT_TYPE_INT ,
1867
- offsetof(StdRdOptions , toast_tuple_target )},
1899
+ offsetof(HeapRdOptions , toast_tuple_target )},
1868
1900
{"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 )},
1870
1904
{"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 )},
1872
1908
{"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 )},
1874
1912
{"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 )},
1876
1916
{"user_catalog_table" , RELOPT_TYPE_BOOL ,
1877
- offsetof(StdRdOptions , user_catalog_table )},
1917
+ offsetof(HeapRdOptions , common ) +
1918
+ offsetof(CommonRdOptions , user_catalog_table )},
1878
1919
{"parallel_workers" , RELOPT_TYPE_INT ,
1879
- offsetof(StdRdOptions , parallel_workers )},
1920
+ offsetof(HeapRdOptions , common ) +
1921
+ offsetof(CommonRdOptions , parallel_workers )},
1880
1922
{"vacuum_index_cleanup" , RELOPT_TYPE_ENUM ,
1881
- offsetof(StdRdOptions , vacuum_index_cleanup )},
1923
+ offsetof(HeapRdOptions , common ) +
1924
+ offsetof(CommonRdOptions , vacuum_index_cleanup )},
1882
1925
{"vacuum_truncate" , RELOPT_TYPE_BOOL ,
1883
- offsetof(StdRdOptions , vacuum_truncate )}
1926
+ offsetof(HeapRdOptions , common ) +
1927
+ offsetof(CommonRdOptions , vacuum_truncate )}
1884
1928
};
1885
1929
1886
1930
return (bytea * ) build_reloptions (reloptions , validate , kind ,
1887
- sizeof (StdRdOptions ),
1931
+ sizeof (HeapRdOptions ),
1888
1932
tab , lengthof (tab ));
1889
1933
}
1890
1934
@@ -2016,26 +2060,33 @@ view_reloptions(Datum reloptions, bool validate)
2016
2060
* Parse options for heaps, views and toast tables.
2017
2061
*/
2018
2062
bytea *
2019
- heap_reloptions (char relkind , Datum reloptions , bool validate )
2063
+ heap_reloptions (char relkind , Datum reloptions ,
2064
+ CommonRdOptions * common , bool validate )
2020
2065
{
2021
- StdRdOptions * rdopts ;
2066
+ HeapRdOptions * rdopts ;
2022
2067
2023
2068
switch (relkind )
2024
2069
{
2025
2070
case RELKIND_TOASTVALUE :
2026
- rdopts = (StdRdOptions * )
2071
+ rdopts = (HeapRdOptions * )
2027
2072
default_reloptions (reloptions , validate , RELOPT_KIND_TOAST );
2028
2073
if (rdopts != NULL )
2029
2074
{
2030
2075
/* adjust default-only parameters for TOAST relations */
2031
2076
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 ;
2034
2079
}
2080
+ if (rdopts != NULL && common != NULL )
2081
+ * common = rdopts -> common ;
2035
2082
return (bytea * ) rdopts ;
2036
2083
case RELKIND_RELATION :
2037
2084
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 ;
2039
2090
default :
2040
2091
/* other relkinds are not supported */
2041
2092
return NULL ;
0 commit comments