Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit346d7be

Browse files
committed
Move view reloptions into their own varlena struct
Per discussion after a gripe from me inhttp://www.postgresql.org/message-id/20140611194633.GH18688@eldon.alvh.no-ip.orgJaime Casanova
1 parent0ffc201 commit346d7be

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
caseRELKIND_RELATION:
836836
caseRELKIND_TOASTVALUE:
837-
caseRELKIND_VIEW:
838837
caseRELKIND_MATVIEW:
839838
options=heap_reloptions(classForm->relkind,datum, false);
840839
break;
840+
caseRELKIND_VIEW:
841+
options=view_reloptions(datum, false);
842+
break;
841843
caseRELKIND_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(Datumreloptions,boolvalidate)
1230+
{
1231+
relopt_value*options;
1232+
ViewOptions*vopts;
1233+
intnumoptions;
1234+
staticconstrelopt_parse_elttab[]= {
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+
returnNULL;
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
caseRELKIND_RELATION:
12491279
caseRELKIND_MATVIEW:
12501280
returndefault_reloptions(reloptions,validate,RELOPT_KIND_HEAP);
1251-
caseRELKIND_VIEW:
1252-
returndefault_reloptions(reloptions,validate,RELOPT_KIND_VIEW);
12531281
default:
12541282
/* other relkinds are not supported */
12551283
returnNULL;

‎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
caseRELKIND_RELATION:
88918894
caseRELKIND_TOASTVALUE:
8892-
caseRELKIND_VIEW:
88938895
caseRELKIND_MATVIEW:
88948896
(void)heap_reloptions(rel->rd_rel->relkind,newOptions, true);
88958897
break;
8898+
caseRELKIND_VIEW:
8899+
(void)view_reloptions(newOptions, true);
8900+
break;
88968901
caseRELKIND_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
externbytea*default_reloptions(Datumreloptions,boolvalidate,
269269
relopt_kindkind);
270270
externbytea*heap_reloptions(charrelkind,Datumreloptions,boolvalidate);
271+
externbytea*view_reloptions(Datumreloptions,boolvalidate);
271272
externbytea*index_reloptions(RegProcedureamoptions,Datumreloptions,
272273
boolvalidate);
273274
externbytea*attribute_reloptions(Datumreloptions,boolvalidate);

‎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
int32vl_len_;/* varlena header (do not touch directly!) */
217217
intfillfactor;/* page fill factor in percent (0..100) */
218218
AutoVacOptsautovacuum;/* autovacuum-related options */
219-
boolsecurity_barrier;/* for views */
220-
intcheck_option_offset;/* for views */
221219
booluser_catalog_table;/* use as an additional catalog
222220
* relation */
223221
}StdRdOptions;
@@ -247,55 +245,69 @@ typedef struct StdRdOptions
247245
#defineRelationGetTargetPageFreeSpace(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+
#defineRelationIsUsedAsCatalogTable(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+
typedefstructViewOptions
263+
{
264+
int32vl_len_;/* varlena header (do not touch directly!) */
265+
boolsecurity_barrier;
266+
intcheck_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
#defineRelationIsSecurityView(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
#defineRelationHasCheckOption(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
#defineRelationHasLocalCheckOption(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
#defineRelationHasCascadedCheckOption(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-
#defineRelationIsUsedAsCatalogTable(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)

[8]ページ先頭

©2009-2025 Movatter.jp