mirror of
https://github.com/postgres/postgres.git
synced 2025-10-19 15:49:24 +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:
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "access/amapi.h"
|
||||
#include "access/htup.h"
|
||||
#include "access/tableam.h"
|
||||
#include "access/tupdesc.h"
|
||||
#include "nodes/pg_list.h"
|
||||
#include "storage/lock.h"
|
||||
@@ -224,6 +225,7 @@ extern Datum transformRelOptions(Datum oldOptions, List *defList,
|
||||
bool acceptOidsOff, bool isReset);
|
||||
extern List *untransformRelOptions(Datum options);
|
||||
extern bytea *extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
|
||||
const TableAmRoutine *tableam,
|
||||
amoptions_function amoptions);
|
||||
extern void *build_reloptions(Datum reloptions, bool validate,
|
||||
relopt_kind kind,
|
||||
|
@@ -737,6 +737,28 @@ typedef struct TableAmRoutine
|
||||
int32 slicelength,
|
||||
struct varlena *result);
|
||||
|
||||
/*
|
||||
* This callback parses and validates the reloptions array for a table.
|
||||
*
|
||||
* This is called only when a non-null reloptions array exists for the
|
||||
* table. 'reloptions' is a text array containing entries of the form
|
||||
* "name=value". The function should construct a bytea value, which will
|
||||
* be copied into the rd_options field of the table's relcache entry. The
|
||||
* data contents of the bytea value are open for the access method to
|
||||
* define.
|
||||
*
|
||||
* When 'validate' is true, the function should report a suitable error
|
||||
* message if any of the options are unrecognized or have invalid values;
|
||||
* when 'validate' is false, invalid entries should be silently ignored.
|
||||
* ('validate' is false when loading options already stored in pg_catalog;
|
||||
* an invalid entry could only be found if the access method has changed
|
||||
* its rules for options, and in that case ignoring obsolete entries is
|
||||
* appropriate.)
|
||||
*
|
||||
* It is OK to return NULL if default behavior is wanted.
|
||||
*/
|
||||
bytea *(*reloptions) (char relkind, Datum reloptions, bool validate);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Planner related functions.
|
||||
@@ -1925,6 +1947,26 @@ table_relation_fetch_toast_slice(Relation toastrel, Oid valueid,
|
||||
result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse options for given table.
|
||||
*/
|
||||
static inline bytea *
|
||||
table_reloptions(Relation rel, char relkind,
|
||||
Datum reloptions, bool validate)
|
||||
{
|
||||
return rel->rd_tableam->reloptions(relkind, reloptions, validate);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse table options without knowledge of particular table.
|
||||
*/
|
||||
static inline bytea *
|
||||
tableam_reloptions(const TableAmRoutine *tableam, char relkind,
|
||||
Datum reloptions, bool validate)
|
||||
{
|
||||
return tableam->reloptions(relkind, reloptions, validate);
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Planner related functionality
|
||||
@@ -2102,6 +2144,7 @@ extern void table_block_relation_estimate_size(Relation rel,
|
||||
*/
|
||||
|
||||
extern const TableAmRoutine *GetTableAmRoutine(Oid amhandler);
|
||||
extern const TableAmRoutine *GetTableAmRoutineByAmOid(Oid amoid);
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Functions in heapam_handler.c
|
||||
|
Reference in New Issue
Block a user