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

Commit5463750

Browse files
committed
Change collate and ctype fields to type text
This changes the data type of the catalog fields datcollate, datctype,collcollate, and collctype from name to text. There wasn't ever areally good reason for them to be of type name; presumably this wasjust carried over from when they were fixed-size fields in pg_control,first into the corresponding pg_database fields, and then topg_collation. The values are not identifiers or object names, and wedon't ever look them up that way.Changing to type text saves space in the typical case, since localenames are typically only a few bytes long. But it is also possiblethat an ICU locale name with several customization options appendedcould be longer than 63 bytes, so this also enables that case, whichwas previously probably broken.Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>Discussion:https://www.postgresql.org/message-id/flat/5e756dd6-0e91-d778-96fd-b1bcb06c161a@2ndquadrant.com
1 parent9e283fc commit5463750

File tree

10 files changed

+105
-67
lines changed

10 files changed

+105
-67
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,7 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
23682368

23692369
<row>
23702370
<entry role="catalog_table_entry"><para role="column_definition">
2371-
<structfield>collcollate</structfield> <type>name</type>
2371+
<structfield>collcollate</structfield> <type>text</type>
23722372
</para>
23732373
<para>
23742374
<symbol>LC_COLLATE</symbol> for this collation object
@@ -2377,7 +2377,7 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
23772377

23782378
<row>
23792379
<entry role="catalog_table_entry"><para role="column_definition">
2380-
<structfield>collctype</structfield> <type>name</type>
2380+
<structfield>collctype</structfield> <type>text</type>
23812381
</para>
23822382
<para>
23832383
<symbol>LC_CTYPE</symbol> for this collation object
@@ -2951,24 +2951,6 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
29512951
</para></entry>
29522952
</row>
29532953

2954-
<row>
2955-
<entry role="catalog_table_entry"><para role="column_definition">
2956-
<structfield>datcollate</structfield> <type>name</type>
2957-
</para>
2958-
<para>
2959-
LC_COLLATE for this database
2960-
</para></entry>
2961-
</row>
2962-
2963-
<row>
2964-
<entry role="catalog_table_entry"><para role="column_definition">
2965-
<structfield>datctype</structfield> <type>name</type>
2966-
</para>
2967-
<para>
2968-
LC_CTYPE for this database
2969-
</para></entry>
2970-
</row>
2971-
29722954
<row>
29732955
<entry role="catalog_table_entry"><para role="column_definition">
29742956
<structfield>datistemplate</structfield> <type>bool</type>
@@ -3043,6 +3025,24 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
30433025
</para></entry>
30443026
</row>
30453027

3028+
<row>
3029+
<entry role="catalog_table_entry"><para role="column_definition">
3030+
<structfield>datcollate</structfield> <type>text</type>
3031+
</para>
3032+
<para>
3033+
LC_COLLATE for this database
3034+
</para></entry>
3035+
</row>
3036+
3037+
<row>
3038+
<entry role="catalog_table_entry"><para role="column_definition">
3039+
<structfield>datctype</structfield> <type>text</type>
3040+
</para>
3041+
<para>
3042+
LC_CTYPE for this database
3043+
</para></entry>
3044+
</row>
3045+
30463046
<row>
30473047
<entry role="catalog_table_entry"><para role="column_definition">
30483048
<structfield>datacl</structfield> <type>aclitem[]</type>

‎src/backend/catalog/pg_collation.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ CollationCreate(const char *collname, Oid collnamespace,
5858
HeapTupletup;
5959
Datumvalues[Natts_pg_collation];
6060
boolnulls[Natts_pg_collation];
61-
NameDataname_name,
62-
name_collate,
63-
name_ctype;
61+
NameDataname_name;
6462
Oidoid;
6563
ObjectAddressmyself,
6664
referenced;
@@ -163,10 +161,8 @@ CollationCreate(const char *collname, Oid collnamespace,
163161
values[Anum_pg_collation_collprovider-1]=CharGetDatum(collprovider);
164162
values[Anum_pg_collation_collisdeterministic-1]=BoolGetDatum(collisdeterministic);
165163
values[Anum_pg_collation_collencoding-1]=Int32GetDatum(collencoding);
166-
namestrcpy(&name_collate,collcollate);
167-
values[Anum_pg_collation_collcollate-1]=NameGetDatum(&name_collate);
168-
namestrcpy(&name_ctype,collctype);
169-
values[Anum_pg_collation_collctype-1]=NameGetDatum(&name_ctype);
164+
values[Anum_pg_collation_collcollate-1]=CStringGetTextDatum(collcollate);
165+
values[Anum_pg_collation_collctype-1]=CStringGetTextDatum(collctype);
170166
if (collversion)
171167
values[Anum_pg_collation_collversion-1]=CStringGetTextDatum(collversion);
172168
else

‎src/backend/commands/collationcmds.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,30 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
129129
{
130130
Oidcollid;
131131
HeapTupletp;
132+
Datumdatum;
133+
boolisnull;
132134

133135
collid=get_collation_oid(defGetQualifiedName(fromEl), false);
134136
tp=SearchSysCache1(COLLOID,ObjectIdGetDatum(collid));
135137
if (!HeapTupleIsValid(tp))
136138
elog(ERROR,"cache lookup failed for collation %u",collid);
137139

138-
collcollate=pstrdup(NameStr(((Form_pg_collation)GETSTRUCT(tp))->collcollate));
139-
collctype=pstrdup(NameStr(((Form_pg_collation)GETSTRUCT(tp))->collctype));
140140
collprovider= ((Form_pg_collation)GETSTRUCT(tp))->collprovider;
141141
collisdeterministic= ((Form_pg_collation)GETSTRUCT(tp))->collisdeterministic;
142142
collencoding= ((Form_pg_collation)GETSTRUCT(tp))->collencoding;
143143

144+
datum=SysCacheGetAttr(COLLOID,tp,Anum_pg_collation_collcollate,&isnull);
145+
if (!isnull)
146+
collcollate=TextDatumGetCString(datum);
147+
else
148+
collcollate=NULL;
149+
150+
datum=SysCacheGetAttr(COLLOID,tp,Anum_pg_collation_collctype,&isnull);
151+
if (!isnull)
152+
collctype=TextDatumGetCString(datum);
153+
else
154+
collctype=NULL;
155+
144156
ReleaseSysCache(tp);
145157

146158
/*
@@ -314,7 +326,7 @@ AlterCollation(AlterCollationStmt *stmt)
314326
OidcollOid;
315327
HeapTupletup;
316328
Form_pg_collationcollForm;
317-
Datumcollversion;
329+
Datumdatum;
318330
boolisnull;
319331
char*oldversion;
320332
char*newversion;
@@ -332,11 +344,12 @@ AlterCollation(AlterCollationStmt *stmt)
332344
elog(ERROR,"cache lookup failed for collation %u",collOid);
333345

334346
collForm= (Form_pg_collation)GETSTRUCT(tup);
335-
collversion=SysCacheGetAttr(COLLOID,tup,Anum_pg_collation_collversion,
336-
&isnull);
337-
oldversion=isnull ?NULL :TextDatumGetCString(collversion);
347+
datum=SysCacheGetAttr(COLLOID,tup,Anum_pg_collation_collversion,&isnull);
348+
oldversion=isnull ?NULL :TextDatumGetCString(datum);
338349

339-
newversion=get_collation_actual_version(collForm->collprovider,NameStr(collForm->collcollate));
350+
datum=SysCacheGetAttr(COLLOID,tup,Anum_pg_collation_collcollate,&isnull);
351+
Assert(!isnull);
352+
newversion=get_collation_actual_version(collForm->collprovider,TextDatumGetCString(datum));
340353

341354
/* cannot change from NULL to non-NULL or vice versa */
342355
if ((!oldversion&&newversion)|| (oldversion&& !newversion))
@@ -383,8 +396,9 @@ pg_collation_actual_version(PG_FUNCTION_ARGS)
383396
{
384397
Oidcollid=PG_GETARG_OID(0);
385398
HeapTupletp;
386-
char*collcollate;
387399
charcollprovider;
400+
Datumdatum;
401+
boolisnull;
388402
char*version;
389403

390404
tp=SearchSysCache1(COLLOID,ObjectIdGetDatum(collid));
@@ -393,12 +407,13 @@ pg_collation_actual_version(PG_FUNCTION_ARGS)
393407
(errcode(ERRCODE_UNDEFINED_OBJECT),
394408
errmsg("collation with OID %u does not exist",collid)));
395409

396-
collcollate=pstrdup(NameStr(((Form_pg_collation)GETSTRUCT(tp))->collcollate));
397410
collprovider= ((Form_pg_collation)GETSTRUCT(tp))->collprovider;
398411

399-
ReleaseSysCache(tp);
412+
datum=SysCacheGetAttr(COLLOID,tp,Anum_pg_collation_collcollate,&isnull);
413+
Assert(!isnull);
414+
version=get_collation_actual_version(collprovider,TextDatumGetCString(datum));
400415

401-
version=get_collation_actual_version(collprovider,collcollate);
416+
ReleaseSysCache(tp);
402417

403418
if (version)
404419
PG_RETURN_TEXT_P(cstring_to_text(version));
@@ -546,7 +561,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
546561
#ifdefREAD_LOCALE_A_OUTPUT
547562
{
548563
FILE*locale_a_handle;
549-
charlocalebuf[NAMEDATALEN];/* we assume ASCII so this is fine */
564+
charlocalebuf[LOCALE_NAME_BUFLEN];
550565
intnvalid=0;
551566
Oidcollid;
552567
CollAliasData*aliases;
@@ -570,7 +585,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
570585
{
571586
size_tlen;
572587
intenc;
573-
charalias[NAMEDATALEN];
588+
charalias[LOCALE_NAME_BUFLEN];
574589

575590
len=strlen(localebuf);
576591

‎src/backend/commands/dbcommands.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,8 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
570570
DirectFunctionCall1(namein,CStringGetDatum(dbname));
571571
new_record[Anum_pg_database_datdba-1]=ObjectIdGetDatum(datdba);
572572
new_record[Anum_pg_database_encoding-1]=Int32GetDatum(encoding);
573-
new_record[Anum_pg_database_datcollate-1]=
574-
DirectFunctionCall1(namein,CStringGetDatum(dbcollate));
575-
new_record[Anum_pg_database_datctype-1]=
576-
DirectFunctionCall1(namein,CStringGetDatum(dbctype));
573+
new_record[Anum_pg_database_datcollate-1]=CStringGetTextDatum(dbcollate);
574+
new_record[Anum_pg_database_datctype-1]=CStringGetTextDatum(dbctype);
577575
new_record[Anum_pg_database_datistemplate-1]=BoolGetDatum(dbistemplate);
578576
new_record[Anum_pg_database_datallowconn-1]=BoolGetDatum(dballowconnections);
579577
new_record[Anum_pg_database_datconnlimit-1]=Int32GetDatum(dbconnlimit);
@@ -1867,6 +1865,9 @@ get_db_info(const char *name, LOCKMODE lockmode,
18671865

18681866
if (strcmp(name,NameStr(dbform->datname))==0)
18691867
{
1868+
Datumdatum;
1869+
boolisnull;
1870+
18701871
/* oid of the database */
18711872
if (dbIdP)
18721873
*dbIdP=dbOid;
@@ -1893,9 +1894,17 @@ get_db_info(const char *name, LOCKMODE lockmode,
18931894
*dbTablespace=dbform->dattablespace;
18941895
/* default locale settings for this database */
18951896
if (dbCollate)
1896-
*dbCollate=pstrdup(NameStr(dbform->datcollate));
1897+
{
1898+
datum=SysCacheGetAttr(DATABASEOID,tuple,Anum_pg_database_datcollate,&isnull);
1899+
Assert(!isnull);
1900+
*dbCollate=TextDatumGetCString(datum);
1901+
}
18971902
if (dbCtype)
1898-
*dbCtype=pstrdup(NameStr(dbform->datctype));
1903+
{
1904+
datum=SysCacheGetAttr(DATABASEOID,tuple,Anum_pg_database_datctype,&isnull);
1905+
Assert(!isnull);
1906+
*dbCtype=TextDatumGetCString(datum);
1907+
}
18991908
ReleaseSysCache(tuple);
19001909
result= true;
19011910
break;

‎src/backend/utils/adt/pg_locale.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pg_perm_setlocale(int category, const char *locale)
179179
*/
180180
if (category==LC_CTYPE)
181181
{
182-
staticcharsave_lc_ctype[NAMEDATALEN+20];
182+
staticcharsave_lc_ctype[LOCALE_NAME_BUFLEN];
183183

184184
/* copy setlocale() return value before callee invokes it again */
185185
strlcpy(save_lc_ctype,result,sizeof(save_lc_ctype));
@@ -1288,17 +1288,21 @@ lookup_collation_cache(Oid collation, bool set_flags)
12881288
{
12891289
/* Attempt to set the flags */
12901290
HeapTupletp;
1291-
Form_pg_collationcollform;
1291+
Datumdatum;
1292+
boolisnull;
12921293
constchar*collcollate;
12931294
constchar*collctype;
12941295

12951296
tp=SearchSysCache1(COLLOID,ObjectIdGetDatum(collation));
12961297
if (!HeapTupleIsValid(tp))
12971298
elog(ERROR,"cache lookup failed for collation %u",collation);
1298-
collform= (Form_pg_collation)GETSTRUCT(tp);
12991299

1300-
collcollate=NameStr(collform->collcollate);
1301-
collctype=NameStr(collform->collctype);
1300+
datum=SysCacheGetAttr(COLLOID,tp,Anum_pg_collation_collcollate,&isnull);
1301+
Assert(!isnull);
1302+
collcollate=TextDatumGetCString(datum);
1303+
datum=SysCacheGetAttr(COLLOID,tp,Anum_pg_collation_collctype,&isnull);
1304+
Assert(!isnull);
1305+
collctype=TextDatumGetCString(datum);
13021306

13031307
cache_entry->collate_is_c= ((strcmp(collcollate,"C")==0)||
13041308
(strcmp(collcollate,"POSIX")==0));
@@ -1484,16 +1488,20 @@ pg_newlocale_from_collation(Oid collid)
14841488
constchar*collctypepg_attribute_unused();
14851489
structpg_locale_structresult;
14861490
pg_locale_tresultp;
1487-
Datumcollversion;
1491+
Datumdatum;
14881492
boolisnull;
14891493

14901494
tp=SearchSysCache1(COLLOID,ObjectIdGetDatum(collid));
14911495
if (!HeapTupleIsValid(tp))
14921496
elog(ERROR,"cache lookup failed for collation %u",collid);
14931497
collform= (Form_pg_collation)GETSTRUCT(tp);
14941498

1495-
collcollate=NameStr(collform->collcollate);
1496-
collctype=NameStr(collform->collctype);
1499+
datum=SysCacheGetAttr(COLLOID,tp,Anum_pg_collation_collcollate,&isnull);
1500+
Assert(!isnull);
1501+
collcollate=TextDatumGetCString(datum);
1502+
datum=SysCacheGetAttr(COLLOID,tp,Anum_pg_collation_collctype,&isnull);
1503+
Assert(!isnull);
1504+
collctype=TextDatumGetCString(datum);
14971505

14981506
/* We'll fill in the result struct locally before allocating memory */
14991507
memset(&result,0,sizeof(result));
@@ -1587,13 +1595,15 @@ pg_newlocale_from_collation(Oid collid)
15871595
#endif/* not USE_ICU */
15881596
}
15891597

1590-
collversion=SysCacheGetAttr(COLLOID,tp,Anum_pg_collation_collversion,
1598+
datum=SysCacheGetAttr(COLLOID,tp,Anum_pg_collation_collversion,
15911599
&isnull);
15921600
if (!isnull)
15931601
{
15941602
char*actual_versionstr;
15951603
char*collversionstr;
15961604

1605+
collversionstr=TextDatumGetCString(datum);
1606+
15971607
actual_versionstr=get_collation_actual_version(collform->collprovider,collcollate);
15981608
if (!actual_versionstr)
15991609
{
@@ -1606,7 +1616,6 @@ pg_newlocale_from_collation(Oid collid)
16061616
(errmsg("collation \"%s\" has no actual version, but a version was specified",
16071617
NameStr(collform->collname))));
16081618
}
1609-
collversionstr=TextDatumGetCString(collversion);
16101619

16111620
if (strcmp(actual_versionstr,collversionstr)!=0)
16121621
ereport(WARNING,

‎src/backend/utils/init/postinit.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include"storage/sync.h"
5454
#include"tcop/tcopprot.h"
5555
#include"utils/acl.h"
56+
#include"utils/builtins.h"
5657
#include"utils/fmgroids.h"
5758
#include"utils/guc.h"
5859
#include"utils/memutils.h"
@@ -306,6 +307,8 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect
306307
{
307308
HeapTupletup;
308309
Form_pg_databasedbform;
310+
Datumdatum;
311+
boolisnull;
309312
char*collate;
310313
char*ctype;
311314

@@ -389,8 +392,12 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect
389392
PGC_BACKEND,PGC_S_DYNAMIC_DEFAULT);
390393

391394
/* assign locale variables */
392-
collate=NameStr(dbform->datcollate);
393-
ctype=NameStr(dbform->datctype);
395+
datum=SysCacheGetAttr(DATABASEOID,tup,Anum_pg_database_datcollate,&isnull);
396+
Assert(!isnull);
397+
collate=TextDatumGetCString(datum);
398+
datum=SysCacheGetAttr(DATABASEOID,tup,Anum_pg_database_datctype,&isnull);
399+
Assert(!isnull);
400+
ctype=TextDatumGetCString(datum);
394401

395402
if (pg_perm_setlocale(LC_COLLATE,collate)==NULL)
396403
ereport(FATAL,

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO202201201
56+
#defineCATALOG_VERSION_NO202201271
5757

5858
#endif

‎src/include/catalog/pg_collation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ CATALOG(pg_collation,3456,CollationRelationId)
3939
charcollprovider;/* see constants below */
4040
boolcollisdeterministicBKI_DEFAULT(t);
4141
int32collencoding;/* encoding for this collation; -1 = "all" */
42-
NameDatacollcollate;/* LC_COLLATE setting */
43-
NameDatacollctype;/* LC_CTYPE setting */
4442
#ifdefCATALOG_VARLEN/* variable-length fields start here */
43+
textcollcollateBKI_FORCE_NOT_NULL;/* LC_COLLATE setting */
44+
textcollctypeBKI_FORCE_NOT_NULL;/* LC_CTYPE setting */
4545
textcollversionBKI_DEFAULT(_null_);/* provider-dependent
4646
* version of collation
4747
* data */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp