8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.24 2009/03/24 20:17:09 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.25 2009/04/04 00:45:02 alvherre Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -52,7 +52,7 @@ static relopt_bool boolRelOpts[] =
52
52
{
53
53
"autovacuum_enabled" ,
54
54
"Enables autovacuum in this relation" ,
55
- RELOPT_KIND_HEAP
55
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
56
56
},
57
57
true
58
58
},
@@ -106,55 +106,55 @@ static relopt_int intRelOpts[] =
106
106
{
107
107
"autovacuum_vacuum_threshold" ,
108
108
"Minimum number of tuple updates or deletes prior to vacuum" ,
109
- RELOPT_KIND_HEAP
109
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
110
110
},
111
111
50 ,0 ,INT_MAX
112
112
},
113
113
{
114
114
{
115
115
"autovacuum_analyze_threshold" ,
116
116
"Minimum number of tuple inserts, updates or deletes prior to analyze" ,
117
- RELOPT_KIND_HEAP
117
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
118
118
},
119
119
50 ,0 ,INT_MAX
120
120
},
121
121
{
122
122
{
123
123
"autovacuum_vacuum_cost_delay" ,
124
124
"Vacuum cost delay in milliseconds, for autovacuum" ,
125
- RELOPT_KIND_HEAP
125
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
126
126
},
127
127
20 ,0 ,100
128
128
},
129
129
{
130
130
{
131
131
"autovacuum_vacuum_cost_limit" ,
132
132
"Vacuum cost amount available before napping, for autovacuum" ,
133
- RELOPT_KIND_HEAP
133
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
134
134
},
135
135
200 ,1 ,10000
136
136
},
137
137
{
138
138
{
139
139
"autovacuum_freeze_min_age" ,
140
140
"Minimum age at which VACUUM should freeze a table row, for autovacuum" ,
141
- RELOPT_KIND_HEAP
141
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
142
142
},
143
143
100000000 ,0 ,1000000000
144
144
},
145
145
{
146
146
{
147
147
"autovacuum_freeze_max_age" ,
148
148
"Age at which to autovacuum a table to prevent transaction ID wraparound" ,
149
- RELOPT_KIND_HEAP
149
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
150
150
},
151
151
200000000 ,100000000 ,2000000000
152
152
},
153
153
{
154
154
{
155
155
"autovacuum_freeze_table_age" ,
156
156
"Age at which VACUUM should perform a full table sweep to replace old Xid values with FrozenXID" ,
157
- RELOPT_KIND_HEAP
157
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
158
158
},150000000 ,0 ,2000000000
159
159
},
160
160
/* list terminator */
@@ -167,15 +167,15 @@ static relopt_real realRelOpts[] =
167
167
{
168
168
"autovacuum_vacuum_scale_factor" ,
169
169
"Number of tuple updates or deletes prior to vacuum as a fraction of reltuples" ,
170
- RELOPT_KIND_HEAP
170
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
171
171
},
172
172
0.2 ,0.0 ,100.0
173
173
},
174
174
{
175
175
{
176
176
"autovacuum_analyze_scale_factor" ,
177
177
"Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples" ,
178
- RELOPT_KIND_HEAP
178
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
179
179
},
180
180
0.1 ,0.0 ,100.0
181
181
},
@@ -190,7 +190,7 @@ static relopt_string stringRelOpts[] =
190
190
};
191
191
192
192
static relopt_gen * * relOpts = NULL ;
193
- static int last_assigned_kind = RELOPT_KIND_LAST_DEFAULT + 1 ;
193
+ static bits32 last_assigned_kind = RELOPT_KIND_LAST_DEFAULT << 1 ;
194
194
195
195
static int num_custom_options = 0 ;
196
196
static relopt_gen * * custom_options = NULL ;
@@ -275,14 +275,20 @@ initialize_reloptions(void)
275
275
* Create a new relopt_kind value, to be used in custom reloptions by
276
276
* user-defined AMs.
277
277
*/
278
- int
278
+ relopt_kind
279
279
add_reloption_kind (void )
280
280
{
281
+ relopt_kind kind ;
282
+
283
+ /* don't hand out the last bit so that the wraparound check is portable */
281
284
if (last_assigned_kind >=RELOPT_KIND_MAX )
282
285
ereport (ERROR ,
283
- (errmsg ("user-defined relation parameter types limit exceeded" )));
286
+ (errcode (ERRCODE_PROGRAM_LIMIT_EXCEEDED ),
287
+ errmsg ("user-defined relation parameter types limit exceeded" )));
284
288
285
- return last_assigned_kind ++ ;
289
+ kind = (relopt_kind )last_assigned_kind ;
290
+ last_assigned_kind <<=1 ;
291
+ return kind ;
286
292
}
287
293
288
294
/*
@@ -325,7 +331,7 @@ add_reloption(relopt_gen *newoption)
325
331
* (for types other than string)
326
332
*/
327
333
static relopt_gen *
328
- allocate_reloption (int kind ,int type ,char * name ,char * desc )
334
+ allocate_reloption (bits32 kinds ,int type ,char * name ,char * desc )
329
335
{
330
336
MemoryContext oldcxt ;
331
337
size_t size ;
@@ -358,7 +364,7 @@ allocate_reloption(int kind, int type, char *name, char *desc)
358
364
newoption -> desc = pstrdup (desc );
359
365
else
360
366
newoption -> desc = NULL ;
361
- newoption -> kind = kind ;
367
+ newoption -> kinds = kinds ;
362
368
newoption -> namelen = strlen (name );
363
369
newoption -> type = type ;
364
370
@@ -372,11 +378,11 @@ allocate_reloption(int kind, int type, char *name, char *desc)
372
378
* Add a new boolean reloption
373
379
*/
374
380
void
375
- add_bool_reloption (int kind ,char * name ,char * desc ,bool default_val )
381
+ add_bool_reloption (bits32 kinds ,char * name ,char * desc ,bool default_val )
376
382
{
377
383
relopt_bool * newoption ;
378
384
379
- newoption = (relopt_bool * )allocate_reloption (kind ,RELOPT_TYPE_BOOL ,
385
+ newoption = (relopt_bool * )allocate_reloption (kinds ,RELOPT_TYPE_BOOL ,
380
386
name ,desc );
381
387
newoption -> default_val = default_val ;
382
388
@@ -388,12 +394,12 @@ add_bool_reloption(int kind, char *name, char *desc, bool default_val)
388
394
* Add a new integer reloption
389
395
*/
390
396
void
391
- add_int_reloption (int kind ,char * name ,char * desc ,int default_val ,
397
+ add_int_reloption (bits32 kinds ,char * name ,char * desc ,int default_val ,
392
398
int min_val ,int max_val )
393
399
{
394
400
relopt_int * newoption ;
395
401
396
- newoption = (relopt_int * )allocate_reloption (kind ,RELOPT_TYPE_INT ,
402
+ newoption = (relopt_int * )allocate_reloption (kinds ,RELOPT_TYPE_INT ,
397
403
name ,desc );
398
404
newoption -> default_val = default_val ;
399
405
newoption -> min = min_val ;
@@ -407,12 +413,12 @@ add_int_reloption(int kind, char *name, char *desc, int default_val,
407
413
* Add a new float reloption
408
414
*/
409
415
void
410
- add_real_reloption (int kind ,char * name ,char * desc ,double default_val ,
416
+ add_real_reloption (bits32 kinds ,char * name ,char * desc ,double default_val ,
411
417
double min_val ,double max_val )
412
418
{
413
419
relopt_real * newoption ;
414
420
415
- newoption = (relopt_real * )allocate_reloption (kind ,RELOPT_TYPE_REAL ,
421
+ newoption = (relopt_real * )allocate_reloption (kinds ,RELOPT_TYPE_REAL ,
416
422
name ,desc );
417
423
newoption -> default_val = default_val ;
418
424
newoption -> min = min_val ;
@@ -431,7 +437,7 @@ add_real_reloption(int kind, char *name, char *desc, double default_val,
431
437
* the validation.
432
438
*/
433
439
void
434
- add_string_reloption (int kind ,char * name ,char * desc ,char * default_val ,
440
+ add_string_reloption (bits32 kinds ,char * name ,char * desc ,char * default_val ,
435
441
validate_string_relopt validator )
436
442
{
437
443
MemoryContext oldcxt ;
@@ -450,7 +456,7 @@ add_string_reloption(int kind, char *name, char *desc, char *default_val,
450
456
newoption -> gen .desc = pstrdup (desc );
451
457
else
452
458
newoption -> gen .desc = NULL ;
453
- newoption -> gen .kind = kind ;
459
+ newoption -> gen .kinds = kinds ;
454
460
newoption -> gen .namelen = strlen (name );
455
461
newoption -> gen .type = RELOPT_TYPE_STRING ;
456
462
newoption -> validate_cb = validator ;
@@ -784,7 +790,7 @@ parseRelOptions(Datum options, bool validate, relopt_kind kind,
784
790
/* Build a list of expected options, based on kind */
785
791
786
792
for (i = 0 ;relOpts [i ];i ++ )
787
- if (relOpts [i ]-> kind == kind )
793
+ if (relOpts [i ]-> kinds & kind )
788
794
numoptions ++ ;
789
795
790
796
if (numoptions == 0 )
@@ -797,7 +803,7 @@ parseRelOptions(Datum options, bool validate, relopt_kind kind,
797
803
798
804
for (i = 0 ,j = 0 ;relOpts [i ];i ++ )
799
805
{
800
- if (relOpts [i ]-> kind == kind )
806
+ if (relOpts [i ]-> kinds & kind )
801
807
{
802
808
reloptions [j ].gen = relOpts [i ];
803
809
reloptions [j ].isset = false;
@@ -1116,7 +1122,16 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
1116
1122
bytea *
1117
1123
heap_reloptions (char relkind ,Datum reloptions ,bool validate )
1118
1124
{
1119
- return default_reloptions (reloptions ,validate ,RELOPT_KIND_HEAP );
1125
+ switch (relkind )
1126
+ {
1127
+ case RELKIND_TOASTVALUE :
1128
+ return default_reloptions (reloptions ,validate ,RELOPT_KIND_TOAST );
1129
+ case RELKIND_RELATION :
1130
+ return default_reloptions (reloptions ,validate ,RELOPT_KIND_HEAP );
1131
+ default :
1132
+ /* sequences, composite types and views are not supported */
1133
+ return NULL ;
1134
+ }
1120
1135
}
1121
1136
1122
1137