summaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
authorAlexander Korotkov2024-04-11 12:46:35 +0000
committerAlexander Korotkov2024-04-11 12:46:35 +0000
commitbc1e2092ebb857802a9713d0d3588079e2f0216a (patch)
treef55adc80b07150bcd7f5cbd50a9bfc89b3f301d6 /src/backend/access
parent87840b9741864dfdb9f63b0056e2783cdb49b8a5 (diff)
Revert: Custom reloptions for table AM
This commit reverts 9bd99f4c26 and 422041542f per review by Andres Freund. Discussion: https://postgr.es/m/20240410165236.rwyrny7ihi4ddxw4%40awork3.anarazel.de
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/common/reloptions.c149
-rw-r--r--src/backend/access/heap/heapam.c4
-rw-r--r--src/backend/access/heap/heapam_handler.c13
-rw-r--r--src/backend/access/heap/heaptoast.c9
-rw-r--r--src/backend/access/heap/hio.c4
-rw-r--r--src/backend/access/heap/pruneheap.c4
-rw-r--r--src/backend/access/heap/rewriteheap.c4
-rw-r--r--src/backend/access/table/tableam.c2
-rw-r--r--src/backend/access/table/tableamapi.c25
9 files changed, 45 insertions, 169 deletions
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
index 24245f71728..d6eb5d85599 100644
--- a/src/backend/access/common/reloptions.c
+++ b/src/backend/access/common/reloptions.c
@@ -24,7 +24,6 @@
#include "access/nbtree.h"
#include "access/reloptions.h"
#include "access/spgist_private.h"
-#include "access/tableam.h"
#include "catalog/pg_type.h"
#include "commands/defrem.h"
#include "commands/tablespace.h"
@@ -45,7 +44,7 @@
* value, upper and lower bounds (if applicable); for strings, consider a
* validation routine.
* (ii) add a record below (or use add_<type>_reloption).
- * (iii) add it to the appropriate options struct (perhaps HeapRdOptions)
+ * (iii) add it to the appropriate options struct (perhaps StdRdOptions)
* (iv) add it to the appropriate handling routine (perhaps
* default_reloptions)
* (v) make sure the lock level is set correctly for that operation
@@ -1375,16 +1374,10 @@ untransformRelOptions(Datum options)
* tupdesc is pg_class' tuple descriptor. amoptions is a pointer to the index
* AM's options parser function in the case of a tuple corresponding to an
* index, or NULL otherwise.
- *
- * If common pointer is provided, then the corresponding struct will be
- * filled with options that table AM exposes for external usage. That must
- * be filled with defaults before passing here.
*/
-
bytea *
extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
- const TableAmRoutine *tableam, amoptions_function amoptions,
- CommonRdOptions *common)
+ amoptions_function amoptions)
{
bytea *options;
bool isnull;
@@ -1406,8 +1399,7 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
case RELKIND_RELATION:
case RELKIND_TOASTVALUE:
case RELKIND_MATVIEW:
- options = tableam_reloptions(tableam, classForm->relkind,
- datum, common, false);
+ options = heap_reloptions(classForm->relkind, datum, false);
break;
case RELKIND_PARTITIONED_TABLE:
options = partitioned_table_reloptions(datum, false);
@@ -1703,7 +1695,7 @@ parse_one_reloption(relopt_value *option, char *text_str, int text_len,
* Given the result from parseRelOptions, allocate a struct that's of the
* specified base size plus any extra space that's needed for string variables.
*
- * "base" should be sizeof(struct) of the reloptions struct (HeapRdOptions or
+ * "base" should be sizeof(struct) of the reloptions struct (StdRdOptions or
* equivalent).
*/
static void *
@@ -1840,95 +1832,59 @@ fillRelOptions(void *rdopts, Size basesize,
/*
- * Option parser for anything that uses HeapRdOptions.
+ * Option parser for anything that uses StdRdOptions.
*/
-static bytea *
+bytea *
default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
{
static const relopt_parse_elt tab[] = {
- {"fillfactor", RELOPT_TYPE_INT, offsetof(HeapRdOptions, fillfactor)},
+ {"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
{"autovacuum_enabled", RELOPT_TYPE_BOOL,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, enabled)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},
{"autovacuum_vacuum_threshold", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, vacuum_threshold)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_threshold)},
{"autovacuum_vacuum_insert_threshold", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, vacuum_ins_threshold)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_threshold)},
{"autovacuum_analyze_threshold", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, analyze_threshold)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_threshold)},
{"autovacuum_vacuum_cost_limit", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, vacuum_cost_limit)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_limit)},
{"autovacuum_freeze_min_age", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, freeze_min_age)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_min_age)},
{"autovacuum_freeze_max_age", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, freeze_max_age)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_max_age)},
{"autovacuum_freeze_table_age", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, freeze_table_age)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, freeze_table_age)},
{"autovacuum_multixact_freeze_min_age", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, multixact_freeze_min_age)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_min_age)},
{"autovacuum_multixact_freeze_max_age", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, multixact_freeze_max_age)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_max_age)},
{"autovacuum_multixact_freeze_table_age", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, multixact_freeze_table_age)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, multixact_freeze_table_age)},
{"log_autovacuum_min_duration", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, log_min_duration)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_min_duration)},
{"toast_tuple_target", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, toast_tuple_target)},
+ offsetof(StdRdOptions, toast_tuple_target)},
{"autovacuum_vacuum_cost_delay", RELOPT_TYPE_REAL,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, vacuum_cost_delay)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)},
{"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, vacuum_scale_factor)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_scale_factor)},
{"autovacuum_vacuum_insert_scale_factor", RELOPT_TYPE_REAL,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, vacuum_ins_scale_factor)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_ins_scale_factor)},
{"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, autovacuum) +
- offsetof(AutoVacOpts, analyze_scale_factor)},
+ offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, analyze_scale_factor)},
{"user_catalog_table", RELOPT_TYPE_BOOL,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, user_catalog_table)},
+ offsetof(StdRdOptions, user_catalog_table)},
{"parallel_workers", RELOPT_TYPE_INT,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, parallel_workers)},
+ offsetof(StdRdOptions, parallel_workers)},
{"vacuum_index_cleanup", RELOPT_TYPE_ENUM,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, vacuum_index_cleanup)},
+ offsetof(StdRdOptions, vacuum_index_cleanup)},
{"vacuum_truncate", RELOPT_TYPE_BOOL,
- offsetof(HeapRdOptions, common) +
- offsetof(CommonRdOptions, vacuum_truncate)}
+ offsetof(StdRdOptions, vacuum_truncate)}
};
return (bytea *) build_reloptions(reloptions, validate, kind,
- sizeof(HeapRdOptions),
+ sizeof(StdRdOptions),
tab, lengthof(tab));
}
@@ -2057,64 +2013,29 @@ view_reloptions(Datum reloptions, bool validate)
}
/*
- * Fill CommonRdOptions with the default values.
- */
-void
-fill_default_common_reloptions(CommonRdOptions *common)
-{
- common->autovacuum.enabled = true;
- common->autovacuum.vacuum_threshold = -1;
- common->autovacuum.vacuum_ins_threshold = -2;
- common->autovacuum.analyze_threshold = -1;
- common->autovacuum.vacuum_cost_limit = -1;
- common->autovacuum.freeze_min_age = -1;
- common->autovacuum.freeze_max_age = -1;
- common->autovacuum.freeze_table_age = -1;
- common->autovacuum.multixact_freeze_min_age = -1;
- common->autovacuum.multixact_freeze_max_age = -1;
- common->autovacuum.multixact_freeze_table_age = -1;
- common->autovacuum.log_min_duration = -1;
- common->autovacuum.vacuum_cost_delay = -1;
- common->autovacuum.vacuum_scale_factor = -1;
- common->autovacuum.vacuum_ins_scale_factor = -1;
- common->autovacuum.analyze_scale_factor = -1;
- common->parallel_workers = -1;
- common->user_catalog_table = false;
- common->vacuum_index_cleanup = STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO;
- common->vacuum_truncate = true;
-}
-
-/*
* Parse options for heaps, views and toast tables.
*/
bytea *
-heap_reloptions(char relkind, Datum reloptions,
- CommonRdOptions *common, bool validate)
+heap_reloptions(char relkind, Datum reloptions, bool validate)
{
- HeapRdOptions *rdopts;
+ StdRdOptions *rdopts;
switch (relkind)
{
case RELKIND_TOASTVALUE:
- rdopts = (HeapRdOptions *)
+ rdopts = (StdRdOptions *)
default_reloptions(reloptions, validate, RELOPT_KIND_TOAST);
if (rdopts != NULL)
{
/* adjust default-only parameters for TOAST relations */
rdopts->fillfactor = 100;
- rdopts->common.autovacuum.analyze_threshold = -1;
- rdopts->common.autovacuum.analyze_scale_factor = -1;
+ rdopts->autovacuum.analyze_threshold = -1;
+ rdopts->autovacuum.analyze_scale_factor = -1;
}
- if (rdopts != NULL && common != NULL)
- *common = rdopts->common;
return (bytea *) rdopts;
case RELKIND_RELATION:
case RELKIND_MATVIEW:
- rdopts = (HeapRdOptions *)
- default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
- if (rdopts != NULL && common != NULL)
- *common = rdopts->common;
- return (bytea *) rdopts;
+ return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
default:
/* other relkinds are not supported */
return NULL;
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 4607505106d..08f6a10ac3d 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2279,8 +2279,8 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,
Assert(!(options & HEAP_INSERT_NO_LOGICAL));
needwal = RelationNeedsWAL(relation);
- saveFreeSpace = HeapGetTargetPageFreeSpace(relation,
- HEAP_DEFAULT_FILLFACTOR);
+ saveFreeSpace = RelationGetTargetPageFreeSpace(relation,
+ HEAP_DEFAULT_FILLFACTOR);
/* Toast and set header data in all the slots */
heaptuples = palloc(ntuples * sizeof(HeapTuple));
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 30095d88b09..2c423286d72 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -23,7 +23,6 @@
#include "access/heapam.h"
#include "access/heaptoast.h"
#include "access/multixact.h"
-#include "access/reloptions.h"
#include "access/rewriteheap.h"
#include "access/syncscan.h"
#include "access/tableam.h"
@@ -2162,17 +2161,6 @@ heapam_relation_toast_am(Relation rel)
return rel->rd_rel->relam;
}
-static bytea *
-heapam_reloptions(char relkind, Datum reloptions,
- CommonRdOptions *common, bool validate)
-{
- Assert(relkind == RELKIND_RELATION ||
- relkind == RELKIND_TOASTVALUE ||
- relkind == RELKIND_MATVIEW);
-
- return heap_reloptions(relkind, reloptions, common, validate);
-}
-
/* ------------------------------------------------------------------------
* Planner related callbacks for the heap AM
@@ -2734,7 +2722,6 @@ static const TableAmRoutine heapam_methods = {
.relation_needs_toast_table = heapam_relation_needs_toast_table,
.relation_toast_am = heapam_relation_toast_am,
.relation_fetch_toast_slice = heap_fetch_toast_slice,
- .reloptions = heapam_reloptions,
.relation_estimate_size = heapam_estimate_rel_size,
diff --git a/src/backend/access/heap/heaptoast.c b/src/backend/access/heap/heaptoast.c
index cffee7e1b7a..a420e165304 100644
--- a/src/backend/access/heap/heaptoast.c
+++ b/src/backend/access/heap/heaptoast.c
@@ -32,13 +32,6 @@
#include "access/toast_internals.h"
#include "utils/fmgroids.h"
-/*
- * HeapGetToastTupleTarget
- * Returns the heap relation's toast_tuple_target. Note multiple eval of argument!
- */
-#define HeapGetToastTupleTarget(relation, defaulttarg) \
- ((HeapRdOptions *) (relation)->rd_options ? \
- ((HeapRdOptions *) (relation)->rd_options)->toast_tuple_target : (defaulttarg))
/* ----------
* heap_toast_delete -
@@ -181,7 +174,7 @@ heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
hoff += BITMAPLEN(numAttrs);
hoff = MAXALIGN(hoff);
/* now convert to a limit on the tuple data size */
- maxDataLen = HeapGetToastTupleTarget(rel, TOAST_TUPLE_TARGET) - hoff;
+ maxDataLen = RelationGetToastTupleTarget(rel, TOAST_TUPLE_TARGET) - hoff;
/*
* Look for attributes with attstorage EXTENDED to compress. Also find
diff --git a/src/backend/access/heap/hio.c b/src/backend/access/heap/hio.c
index ed731179b45..7c662cdf46e 100644
--- a/src/backend/access/heap/hio.c
+++ b/src/backend/access/heap/hio.c
@@ -536,8 +536,8 @@ RelationGetBufferForTuple(Relation relation, Size len,
len, MaxHeapTupleSize)));
/* Compute desired extra freespace due to fillfactor option */
- saveFreeSpace = HeapGetTargetPageFreeSpace(relation,
- HEAP_DEFAULT_FILLFACTOR);
+ saveFreeSpace = RelationGetTargetPageFreeSpace(relation,
+ HEAP_DEFAULT_FILLFACTOR);
/*
* Since pages without tuples can still have line pointers, we consider
diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c
index 20142dd2144..d2eecaf7ebc 100644
--- a/src/backend/access/heap/pruneheap.c
+++ b/src/backend/access/heap/pruneheap.c
@@ -235,8 +235,8 @@ heap_page_prune_opt(Relation relation, Buffer buffer)
* important than sometimes getting a wrong answer in what is after all
* just a heuristic estimate.
*/
- minfree = HeapGetTargetPageFreeSpace(relation,
- HEAP_DEFAULT_FILLFACTOR);
+ minfree = RelationGetTargetPageFreeSpace(relation,
+ HEAP_DEFAULT_FILLFACTOR);
minfree = Max(minfree, BLCKSZ / 10);
if (PageIsFull(page) || PageGetHeapFreeSpace(page) < minfree)
diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c
index 2bbf121146e..473f3aa9bef 100644
--- a/src/backend/access/heap/rewriteheap.c
+++ b/src/backend/access/heap/rewriteheap.c
@@ -641,8 +641,8 @@ raw_heap_insert(RewriteState state, HeapTuple tup)
len, MaxHeapTupleSize)));
/* Compute desired extra freespace due to fillfactor option */
- saveFreeSpace = HeapGetTargetPageFreeSpace(state->rs_new_rel,
- HEAP_DEFAULT_FILLFACTOR);
+ saveFreeSpace = RelationGetTargetPageFreeSpace(state->rs_new_rel,
+ HEAP_DEFAULT_FILLFACTOR);
/* Now we can check to see if there's enough free space already. */
page = (Page) state->rs_buffer;
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index 5d5f0e68fd7..805d222cebc 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -750,7 +750,7 @@ table_block_relation_estimate_size(Relation rel, int32 *attr_widths,
* The other branch considers it implicitly by calculating density
* from actual relpages/reltuples statistics.
*/
- fillfactor = HeapGetFillFactor(rel, HEAP_DEFAULT_FILLFACTOR);
+ fillfactor = RelationGetFillFactor(rel, HEAP_DEFAULT_FILLFACTOR);
tuple_width = get_rel_data_width(rel, attr_widths);
tuple_width += overhead_bytes_per_tuple;
diff --git a/src/backend/access/table/tableamapi.c b/src/backend/access/table/tableamapi.c
index d9e23ef3175..55b8caeadf2 100644
--- a/src/backend/access/table/tableamapi.c
+++ b/src/backend/access/table/tableamapi.c
@@ -13,11 +13,9 @@
#include "access/tableam.h"
#include "access/xact.h"
-#include "catalog/pg_am.h"
#include "commands/defrem.h"
#include "miscadmin.h"
#include "utils/guc_hooks.h"
-#include "utils/syscache.h"
/*
@@ -100,29 +98,6 @@ GetTableAmRoutine(Oid amhandler)
return routine;
}
-/*
- * GetTableAmRoutineByAmOid
- * Given the table access method oid get its TableAmRoutine struct, which
- * will be palloc'd in the caller's memory context.
- */
-const TableAmRoutine *
-GetTableAmRoutineByAmOid(Oid amoid)
-{
- HeapTuple ht_am;
- Form_pg_am amrec;
- const TableAmRoutine *tableam = NULL;
-
- ht_am = SearchSysCache1(AMOID, ObjectIdGetDatum(amoid));
- if (!HeapTupleIsValid(ht_am))
- elog(ERROR, "cache lookup failed for access method %u",
- amoid);
- amrec = (Form_pg_am) GETSTRUCT(ht_am);
-
- tableam = GetTableAmRoutine(amrec->amhandler);
- ReleaseSysCache(ht_am);
- return tableam;
-}
-
/* check_hook: validate new default_table_access_method */
bool
check_default_table_access_method(char **newval, void **extra, GucSource source)