Skip to content

Commit 5219f80

Browse files
committed
Further code review for genbki.pl. Improve comments, fix some
rather random code choices, don't slavishly duplicate the original pg_attribute.h's failure to put an OID into Schema_pg_index entries.
1 parent daf5b0f commit 5219f80

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

src/backend/catalog/genbki.pl

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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/05 02:34:03 tgl Exp $
13+
# $PostgreSQL: pgsql/src/backend/catalog/genbki.pl,v 1.3 2010/01/05 06:41:44 tgl Exp $
1414
#
1515
#----------------------------------------------------------------------
1616

@@ -146,7 +146,7 @@
146146
my $oid = $row->{oid} ? "OID = $row->{oid} " : '';
147147
printf BKI "insert %s( %s)\n", $oid, $row->{bki_values};
148148

149-
# Write values to postgres.description and postgres.shdescription
149+
# Write comments to postgres.description and postgres.shdescription
150150
if (defined $row->{descr})
151151
{
152152
printf DESCR "%s\t%s\t0\t%s\n", $row->{oid}, $catname, $row->{descr};
@@ -166,15 +166,15 @@
166166
{
167167
my $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.
170171
next if $table->{schema_macro} ne 'True';
171172

172173
$schemapg_entries{$table_name} = [];
173174
push @tables_needing_macros, $table_name;
174175
my $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.
178178
my $attnum = 0;
179179
my @user_attrs = @{ $table->{columns} };
180180
foreach my $attr (@user_attrs)
@@ -184,21 +184,20 @@
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.
189188
if ($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);
196195
push @{ $schemapg_entries{$table_name} },
197196
'{ ' . join(', ', map $row->{$_}, @attnames) . ' }';
198197
}
199198

200-
# Only postgres.bki has entries corresponding to system
201-
# attributes, so only bootstrapped relations here
199+
# Generate entries for system attributes.
200+
# We only need postgres.bki entries, not schemapg.h entries.
202201
if ($is_bootstrap eq ' bootstrap')
203202
{
204203
$attnum = 0;
@@ -215,12 +214,13 @@
215214
{
216215
$attnum--;
217216
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-
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
}
@@ -299,8 +299,8 @@
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 a pg_attribute
303-
# entry
302+
# to the name and type of a column, generate a reference to a hash that
303+
# represents a pg_attribute entry
304304
sub emit_pgattr_row
305305
{
306306
my ($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
321321
foreach my $type (@types)
322322
{
323323
if ( 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';
332341
last;
333342
}
334343
}
@@ -357,25 +366,21 @@ sub bki_insert
357366
printf 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 in pg_attribute.
369+
# The field values of a Schema_pg_xxx declaration are similar, but not
370+
# quite identical, to the corresponding values in postgres.bki.
362371
sub emit_schemapg_row
363372
{
364373
my $row = shift;
365374
my @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.
379384
foreach my $attr (@bool_attrs)
380385
{
381386
$row->{$attr} =

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