10
10
# Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
11
11
# Portions Copyright (c) 1994, Regents of the University of California
12
12
#
13
- # $PostgreSQL: pgsql/src/backend/catalog/genbki.pl,v 1.2 2010/01/0502:34:03 tgl Exp $
13
+ # $PostgreSQL: pgsql/src/backend/catalog/genbki.pl,v 1.3 2010/01/0506:41:44 tgl Exp $
14
14
#
15
15
# ----------------------------------------------------------------------
16
16
146
146
my $oid =$row -> {oid } ?" OID =$row ->{oid}" :' ' ;
147
147
printf BKI" insert%s (%s )\n " ,$oid ,$row -> {bki_values };
148
148
149
- # Writevalues to postgres.description and postgres.shdescription
149
+ # Writecomments to postgres.description and postgres.shdescription
150
150
if (defined $row -> {descr })
151
151
{
152
152
printf DESCR" %s \t %s \t 0\t %s \n " ,$row -> {oid },$catname ,$row -> {descr };
166
166
{
167
167
my $table =$catalogs -> {$table_name };
168
168
169
- # Build Schema_pg_xxx macros needed by relcache.c.
169
+ # Currently, all bootstrapped relations also need schemapg.h
170
+ # entries, so skip if the relation isn't to be in schemapg.h.
170
171
next if $table -> {schema_macro }ne ' True' ;
171
172
172
173
$schemapg_entries {$table_name } = [];
173
174
push @tables_needing_macros ,$table_name ;
174
175
my $is_bootstrap =$table -> {bootstrap };
175
176
176
- # Both postgres.bki and schemapg.h have entries corresponding
177
- # to user attributes
177
+ # Generate entries for user attributes.
178
178
my $attnum = 0;
179
179
my @user_attrs = @{$table -> {columns } };
180
180
foreach my $attr (@user_attrs )
184
184
$row -> {attnum } =$attnum ;
185
185
$row -> {attstattarget } =' -1' ;
186
186
187
- # Of these tables, only bootstrapped ones
188
- # have data declarations in postgres.bki
187
+ # If it's bootstrapped, put an entry in postgres.bki.
189
188
if ($is_bootstrap eq ' bootstrap' )
190
189
{
191
190
bki_insert($row ,@attnames );
192
191
}
193
192
194
- # Store schemapg entries for later
193
+ # Store schemapg entries for later.
195
194
$row = emit_schemapg_row($row ,grep {$bki_attr {$_ }eq ' bool' }@attnames );
196
195
push @{$schemapg_entries {$table_name } },
197
196
' {' .join (' ,' ,map $row -> {$_ },@attnames ) .' }' ;
198
197
}
199
198
200
- # Only postgres.bki has entriescorresponding to system
201
- # attributes, so onlybootstrapped relations here
199
+ # Generate entriesfor system attributes.
200
+ # We onlyneed postgres.bki entries, not schemapg.h entries.
202
201
if ($is_bootstrap eq ' bootstrap' )
203
202
{
204
203
$attnum = 0;
215
214
{
216
215
$attnum --;
217
216
my $row = emit_pgattr_row($table_name ,$attr );
218
-
219
- # pg_attribute has no oids -- skip
220
- next if $table_name eq ' pg_attribute' &&$row -> {attname }eq ' oid' ;
221
-
222
217
$row -> {attnum } =$attnum ;
223
218
$row -> {attstattarget } =' 0' ;
219
+
220
+ # some catalogs don't have oids
221
+ next if $table -> {without_oids }eq ' without_oids' &&
222
+ $row -> {attname }eq ' oid' ;
223
+
224
224
bki_insert($row ,@attnames );
225
225
}
226
226
}
299
299
300
300
301
301
# Given a system catalog name and a reference to a key-value pair corresponding
302
- # to the name and type of a column, generate a reference to apg_attribute
303
- # entry
302
+ # to the name and type of a column, generate a reference to ahash that
303
+ # represents a pg_attribute entry
304
304
sub emit_pgattr_row
305
305
{
306
306
my ($table_name ,$attr ) =@_ ;
@@ -317,7 +317,7 @@ sub emit_pgattr_row
317
317
$atttype =' _' .$1 ;
318
318
}
319
319
320
- # Copy the type data from pg_type,with minor modifications:
320
+ # Copy the type data from pg_type,and add some type-dependent items
321
321
foreach my $type (@types )
322
322
{
323
323
if (defined $type -> {typname } &&$type -> {typname }eq $atttype )
@@ -327,8 +327,17 @@ sub emit_pgattr_row
327
327
$row {attbyval } =$type -> {typbyval };
328
328
$row {attstorage } =$type -> {typstorage };
329
329
$row {attalign } =$type -> {typalign };
330
+ # set attndims if it's an array type
330
331
$row {attndims } =$type -> {typcategory }eq ' A' ?' 1' :' 0' ;
331
- $row {attnotnull } =$type -> {typstorage }eq ' x' ?' f' :' t' ;
332
+ # This approach to attnotnull is not really good enough;
333
+ # we need to know about prior column types too. Look at
334
+ # DefineAttr in bootstrap.c. For the moment it's okay for
335
+ # the column orders appearing in bootstrapped catalogs.
336
+ $row {attnotnull } =
337
+ $type -> {typname }eq ' oidvector' ?' t'
338
+ :$type -> {typname }eq ' int2vector' ?' t'
339
+ :$type -> {typlen }eq ' NAMEDATALEN' ?' t'
340
+ :$type -> {typlen } > 0 ?' t' :' f' ;
332
341
last ;
333
342
}
334
343
}
@@ -357,25 +366,21 @@ sub bki_insert
357
366
printf BKI" insert%s (%s )\n " ,$oid ,$bki_values ;
358
367
}
359
368
360
- # The values of a Schema_pg_xxx declaration are similar, but not
361
- # quite identical, to the corresponding values inpg_attribute .
369
+ # Thefield values of a Schema_pg_xxx declaration are similar, but not
370
+ # quite identical, to the corresponding values inpostgres.bki .
362
371
sub emit_schemapg_row
363
372
{
364
373
my $row =shift ;
365
374
my @bool_attrs =@_ ;
366
375
367
- # pg_index has attrelid = 0 in schemapg.h
368
- if ($row -> {attrelid }eq ' 2610' )
369
- {
370
- $row -> {attrelid } =' 0' ;
371
- }
372
-
376
+ # Supply appropriate quoting for these fields.
373
377
$row -> {attname } =q| {"| .$row -> {attname } .q| "}| ;
374
378
$row -> {attstorage } =q| '| .$row -> {attstorage } .q| '| ;
375
379
$row -> {attalign } =q| '| .$row -> {attalign } .q| '| ;
376
380
$row -> {attacl } =q| { 0 }| ;
377
381
378
- # Expand booleans, accounting for FLOAT4PASSBYVAL etc.
382
+ # Expand booleans from 'f'/'t' to 'false'/'true'.
383
+ # Some values might be other macros (eg FLOAT4PASSBYVAL), don't change.
379
384
foreach my $attr (@bool_attrs )
380
385
{
381
386
$row -> {$attr } =