1010# Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
1111# Portions Copyright (c) 1994, Regents of the University of California
1212#
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 $
1414#
1515# ----------------------------------------------------------------------
1616
146146my $oid =$row -> {oid } ?" OID =$row ->{oid}" :' ' ;
147147printf BKI" insert%s (%s )\n " ,$oid ,$row -> {bki_values };
148148
149- # Writevalues to postgres.description and postgres.shdescription
149+ # Writecomments to postgres.description and postgres.shdescription
150150if (defined $row -> {descr })
151151 {
152152printf DESCR" %s \t %s \t 0\t %s \n " ,$row -> {oid },$catname ,$row -> {descr };
166166 {
167167my $table =$catalogs -> {$table_name };
168168
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.
170171next if $table -> {schema_macro }ne ' True' ;
171172
172173$schemapg_entries {$table_name } = [];
173174push @tables_needing_macros ,$table_name ;
174175my $is_bootstrap =$table -> {bootstrap };
175176
176- # Both postgres.bki and schemapg.h have entries corresponding
177- # to user attributes
177+ # Generate entries for user attributes.
178178my $attnum = 0;
179179my @user_attrs = @{$table -> {columns } };
180180foreach my $attr (@user_attrs )
184184$row -> {attnum } =$attnum ;
185185$row -> {attstattarget } =' -1' ;
186186
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.
189188if ($is_bootstrap eq ' bootstrap' )
190189 {
191190 bki_insert($row ,@attnames );
192191 }
193192
194- # Store schemapg entries for later
193+ # Store schemapg entries for later.
195194$row = emit_schemapg_row($row ,grep {$bki_attr {$_ }eq ' bool' }@attnames );
196195push @{$schemapg_entries {$table_name } },
197196' {' .join (' ,' ,map $row -> {$_ },@attnames ) .' }' ;
198197 }
199198
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.
202201if ($is_bootstrap eq ' bootstrap' )
203202 {
204203$attnum = 0;
215214 {
216215$attnum --;
217216my $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-
222217$row -> {attnum } =$attnum ;
223218$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+
224224 bki_insert($row ,@attnames );
225225 }
226226 }
299299
300300
301301# 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
304304sub emit_pgattr_row
305305{
306306my ($table_name ,$attr ) =@_ ;
@@ -317,7 +317,7 @@ sub emit_pgattr_row
317317$atttype =' _' .$1 ;
318318 }
319319
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
321321foreach my $type (@types )
322322 {
323323if (defined $type -> {typname } &&$type -> {typname }eq $atttype )
@@ -327,8 +327,17 @@ sub emit_pgattr_row
327327$row {attbyval } =$type -> {typbyval };
328328$row {attstorage } =$type -> {typstorage };
329329$row {attalign } =$type -> {typalign };
330+ # set attndims if it's an array type
330331$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' ;
332341last ;
333342 }
334343 }
@@ -357,25 +366,21 @@ sub bki_insert
357366printf BKI" insert%s (%s )\n " ,$oid ,$bki_values ;
358367}
359368
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 .
362371sub emit_schemapg_row
363372{
364373my $row =shift ;
365374my @bool_attrs =@_ ;
366375
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.
373377$row -> {attname } =q| {"| .$row -> {attname } .q| "}| ;
374378$row -> {attstorage } =q| '| .$row -> {attstorage } .q| '| ;
375379$row -> {attalign } =q| '| .$row -> {attalign } .q| '| ;
376380$row -> {attacl } =q| { 0 }| ;
377381
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.
379384foreach my $attr (@bool_attrs )
380385 {
381386$row -> {$attr } =