Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9e9b9ac

Browse files
committed
Make a code-cleanup pass over the collations patch.
This patch is almost entirely cosmetic --- mostly cleaning up a lot of neglected comments, and fixing code layout problems in places where the patch made lines too long and then pgindent did weird things with that. I did find a bug-of-omission in equalTupleDescs().
1 parent 0cfdc1c commit 9e9b9ac

24 files changed

+179
-118
lines changed

doc/src/sgml/catalogs.sgml

+4-4
Original file line numberDiff line numberDiff line change
@@ -2159,8 +2159,8 @@
21592159
(<structfield>collname</>, <structfield>collnamespace</>).
21602160
<productname>PostgreSQL</productname> generally ignores all
21612161
collations that do not have <structfield>collencoding</> equal to
2162-
either the current database's encoding or -1, and creation of new
2163-
entries matching an entry with <structfield>collencoding</> = -1
2162+
either the current database's encoding or -1, and creation of new entries
2163+
with the same name as an entry with <structfield>collencoding</> = -1
21642164
is forbidden. Therefore it is sufficient to use a qualified SQL name
21652165
(<replaceable>schema</>.<replaceable>name</>) to identify a collation,
21662166
even though this is not unique according to the catalog definition.
@@ -6138,8 +6138,8 @@
61386138
of the type. If the type does not support collations, this will
61396139
be zero. A base type that supports collations will have
61406140
<symbol>DEFAULT_COLLATION_OID</symbol> here. A domain over a
6141-
collatable type can have some other collation OID, if one was defined
6142-
for the domain.
6141+
collatable type can have some other collation OID, if one was
6142+
specified for the domain.
61436143
</para></entry>
61446144
</row>
61456145

doc/src/sgml/indices.sgml

+12-15
Original file line numberDiff line numberDiff line change
@@ -1004,12 +1004,11 @@ SELECT am.amname AS index_method,
10041004

10051005

10061006
<sect1 id="indexes-collations">
1007-
<title>Collations and Indexes</title>
1007+
<title>Indexes and Collations</title>
10081008

10091009
<para>
1010-
An index can only support one collation for one column or
1011-
expression. If multiple collations are of interest, multiple
1012-
indexes may be created.
1010+
An index can support only one collation per index column.
1011+
If multiple collations are of interest, multiple indexes may be needed.
10131012
</para>
10141013

10151014
<para>
@@ -1022,23 +1021,21 @@ CREATE TABLE test1c (
10221021

10231022
CREATE INDEX test1c_content_index ON test1c (content);
10241023
</programlisting>
1025-
The created index automatically follows the collation of the
1026-
underlying column, and so a query of the form
1024+
The index automatically uses the collation of the
1025+
underlying column. So a query of the form
10271026
<programlisting>
1028-
SELECT * FROM test1c WHERE content = <replaceable>constant</replaceable>;
1027+
SELECT * FROM test1c WHERE content &gt; <replaceable>constant</replaceable>;
10291028
</programlisting>
1030-
could use the index.
1031-
</para>
1032-
1033-
<para>
1034-
If in addition, a query of the form, say,
1029+
could use the index, because the comparison will by default use the
1030+
collation of the column. However, this index cannot accelerate queries
1031+
that involve some other collation. So if queries of the form, say,
10351032
<programlisting>
10361033
SELECT * FROM test1c WHERE content &gt; <replaceable>constant</replaceable> COLLATE "y";
10371034
</programlisting>
1038-
is of interest, an additional index could be created that supports
1039-
the <literal>"y"</literal> collation, like so:
1035+
are also of interest, an additional index could be created that supports
1036+
the <literal>"y"</literal> collation, like this:
10401037
<programlisting>
1041-
CREATE INDEX test1c_content_index ON test1c (content COLLATE "y");
1038+
CREATE INDEX test1c_content_y_index ON test1c (content COLLATE "y");
10421039
</programlisting>
10431040
</para>
10441041
</sect1>

doc/src/sgml/ref/create_collation.sgml

+4-3
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ CREATE COLLATION <replaceable>name</replaceable> FROM <replaceable>existing_coll
108108
<listitem>
109109
<para>
110110
The name of an existing collation to copy. The new collation
111-
will have the same properties as the existing one, but they
112-
will become independent objects.
111+
will have the same properties as the existing one, but it
112+
will be an independent object.
113113
</para>
114114
</listitem>
115115
</varlistentry>
@@ -134,7 +134,8 @@ CREATE COLLATION <replaceable>name</replaceable> FROM <replaceable>existing_coll
134134
<title>Examples</title>
135135

136136
<para>
137-
To create a collation from the locale <literal>fr_FR.utf8</literal>
137+
To create a collation from the operating system locale
138+
<literal>fr_FR.utf8</literal>
138139
(assuming the current database encoding is <literal>UTF8</literal>):
139140
<programlisting>
140141
CREATE COLLATION french (LOCALE = 'fr_FR.utf8');

doc/src/sgml/ref/create_domain.sgml

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ CREATE DOMAIN <replaceable class="parameter">name</replaceable> [ AS ] <replacea
9090
<para>
9191
An optional collation for the domain. If no collation is
9292
specified, the underlying data type's default collation is used.
93-
The underlying type must be collatable when <literal>COLLATE</>
93+
The underlying type must be collatable if <literal>COLLATE</>
9494
is specified.
9595
</para>
9696
</listitem>

doc/src/sgml/ref/create_index.sgml

+9-3
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ <replaceable class="parameter">name</
188188
The name of the collation to use for the index. By default,
189189
the index uses the collation declared for the column to be
190190
indexed or the result collation of the expression to be
191-
indexed. Indexes with nondefault collations are
192-
available for use by queries that involve expressions using
193-
nondefault collations.
191+
indexed. Indexes with non-default collations can be useful for
192+
queries that involve expressions using non-default collations.
194193
</para>
195194
</listitem>
196195
</varlistentry>
@@ -537,6 +536,13 @@ CREATE INDEX ON films ((lower(title)));
537536
will choose a name, typically <literal>films_lower_idx</>.)
538537
</para>
539538

539+
<para>
540+
To create an index with non-default collation:
541+
<programlisting>
542+
CREATE INDEX title_idx_german ON films (title COLLATE "de_DE");
543+
</programlisting>
544+
</para>
545+
540546
<para>
541547
To create an index with non-default sort ordering of nulls:
542548
<programlisting>

doc/src/sgml/ref/create_type.sgml

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,10 @@ CREATE TYPE <replaceable class="parameter">name</replaceable>
355355
</para>
356356

357357
<para>
358-
If the optional
358+
If the optional boolean
359359
parameter <replaceable class="parameter">collatable</replaceable>
360360
is true, column definitions and expressions of the type may carry
361-
collation information and allow the use of
361+
collation information through use of
362362
the <literal>COLLATE</literal> clause. It is up to the
363363
implementations of the functions operating on the type to actually
364364
make use of the collation information; this does not happen

doc/src/sgml/regress.sgml

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ gmake check LANG=C ENCODING=EUC_JP
238238
</sect2>
239239

240240
<sect2>
241-
<title>Extra tests</title>
241+
<title>Extra Tests</title>
242242

243243
<para>
244244
The regression test suite contains a few test files that are not
@@ -253,8 +253,8 @@ gmake check EXTRA_TESTS=numeric_big
253253
<screen>
254254
gmake check EXTRA_TESTS=collate.linux.utf8 LANG=en_US.utf8
255255
</screen>
256-
This test works only on Linux/glibc platforms and when run in a
257-
UTF-8 locale.
256+
The <literal>collate.linux.utf8</> test works only on Linux/glibc
257+
platforms, and only when run in a locale that uses UTF-8 encoding.
258258
</para>
259259
</sect2>
260260
</sect1>

src/backend/access/common/tupdesc.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
360360
return false;
361361
if (attr1->attinhcount != attr2->attinhcount)
362362
return false;
363+
if (attr1->attcollation != attr2->attcollation)
364+
return false;
363365
/* attacl and attoptions are not even present... */
364366
}
365367

@@ -611,7 +613,9 @@ BuildDescForRelation(List *schema)
611613
* BuildDescFromLists
612614
*
613615
* Build a TupleDesc given lists of column names (as String nodes),
614-
* column type OIDs, and column typmods. No constraints are generated.
616+
* column type OIDs, typmods, and collation OIDs.
617+
*
618+
* No constraints are generated.
615619
*
616620
* This is essentially a cut-down version of BuildDescForRelation for use
617621
* with functions returning RECORD.

src/backend/catalog/dependency.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -2227,14 +2227,16 @@ getObjectDescription(const ObjectAddress *object)
22272227
case OCLASS_COLLATION:
22282228
{
22292229
HeapTuple collTup;
2230+
Form_pg_collation coll;
22302231

22312232
collTup = SearchSysCache1(COLLOID,
22322233
ObjectIdGetDatum(object->objectId));
22332234
if (!HeapTupleIsValid(collTup))
22342235
elog(ERROR, "cache lookup failed for collation %u",
22352236
object->objectId);
2237+
coll = (Form_pg_collation) GETSTRUCT(collTup);
22362238
appendStringInfo(&buffer, _("collation %s"),
2237-
NameStr(((Form_pg_collation) GETSTRUCT(collTup))->collname));
2239+
NameStr(coll->collname));
22382240
ReleaseSysCache(collTup);
22392241
break;
22402242
}

src/backend/catalog/heap.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
644644

645645
/*
646646
* First we add the user attributes. This is also a convenient place to
647-
* add dependencies on their datatypes.
647+
* add dependencies on their datatypes and collations.
648648
*/
649649
for (i = 0; i < natts; i++)
650650
{
@@ -666,7 +666,9 @@ AddNewAttributeTuples(Oid new_rel_oid,
666666
referenced.objectSubId = 0;
667667
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
668668

669-
if (OidIsValid(attr->attcollation))
669+
/* The default collation is pinned, so don't bother recording it */
670+
if (OidIsValid(attr->attcollation) &&
671+
attr->attcollation != DEFAULT_COLLATION_OID)
670672
{
671673
referenced.classId = CollationRelationId;
672674
referenced.objectId = attr->attcollation;
@@ -921,7 +923,7 @@ AddNewRelationType(const char *typeName,
921923
-1, /* typmod */
922924
0, /* array dimensions for typBaseType */
923925
false, /* Type NOT NULL */
924-
InvalidOid); /* typcollation */
926+
InvalidOid); /* rowtypes never have a collation */
925927
}
926928

927929
/* --------------------------------
@@ -1183,7 +1185,7 @@ heap_create_with_catalog(const char *relname,
11831185
-1, /* typmod */
11841186
0, /* array dimensions for typBaseType */
11851187
false, /* Type NOT NULL */
1186-
InvalidOid); /* typcollation */
1188+
InvalidOid); /* rowtypes never have a collation */
11871189

11881190
pfree(relarrayname);
11891191
}

src/backend/catalog/index.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ ConstructTupleDescriptor(Relation heapRelation,
351351
to->atthasdef = false;
352352
to->attislocal = true;
353353
to->attinhcount = 0;
354-
355354
to->attcollation = collationObjectId[i];
356355
}
357356
else
@@ -388,7 +387,6 @@ ConstructTupleDescriptor(Relation heapRelation,
388387
to->attcacheoff = -1;
389388
to->atttypmod = -1;
390389
to->attislocal = true;
391-
392390
to->attcollation = collationObjectId[i];
393391

394392
ReleaseSysCache(tuple);
@@ -653,6 +651,7 @@ UpdateIndexRelation(Oid indexoid,
653651
* indexColNames: column names to use for index (List of char *)
654652
* accessMethodObjectId: OID of index AM to use
655653
* tableSpaceId: OID of tablespace to use
654+
* collationObjectId: array of collation OIDs, one per index column
656655
* classObjectId: array of index opclass OIDs, one per index column
657656
* coloptions: array of per-index-column indoption settings
658657
* reloptions: AM-specific options
@@ -871,7 +870,8 @@ index_create(Relation heapRelation,
871870
* ----------------
872871
*/
873872
UpdateIndexRelation(indexRelationId, heapRelationId, indexInfo,
874-
collationObjectId, classObjectId, coloptions, isprimary, is_exclusion,
873+
collationObjectId, classObjectId, coloptions,
874+
isprimary, is_exclusion,
875875
!deferrable,
876876
!concurrent);
877877

@@ -965,9 +965,11 @@ index_create(Relation heapRelation,
965965
}
966966

967967
/* Store dependency on collations */
968+
/* The default collation is pinned, so don't bother recording it */
968969
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
969970
{
970-
if (OidIsValid(collationObjectId[i]))
971+
if (OidIsValid(collationObjectId[i]) &&
972+
collationObjectId[i] != DEFAULT_COLLATION_OID)
971973
{
972974
referenced.classId = CollationRelationId;
973975
referenced.objectId = collationObjectId[i];
@@ -2445,8 +2447,8 @@ validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
24452447
ivinfo.num_heap_tuples = heapRelation->rd_rel->reltuples;
24462448
ivinfo.strategy = NULL;
24472449

2448-
state.tuplesort = tuplesort_begin_datum(TIDOID,
2449-
TIDLessOperator, InvalidOid, false,
2450+
state.tuplesort = tuplesort_begin_datum(TIDOID, TIDLessOperator,
2451+
InvalidOid, false,
24502452
maintenance_work_mem,
24512453
false);
24522454
state.htups = state.itups = state.tups_inserted = 0;

src/backend/catalog/pg_type.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,9 @@ GenerateTypeDependencies(Oid typeNamespace,
643643
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
644644
}
645645

646-
/* Normal dependency from a domain to its base type's collation. */
647-
if (OidIsValid(typeCollation))
646+
/* Normal dependency from a domain to its collation. */
647+
/* We know the default collation is pinned, so don't bother recording it */
648+
if (OidIsValid(typeCollation) && typeCollation != DEFAULT_COLLATION_OID)
648649
{
649650
referenced.classId = CollationRelationId;
650651
referenced.objectId = typeCollation;

src/backend/commands/indexcmds.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ DefineIndex(RangeVar *heapRelation,
350350
collationObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
351351
classObjectId = (Oid *) palloc(numberOfAttributes * sizeof(Oid));
352352
coloptions = (int16 *) palloc(numberOfAttributes * sizeof(int16));
353-
ComputeIndexAttrs(indexInfo, collationObjectId, classObjectId, coloptions, attributeList,
353+
ComputeIndexAttrs(indexInfo, collationObjectId, classObjectId,
354+
coloptions, attributeList,
354355
exclusionOpNames, relationId,
355356
accessMethodName, accessMethodId,
356357
amcanorder, isconstraint);
@@ -395,7 +396,8 @@ DefineIndex(RangeVar *heapRelation,
395396
indexRelationId =
396397
index_create(rel, indexRelationName, indexRelationId,
397398
indexInfo, indexColNames,
398-
accessMethodId, tablespaceId, collationObjectId, classObjectId,
399+
accessMethodId, tablespaceId,
400+
collationObjectId, classObjectId,
399401
coloptions, reloptions, primary,
400402
isconstraint, deferrable, initdeferred,
401403
allowSystemTableMods,

0 commit comments

Comments
 (0)