1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-22 12:22:45 +03:00

Custom reloptions for table AM

Let table AM define custom reloptions for its tables. This allows specifying
AM-specific parameters by the WITH clause when creating a table.

The reloptions, which could be used outside of table AM, are now extracted
into the CommonRdOptions data structure.  These options could be by decision
of table AM directly specified by a user or calculated in some way.

The new test module test_tam_options evaluates the ability to set up custom
reloptions and calculate fields of CommonRdOptions on their base.

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, Jess Davis
This commit is contained in:
Alexander Korotkov
2024-04-08 11:23:28 +03:00
parent 6f3d8d5e7c
commit 9bd99f4c26
29 changed files with 639 additions and 161 deletions

View File

@@ -65,6 +65,7 @@
#include "utils/acl.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "access/relation.h"
/* Hook for plugins to get control in ProcessUtility() */
ProcessUtility_hook_type ProcessUtility_hook = NULL;
@@ -1156,6 +1157,9 @@ ProcessUtilitySlow(ParseState *pstate,
CreateStmt *cstmt = (CreateStmt *) stmt;
Datum toast_options;
static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
const TableAmRoutine *tableam = NULL;
Oid accessMethodId;
Relation rel;
/* Remember transformed RangeVar for LIKE */
table_rv = cstmt->relation;
@@ -1185,9 +1189,27 @@ ProcessUtilitySlow(ParseState *pstate,
validnsps,
true,
false);
(void) heap_reloptions(RELKIND_TOASTVALUE,
toast_options,
true);
/*
* Get toast table AM to validate its options.
* Only relevant if table itself has a table AM.
* We don't need to place the lock given that
* DefineRelation() already placed the
* AccessExclusiveLock.
*/
rel = relation_open(address.objectId, NoLock);
accessMethodId = rel->rd_tableam ?
table_relation_toast_am(rel) : InvalidOid;
relation_close(rel, NoLock);
if (OidIsValid(accessMethodId))
{
tableam = GetTableAmRoutineByAmOid(accessMethodId);
(void) tableam_reloptions(tableam, RELKIND_TOASTVALUE,
toast_options,
NULL,
true);
}
NewRelationCreateToastTable(address.objectId,
toast_options);