Commit 346d7be1 authored by Alvaro Herrera's avatar Alvaro Herrera

Move view reloptions into their own varlena struct

Per discussion after a gripe from me in
http://www.postgresql.org/message-id/20140611194633.GH18688@eldon.alvh.no-ip.org

Jaime Casanova
parent 0ffc201a
...@@ -834,10 +834,12 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, Oid amoptions) ...@@ -834,10 +834,12 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, Oid amoptions)
{ {
case RELKIND_RELATION: case RELKIND_RELATION:
case RELKIND_TOASTVALUE: case RELKIND_TOASTVALUE:
case RELKIND_VIEW:
case RELKIND_MATVIEW: case RELKIND_MATVIEW:
options = heap_reloptions(classForm->relkind, datum, false); options = heap_reloptions(classForm->relkind, datum, false);
break; break;
case RELKIND_VIEW:
options = view_reloptions(datum, false);
break;
case RELKIND_INDEX: case RELKIND_INDEX:
options = index_reloptions(amoptions, datum, false); options = index_reloptions(amoptions, datum, false);
break; break;
...@@ -1200,10 +1202,6 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind) ...@@ -1200,10 +1202,6 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_scale_factor)}, offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_scale_factor)},
{"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL, {"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_scale_factor)}, offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_scale_factor)},
{"security_barrier", RELOPT_TYPE_BOOL,
offsetof(StdRdOptions, security_barrier)},
{"check_option", RELOPT_TYPE_STRING,
offsetof(StdRdOptions, check_option_offset)},
{"user_catalog_table", RELOPT_TYPE_BOOL, {"user_catalog_table", RELOPT_TYPE_BOOL,
offsetof(StdRdOptions, user_catalog_table)} offsetof(StdRdOptions, user_catalog_table)}
}; };
...@@ -1224,6 +1222,38 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind) ...@@ -1224,6 +1222,38 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
return (bytea *) rdopts; return (bytea *) rdopts;
} }
/*
* Option parser for views
*/
bytea *
view_reloptions(Datum reloptions, bool validate)
{
relopt_value *options;
ViewOptions *vopts;
int numoptions;
static const relopt_parse_elt tab[] = {
{"security_barrier", RELOPT_TYPE_BOOL,
offsetof(ViewOptions, security_barrier)},
{"check_option", RELOPT_TYPE_STRING,
offsetof(ViewOptions, check_option_offset)}
};
options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
/* if none set, we're done */
if (numoptions == 0)
return NULL;
vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
validate, tab, lengthof(tab));
pfree(options);
return (bytea *) vopts;
}
/* /*
* Parse options for heaps, views and toast tables. * Parse options for heaps, views and toast tables.
*/ */
...@@ -1248,8 +1278,6 @@ heap_reloptions(char relkind, Datum reloptions, bool validate) ...@@ -1248,8 +1278,6 @@ heap_reloptions(char relkind, Datum reloptions, bool validate)
case RELKIND_RELATION: case RELKIND_RELATION:
case RELKIND_MATVIEW: case RELKIND_MATVIEW:
return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP); return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
case RELKIND_VIEW:
return default_reloptions(reloptions, validate, RELOPT_KIND_VIEW);
default: default:
/* other relkinds are not supported */ /* other relkinds are not supported */
return NULL; return NULL;
......
...@@ -533,7 +533,10 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId) ...@@ -533,7 +533,10 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
reloptions = transformRelOptions((Datum) 0, stmt->options, NULL, validnsps, reloptions = transformRelOptions((Datum) 0, stmt->options, NULL, validnsps,
true, false); true, false);
(void) heap_reloptions(relkind, reloptions, true); if (relkind == RELKIND_VIEW)
(void) view_reloptions(reloptions, true);
else
(void) heap_reloptions(relkind, reloptions, true);
if (stmt->ofTypename) if (stmt->ofTypename)
{ {
...@@ -8889,10 +8892,12 @@ ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation, ...@@ -8889,10 +8892,12 @@ ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation,
{ {
case RELKIND_RELATION: case RELKIND_RELATION:
case RELKIND_TOASTVALUE: case RELKIND_TOASTVALUE:
case RELKIND_VIEW:
case RELKIND_MATVIEW: case RELKIND_MATVIEW:
(void) heap_reloptions(rel->rd_rel->relkind, newOptions, true); (void) heap_reloptions(rel->rd_rel->relkind, newOptions, true);
break; break;
case RELKIND_VIEW:
(void) view_reloptions(newOptions, true);
break;
case RELKIND_INDEX: case RELKIND_INDEX:
(void) index_reloptions(rel->rd_am->amoptions, newOptions, true); (void) index_reloptions(rel->rd_am->amoptions, newOptions, true);
break; break;
......
...@@ -268,6 +268,7 @@ extern void fillRelOptions(void *rdopts, Size basesize, ...@@ -268,6 +268,7 @@ extern void fillRelOptions(void *rdopts, Size basesize,
extern bytea *default_reloptions(Datum reloptions, bool validate, extern bytea *default_reloptions(Datum reloptions, bool validate,
relopt_kind kind); relopt_kind kind);
extern bytea *heap_reloptions(char relkind, Datum reloptions, bool validate); extern bytea *heap_reloptions(char relkind, Datum reloptions, bool validate);
extern bytea *view_reloptions(Datum reloptions, bool validate);
extern bytea *index_reloptions(RegProcedure amoptions, Datum reloptions, extern bytea *index_reloptions(RegProcedure amoptions, Datum reloptions,
bool validate); bool validate);
extern bytea *attribute_reloptions(Datum reloptions, bool validate); extern bytea *attribute_reloptions(Datum reloptions, bool validate);
......
...@@ -216,8 +216,6 @@ typedef struct StdRdOptions ...@@ -216,8 +216,6 @@ typedef struct StdRdOptions
int32 vl_len_; /* varlena header (do not touch directly!) */ int32 vl_len_; /* varlena header (do not touch directly!) */
int fillfactor; /* page fill factor in percent (0..100) */ int fillfactor; /* page fill factor in percent (0..100) */
AutoVacOpts autovacuum; /* autovacuum-related options */ AutoVacOpts autovacuum; /* autovacuum-related options */
bool security_barrier; /* for views */
int check_option_offset; /* for views */
bool user_catalog_table; /* use as an additional catalog bool user_catalog_table; /* use as an additional catalog
* relation */ * relation */
} StdRdOptions; } StdRdOptions;
...@@ -247,55 +245,69 @@ typedef struct StdRdOptions ...@@ -247,55 +245,69 @@ typedef struct StdRdOptions
#define RelationGetTargetPageFreeSpace(relation, defaultff) \ #define RelationGetTargetPageFreeSpace(relation, defaultff) \
(BLCKSZ * (100 - RelationGetFillFactor(relation, defaultff)) / 100) (BLCKSZ * (100 - RelationGetFillFactor(relation, defaultff)) / 100)
/*
* RelationIsUsedAsCatalogTable
* Returns whether the relation should be treated as a catalog table
* from the pov of logical decoding. Note multiple eval or argument!
*/
#define RelationIsUsedAsCatalogTable(relation) \
((relation)->rd_options ? \
((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)
/*
* ViewOptions
* Contents of rd_options for views
*/
typedef struct ViewOptions
{
int32 vl_len_; /* varlena header (do not touch directly!) */
bool security_barrier;
int check_option_offset;
} ViewOptions;
/* /*
* RelationIsSecurityView * RelationIsSecurityView
* Returns whether the relation is security view, or not * Returns whether the relation is security view, or not. Note multiple
* eval of argument!
*/ */
#define RelationIsSecurityView(relation) \ #define RelationIsSecurityView(relation) \
((relation)->rd_options ? \ ((relation)->rd_options ? \
((StdRdOptions *) (relation)->rd_options)->security_barrier : false) ((ViewOptions *) (relation)->rd_options)->security_barrier : false)
/* /*
* RelationHasCheckOption * RelationHasCheckOption
* Returns true if the relation is a view defined with either the local * Returns true if the relation is a view defined with either the local
* or the cascaded check option. * or the cascaded check option. Note multiple eval of argument!
*/ */
#define RelationHasCheckOption(relation) \ #define RelationHasCheckOption(relation) \
((relation)->rd_options && \ ((relation)->rd_options && \
((StdRdOptions *) (relation)->rd_options)->check_option_offset != 0) ((ViewOptions *) (relation)->rd_options)->check_option_offset != 0)
/* /*
* RelationHasLocalCheckOption * RelationHasLocalCheckOption
* Returns true if the relation is a view defined with the local check * Returns true if the relation is a view defined with the local check
* option. * option. Note multiple eval of argument!
*/ */
#define RelationHasLocalCheckOption(relation) \ #define RelationHasLocalCheckOption(relation) \
((relation)->rd_options && \ ((relation)->rd_options && \
((StdRdOptions *) (relation)->rd_options)->check_option_offset != 0 ? \ ((ViewOptions *) (relation)->rd_options)->check_option_offset != 0 ? \
strcmp((char *) (relation)->rd_options + \ strcmp((char *) (relation)->rd_options + \
((StdRdOptions *) (relation)->rd_options)->check_option_offset, \ ((ViewOptions *) (relation)->rd_options)->check_option_offset, \
"local") == 0 : false) "local") == 0 : false)
/* /*
* RelationHasCascadedCheckOption * RelationHasCascadedCheckOption
* Returns true if the relation is a view defined with the cascaded check * Returns true if the relation is a view defined with the cascaded check
* option. * option. Note multiple eval of argument!
*/ */
#define RelationHasCascadedCheckOption(relation) \ #define RelationHasCascadedCheckOption(relation) \
((relation)->rd_options && \ ((relation)->rd_options && \
((StdRdOptions *) (relation)->rd_options)->check_option_offset != 0 ? \ ((ViewOptions *) (relation)->rd_options)->check_option_offset != 0 ? \
strcmp((char *) (relation)->rd_options + \ strcmp((char *) (relation)->rd_options + \
((StdRdOptions *) (relation)->rd_options)->check_option_offset, \ ((ViewOptions *) (relation)->rd_options)->check_option_offset, \
"cascaded") == 0 : false) "cascaded") == 0 : false)
/*
* RelationIsUsedAsCatalogTable
* Returns whether the relation should be treated as a catalog table
* from the pov of logical decoding.
*/
#define RelationIsUsedAsCatalogTable(relation) \
((relation)->rd_options ? \
((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)
/* /*
* RelationIsValid * RelationIsValid
......
...@@ -1955,6 +1955,7 @@ VariableSpace ...@@ -1955,6 +1955,7 @@ VariableSpace
VariableStatData VariableStatData
Vfd Vfd
ViewCheckOption ViewCheckOption
ViewOptions
ViewStmt ViewStmt
VirtualTransactionId VirtualTransactionId
Vsrt Vsrt
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment