Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ffcccd

Browse files
committed
Rationalize handling of array type names in bootstrap data.
Formerly, Catalog.pm turned a C array type declaration in the catalogheader files into a SQL type, e.g., 'foo[]'. Along the way, genbki.plturned this into '_foo' for the purpose of type lookups, but wrote 'foo[]'to postgres.bki. During bootstrap, bootscanner.l had to have a specialcase rule to tokenize this, and then MapArrayTypeName() would turn 'foo[]'into '_foo' one more time.This seems unnecessarily complicated, especially since nobody cares thatmuch about the readability of postgres.bki. Instead, make Catalog.pmconvert the C declaration into '_foo' to start with, and preserve thatrepresentation 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 nowdeclared like proconfig = _text ,rather than proconfig = text[] ,No documentation update, since the SGML docs didn't mention any of thisin the first place, and it's all pretty transparent to writers ofcatalog header files anyway.John NaylorDiscussion:https://postgr.es/m/CAJVSVGUNao=-Q2-vAN3PYcdF5tnL5JAHwGwzZGuYHtq+Mk_9ng@mail.gmail.com
1 parente90d4dd commit9ffcccd

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 intyyline = 1;/* line number for error reporting */
6565
%optionprefix="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(constchar*s)
1053-
{
1054-
inti,
1055-
j;
1056-
charnewStr[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-
returnpstrdup(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 oroid[], 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 ($atttypeeq'oid[]')
372+
elsif ($atttypeeq'_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 ='_' .$1if$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
externvoidInsertOneValue(char*value,inti);
4545
externvoidInsertOneNull(inti);
4646

47-
externchar*MapArrayTypeName(constchar*s);
48-
4947
externvoidindex_register(Oidheap,Oidind,IndexInfo*indexInfo);
5048
externvoidbuild_indices(void);
5149

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp