Skip to content

Commit 9ffcccd

Browse files
committed
Rationalize handling of array type names in bootstrap data.
Formerly, Catalog.pm turned a C array type declaration in the catalog header files into a SQL type, e.g., 'foo[]'. Along the way, genbki.pl turned this into '_foo' for the purpose of type lookups, but wrote 'foo[]' to postgres.bki. During bootstrap, bootscanner.l had to have a special case rule to tokenize this, and then MapArrayTypeName() would turn 'foo[]' into '_foo' one more time. This seems unnecessarily complicated, especially since nobody cares that much about the readability of postgres.bki. Instead, make Catalog.pm convert the C declaration into '_foo' to start with, and preserve that representation of the type name throughout bootstrap data processing. Then rip out the special-case code in bootscanner.l and bootstrap.c. This changes postgres.bki to the extent that array fields are now declared like proconfig = _text , rather than proconfig = text[] , No documentation update, since the SGML docs didn't mention any of this in the first place, and it's all pretty transparent to writers of catalog header files anyway. John Naylor Discussion: https://postgr.es/m/CAJVSVGUNao=-Q2-vAN3PYcdF5tnL5JAHwGwzZGuYHtq+Mk_9ng@mail.gmail.com
1 parent e90d4dd commit 9ffcccd

File tree

5 files changed

+8
-46
lines changed

5 files changed

+8
-46
lines changed

src/backend/bootstrap/bootscanner.l

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ static int yyline = 1; /* line number for error reporting */
6565
%option prefix="boot_yy"
6666

6767

68-
D [0-9]
6968
id [-A-Za-z0-9_]+
7069
sid \"([^\"])*\"
71-
arrayid [A-Za-z0-9_]+\[{D}*\]
7270

7371
%%
7472

@@ -111,10 +109,6 @@ insert { return INSERT_TUPLE; }
111109
"NOT" { return XNOT; }
112110
"NULL" { return XNULL; }
113111

114-
{arrayid} {
115-
yylval.str = MapArrayTypeName(yytext);
116-
return ID;
117-
}
118112
{id} {
119113
yylval.str = scanstr(yytext);
120114
return ID;

src/backend/bootstrap/bootstrap.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,36 +1036,6 @@ AllocateAttribute(void)
10361036
MemoryContextAllocZero(TopMemoryContext, ATTRIBUTE_FIXED_PART_SIZE);
10371037
}
10381038

1039-
/*
1040-
* MapArrayTypeName
1041-
*
1042-
* Given a type name, produce the corresponding array type name by prepending
1043-
* '_' and truncating as needed to fit in NAMEDATALEN-1 bytes. This is only
1044-
* used in bootstrap mode, so we can get away with assuming that the input is
1045-
* ASCII and we don't need multibyte-aware truncation.
1046-
*
1047-
* The given string normally ends with '[]' or '[digits]'; we discard that.
1048-
*
1049-
* The result is a palloc'd string.
1050-
*/
1051-
char *
1052-
MapArrayTypeName(const char *s)
1053-
{
1054-
int i,
1055-
j;
1056-
char newStr[NAMEDATALEN];
1057-
1058-
newStr[0] = '_';
1059-
j = 1;
1060-
for (i = 0; i < NAMEDATALEN - 2 && s[i] != '['; i++, j++)
1061-
newStr[j] = s[i];
1062-
1063-
newStr[j] = '\0';
1064-
1065-
return pstrdup(newStr);
1066-
}
1067-
1068-
10691039
/*
10701040
* index_register() -- record an index that has been set up for building
10711041
* later.

src/backend/catalog/Catalog.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,14 @@ sub ParseHeader
161161
{
162162
$atttype = $RENAME_ATTTYPE{$atttype};
163163
}
164-
if ($attname =~ /(.*)\[.*\]/) # array attribute
164+
165+
# If the C name ends with '[]' or '[digits]', we have
166+
# an array type, so we discard that from the name and
167+
# prepend '_' to the type.
168+
if ($attname =~ /(\w+)\[\d*\]/)
165169
{
166170
$attname = $1;
167-
$atttype .= '[]';
171+
$atttype = '_' . $atttype;
168172
}
169173

170174
$column{type} = $atttype;

src/backend/catalog/genbki.pl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351

352352
# Replace OID synonyms with OIDs per the appropriate lookup rule.
353353
#
354-
# If the column type is oidvector or oid[], we have to replace
354+
# If the column type is oidvector or _oid, we have to replace
355355
# each element of the array as per the lookup rule.
356356
if ($column->{lookup})
357357
{
@@ -369,7 +369,7 @@
369369
\%bki_values, @lookupnames);
370370
$bki_values{$attname} = join(' ', @lookupoids);
371371
}
372-
elsif ($atttype eq 'oid[]')
372+
elsif ($atttype eq '_oid')
373373
{
374374
if ($bki_values{$attname} ne '_null_')
375375
{
@@ -598,10 +598,6 @@ sub morph_row_for_pgattr
598598

599599
$row->{attname} = $attname;
600600

601-
# Adjust type name for arrays: foo[] becomes _foo, so we can look it up in
602-
# pg_type
603-
$atttype = '_' . $1 if $atttype =~ /(.+)\[\]$/;
604-
605601
# Copy the type data from pg_type, and add some type-dependent items
606602
my $type = $types{$atttype};
607603

src/include/bootstrap/bootstrap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ extern void InsertOneTuple(Oid objectid);
4444
extern void InsertOneValue(char *value, int i);
4545
extern void InsertOneNull(int i);
4646

47-
extern char *MapArrayTypeName(const char *s);
48-
4947
extern void index_register(Oid heap, Oid ind, IndexInfo *indexInfo);
5048
extern void build_indices(void);
5149

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