mirror of
https://github.com/postgres/postgres.git
synced 2025-12-19 17:02:53 +03:00
Custom reloptions for table AM
Let table AM define custom reloptions for its tables. This allows to specify AM-specific parameters by WITH clause when creating a table. The code may use some parts from prior work by Hao Wu. Discussion: https://postgr.es/m/CAPpHfdurb9ycV8udYqM%3Do0sPS66PJ4RCBM1g-bBpvzUfogY0EA%40mail.gmail.com Discussion: https://postgr.es/m/AMUA1wBBBxfc3tKRLLdU64rb.1.1683276279979.Hmail.wuhao%40hashdata.cn Reviewed-by: Reviewed-by: Pavel Borisov, Matthias van de Meent
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#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"
|
||||
@@ -1377,7 +1378,7 @@ untransformRelOptions(Datum options)
|
||||
*/
|
||||
bytea *
|
||||
extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
|
||||
amoptions_function amoptions)
|
||||
const TableAmRoutine *tableam, amoptions_function amoptions)
|
||||
{
|
||||
bytea *options;
|
||||
bool isnull;
|
||||
@@ -1399,7 +1400,8 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
|
||||
case RELKIND_RELATION:
|
||||
case RELKIND_TOASTVALUE:
|
||||
case RELKIND_MATVIEW:
|
||||
options = heap_reloptions(classForm->relkind, datum, false);
|
||||
options = tableam_reloptions(tableam, classForm->relkind,
|
||||
datum, false);
|
||||
break;
|
||||
case RELKIND_PARTITIONED_TABLE:
|
||||
options = partitioned_table_reloptions(datum, false);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#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"
|
||||
@@ -2155,6 +2156,16 @@ heapam_relation_toast_am(Relation rel)
|
||||
return rel->rd_rel->relam;
|
||||
}
|
||||
|
||||
static bytea *
|
||||
heapam_reloptions(char relkind, Datum reloptions, bool validate)
|
||||
{
|
||||
Assert(relkind == RELKIND_RELATION ||
|
||||
relkind == RELKIND_TOASTVALUE ||
|
||||
relkind == RELKIND_MATVIEW);
|
||||
|
||||
return heap_reloptions(relkind, reloptions, validate);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Planner related callbacks for the heap AM
|
||||
@@ -2660,6 +2671,7 @@ 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,
|
||||
|
||||
|
||||
@@ -13,9 +13,11 @@
|
||||
|
||||
#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"
|
||||
|
||||
|
||||
/*
|
||||
@@ -98,6 +100,29 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user