Skip to content

Commit 346d7be

Browse files
committed
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
1 parent 0ffc201 commit 346d7be

File tree

5 files changed

+76
-29
lines changed

5 files changed

+76
-29
lines changed

src/backend/access/common/reloptions.c

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,12 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, Oid amoptions)
834834
{
835835
case RELKIND_RELATION:
836836
case RELKIND_TOASTVALUE:
837-
case RELKIND_VIEW:
838837
case RELKIND_MATVIEW:
839838
options = heap_reloptions(classForm->relkind, datum, false);
840839
break;
840+
case RELKIND_VIEW:
841+
options = view_reloptions(datum, false);
842+
break;
841843
case RELKIND_INDEX:
842844
options = index_reloptions(amoptions, datum, false);
843845
break;
@@ -1200,10 +1202,6 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
12001202
offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, vacuum_scale_factor)},
12011203
{"autovacuum_analyze_scale_factor", RELOPT_TYPE_REAL,
12021204
offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_scale_factor)},
1203-
{"security_barrier", RELOPT_TYPE_BOOL,
1204-
offsetof(StdRdOptions, security_barrier)},
1205-
{"check_option", RELOPT_TYPE_STRING,
1206-
offsetof(StdRdOptions, check_option_offset)},
12071205
{"user_catalog_table", RELOPT_TYPE_BOOL,
12081206
offsetof(StdRdOptions, user_catalog_table)}
12091207
};
@@ -1224,6 +1222,38 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
12241222
return (bytea *) rdopts;
12251223
}
12261224

1225+
/*
1226+
* Option parser for views
1227+
*/
1228+
bytea *
1229+
view_reloptions(Datum reloptions, bool validate)
1230+
{
1231+
relopt_value *options;
1232+
ViewOptions *vopts;
1233+
int numoptions;
1234+
static const relopt_parse_elt tab[] = {
1235+
{"security_barrier", RELOPT_TYPE_BOOL,
1236+
offsetof(ViewOptions, security_barrier)},
1237+
{"check_option", RELOPT_TYPE_STRING,
1238+
offsetof(ViewOptions, check_option_offset)}
1239+
};
1240+
1241+
options = parseRelOptions(reloptions, validate, RELOPT_KIND_VIEW, &numoptions);
1242+
1243+
/* if none set, we're done */
1244+
if (numoptions == 0)
1245+
return NULL;
1246+
1247+
vopts = allocateReloptStruct(sizeof(ViewOptions), options, numoptions);
1248+
1249+
fillRelOptions((void *) vopts, sizeof(ViewOptions), options, numoptions,
1250+
validate, tab, lengthof(tab));
1251+
1252+
pfree(options);
1253+
1254+
return (bytea *) vopts;
1255+
}
1256+
12271257
/*
12281258
* Parse options for heaps, views and toast tables.
12291259
*/
@@ -1248,8 +1278,6 @@ heap_reloptions(char relkind, Datum reloptions, bool validate)
12481278
case RELKIND_RELATION:
12491279
case RELKIND_MATVIEW:
12501280
return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
1251-
case RELKIND_VIEW:
1252-
return default_reloptions(reloptions, validate, RELOPT_KIND_VIEW);
12531281
default:
12541282
/* other relkinds are not supported */
12551283
return NULL;

src/backend/commands/tablecmds.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,10 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
533533
reloptions = transformRelOptions((Datum) 0, stmt->options, NULL, validnsps,
534534
true, false);
535535

536-
(void) heap_reloptions(relkind, reloptions, true);
536+
if (relkind == RELKIND_VIEW)
537+
(void) view_reloptions(reloptions, true);
538+
else
539+
(void) heap_reloptions(relkind, reloptions, true);
537540

538541
if (stmt->ofTypename)
539542
{
@@ -8889,10 +8892,12 @@ ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation,
88898892
{
88908893
case RELKIND_RELATION:
88918894
case RELKIND_TOASTVALUE:
8892-
case RELKIND_VIEW:
88938895
case RELKIND_MATVIEW:
88948896
(void) heap_reloptions(rel->rd_rel->relkind, newOptions, true);
88958897
break;
8898+
case RELKIND_VIEW:
8899+
(void) view_reloptions(newOptions, true);
8900+
break;
88968901
case RELKIND_INDEX:
88978902
(void) index_reloptions(rel->rd_am->amoptions, newOptions, true);
88988903
break;

src/include/access/reloptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ extern void fillRelOptions(void *rdopts, Size basesize,
268268
extern bytea *default_reloptions(Datum reloptions, bool validate,
269269
relopt_kind kind);
270270
extern bytea *heap_reloptions(char relkind, Datum reloptions, bool validate);
271+
extern bytea *view_reloptions(Datum reloptions, bool validate);
271272
extern bytea *index_reloptions(RegProcedure amoptions, Datum reloptions,
272273
bool validate);
273274
extern bytea *attribute_reloptions(Datum reloptions, bool validate);

src/include/utils/rel.h

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ typedef struct StdRdOptions
216216
int32 vl_len_; /* varlena header (do not touch directly!) */
217217
int fillfactor; /* page fill factor in percent (0..100) */
218218
AutoVacOpts autovacuum; /* autovacuum-related options */
219-
bool security_barrier; /* for views */
220-
int check_option_offset; /* for views */
221219
bool user_catalog_table; /* use as an additional catalog
222220
* relation */
223221
} StdRdOptions;
@@ -247,55 +245,69 @@ typedef struct StdRdOptions
247245
#define RelationGetTargetPageFreeSpace(relation, defaultff) \
248246
(BLCKSZ * (100 - RelationGetFillFactor(relation, defaultff)) / 100)
249247

248+
/*
249+
* RelationIsUsedAsCatalogTable
250+
* Returns whether the relation should be treated as a catalog table
251+
* from the pov of logical decoding. Note multiple eval or argument!
252+
*/
253+
#define RelationIsUsedAsCatalogTable(relation) \
254+
((relation)->rd_options ? \
255+
((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)
256+
257+
258+
/*
259+
* ViewOptions
260+
* Contents of rd_options for views
261+
*/
262+
typedef struct ViewOptions
263+
{
264+
int32 vl_len_; /* varlena header (do not touch directly!) */
265+
bool security_barrier;
266+
int check_option_offset;
267+
} ViewOptions;
268+
250269
/*
251270
* RelationIsSecurityView
252-
* Returns whether the relation is security view, or not
271+
* Returns whether the relation is security view, or not. Note multiple
272+
* eval of argument!
253273
*/
254274
#define RelationIsSecurityView(relation) \
255275
((relation)->rd_options ? \
256-
((StdRdOptions *) (relation)->rd_options)->security_barrier : false)
276+
((ViewOptions *) (relation)->rd_options)->security_barrier : false)
257277

258278
/*
259279
* RelationHasCheckOption
260280
* Returns true if the relation is a view defined with either the local
261-
* or the cascaded check option.
281+
* or the cascaded check option. Note multiple eval of argument!
262282
*/
263283
#define RelationHasCheckOption(relation) \
264284
((relation)->rd_options && \
265-
((StdRdOptions *) (relation)->rd_options)->check_option_offset != 0)
285+
((ViewOptions *) (relation)->rd_options)->check_option_offset != 0)
266286

267287
/*
268288
* RelationHasLocalCheckOption
269289
* Returns true if the relation is a view defined with the local check
270-
* option.
290+
* option. Note multiple eval of argument!
271291
*/
272292
#define RelationHasLocalCheckOption(relation) \
273293
((relation)->rd_options && \
274-
((StdRdOptions *) (relation)->rd_options)->check_option_offset != 0 ? \
294+
((ViewOptions *) (relation)->rd_options)->check_option_offset != 0 ? \
275295
strcmp((char *) (relation)->rd_options + \
276-
((StdRdOptions *) (relation)->rd_options)->check_option_offset, \
296+
((ViewOptions *) (relation)->rd_options)->check_option_offset, \
277297
"local") == 0 : false)
278298

279299
/*
280300
* RelationHasCascadedCheckOption
281301
* Returns true if the relation is a view defined with the cascaded check
282-
* option.
302+
* option. Note multiple eval of argument!
283303
*/
284304
#define RelationHasCascadedCheckOption(relation) \
285305
((relation)->rd_options && \
286-
((StdRdOptions *) (relation)->rd_options)->check_option_offset != 0 ? \
306+
((ViewOptions *) (relation)->rd_options)->check_option_offset != 0 ? \
287307
strcmp((char *) (relation)->rd_options + \
288-
((StdRdOptions *) (relation)->rd_options)->check_option_offset, \
308+
((ViewOptions *) (relation)->rd_options)->check_option_offset, \
289309
"cascaded") == 0 : false)
290310

291-
/*
292-
* RelationIsUsedAsCatalogTable
293-
* Returns whether the relation should be treated as a catalog table
294-
* from the pov of logical decoding.
295-
*/
296-
#define RelationIsUsedAsCatalogTable(relation) \
297-
((relation)->rd_options ? \
298-
((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)
299311

300312
/*
301313
* RelationIsValid

src/tools/pgindent/typedefs.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,7 @@ VariableSpace
19551955
VariableStatData
19561956
Vfd
19571957
ViewCheckOption
1958+
ViewOptions
19581959
ViewStmt
19591960
VirtualTransactionId
19601961
Vsrt

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy