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

Commit0c9d9e8

Browse files
committed
More collations cleanup, from trawling for missed collation assignments.
Mostly cosmetic, though I did find that generateClonedIndexStmt failedto clone the index's collations.
1 parentb23c9fa commit0c9d9e8

File tree

9 files changed

+70
-14
lines changed

9 files changed

+70
-14
lines changed

‎src/backend/bootstrap/bootparse.y

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ boot_index_param:
345345
n->name =$1;
346346
n->expr =NULL;
347347
n->indexcolname =NULL;
348+
n->collation = NIL;
348349
n->opclass = list_make1(makeString($2));
349350
n->ordering = SORTBY_DEFAULT;
350351
n->nulls_ordering = SORTBY_NULLS_DEFAULT;

‎src/backend/nodes/nodeFuncs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,8 @@ bool
30273027
return true;
30283028
if (walker(coldef->raw_default,context))
30293029
return true;
3030+
if (walker(coldef->collClause,context))
3031+
return true;
30303032
/* for now, constraints are ignored */
30313033
}
30323034
break;

‎src/backend/optimizer/util/plancat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
190190
info->rel=rel;
191191
info->ncolumns=ncolumns=index->indnatts;
192192
info->indexkeys= (int*)palloc(sizeof(int)*ncolumns);
193+
info->indexcollations= (Oid*)palloc(sizeof(Oid)*ncolumns);
193194
info->opfamily= (Oid*)palloc(sizeof(Oid)*ncolumns);
194195
info->opcintype= (Oid*)palloc(sizeof(Oid)*ncolumns);
195-
info->indexcollations= (Oid*)palloc(sizeof(Oid)*ncolumns);
196196

197197
for (i=0;i<ncolumns;i++)
198198
{

‎src/backend/parser/parse_relation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ addRangeTableEntryForFunction(ParseState *pstate,
11521152

11531153
/*
11541154
* Use the column definition list to form the alias list and
1155-
* funccoltypes/funccoltypmods lists.
1155+
* funccoltypes/funccoltypmods/funccolcollations lists.
11561156
*/
11571157
foreach(col,coldeflist)
11581158
{

‎src/backend/parser/parse_utilcmd.c

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include"catalog/heap.h"
3434
#include"catalog/index.h"
3535
#include"catalog/namespace.h"
36+
#include"catalog/pg_collation.h"
3637
#include"catalog/pg_constraint.h"
3738
#include"catalog/pg_opclass.h"
3839
#include"catalog/pg_operator.h"
@@ -111,6 +112,7 @@ static void transformOfType(CreateStmtContext *cxt,
111112
staticchar*chooseIndexName(constRangeVar*relation,IndexStmt*index_stmt);
112113
staticIndexStmt*generateClonedIndexStmt(CreateStmtContext*cxt,
113114
Relationparent_index,AttrNumber*attmap);
115+
staticList*get_collation(Oidcollation,Oidactual_datatype);
114116
staticList*get_opclass(Oidopclass,Oidactual_datatype);
115117
staticvoidtransformIndexConstraints(CreateStmtContext*cxt);
116118
staticIndexStmt*transformIndexConstraint(Constraint*constraint,
@@ -904,6 +906,7 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
904906
Form_pg_classidxrelrec;
905907
Form_pg_indexidxrec;
906908
Form_pg_amamrec;
909+
oidvector*indcollation;
907910
oidvector*indclass;
908911
IndexStmt*index;
909912
List*indexprs;
@@ -931,6 +934,12 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
931934
/* Fetch pg_am tuple for source index from relcache entry */
932935
amrec=source_idx->rd_am;
933936

937+
/* Extract indcollation from the pg_index tuple */
938+
datum=SysCacheGetAttr(INDEXRELID,ht_idx,
939+
Anum_pg_index_indcollation,&isnull);
940+
Assert(!isnull);
941+
indcollation= (oidvector*)DatumGetPointer(datum);
942+
934943
/* Extract indclass from the pg_index tuple */
935944
datum=SysCacheGetAttr(INDEXRELID,ht_idx,
936945
Anum_pg_index_indclass,&isnull);
@@ -1094,6 +1103,9 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
10941103
/* Copy the original index column name */
10951104
iparam->indexcolname=pstrdup(NameStr(attrs[keyno]->attname));
10961105

1106+
/* Add the collation name, if non-default */
1107+
iparam->collation=get_collation(indcollation->values[keyno],keycoltype);
1108+
10971109
/* Add the operator class name, if non-default */
10981110
iparam->opclass=get_opclass(indclass->values[keyno],keycoltype);
10991111

@@ -1152,17 +1164,51 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
11521164
}
11531165

11541166
/*
1155-
* get_opclass- fetch name of an index operator class
1167+
* get_collation- fetch qualified name of a collation
1168+
*
1169+
* If collation is InvalidOid or is the default for the given actual_datatype,
1170+
* then the return value is NIL.
1171+
*/
1172+
staticList*
1173+
get_collation(Oidcollation,Oidactual_datatype)
1174+
{
1175+
List*result;
1176+
HeapTupleht_coll;
1177+
Form_pg_collationcoll_rec;
1178+
char*nsp_name;
1179+
char*coll_name;
1180+
1181+
if (!OidIsValid(collation))
1182+
returnNIL;/* easy case */
1183+
if (collation==get_typcollation(actual_datatype))
1184+
returnNIL;/* just let it default */
1185+
1186+
ht_coll=SearchSysCache1(COLLOID,ObjectIdGetDatum(collation));
1187+
if (!HeapTupleIsValid(ht_coll))
1188+
elog(ERROR,"cache lookup failed for collation %u",collation);
1189+
coll_rec= (Form_pg_collation)GETSTRUCT(ht_coll);
1190+
1191+
/* For simplicity, we always schema-qualify the name */
1192+
nsp_name=get_namespace_name(coll_rec->collnamespace);
1193+
coll_name=pstrdup(NameStr(coll_rec->collname));
1194+
result=list_make2(makeString(nsp_name),makeString(coll_name));
1195+
1196+
ReleaseSysCache(ht_coll);
1197+
returnresult;
1198+
}
1199+
1200+
/*
1201+
* get_opclass- fetch qualified name of an index operator class
11561202
*
11571203
* If the opclass is the default for the given actual_datatype, then
11581204
* the return value is NIL.
11591205
*/
11601206
staticList*
11611207
get_opclass(Oidopclass,Oidactual_datatype)
11621208
{
1209+
List*result=NIL;
11631210
HeapTupleht_opc;
11641211
Form_pg_opclassopc_rec;
1165-
List*result=NIL;
11661212

11671213
ht_opc=SearchSysCache1(CLAOID,ObjectIdGetDatum(opclass));
11681214
if (!HeapTupleIsValid(ht_opc))
@@ -1663,6 +1709,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
16631709
iparam->name=pstrdup(key);
16641710
iparam->expr=NULL;
16651711
iparam->indexcolname=NULL;
1712+
iparam->collation=NIL;
16661713
iparam->opclass=NIL;
16671714
iparam->ordering=SORTBY_DEFAULT;
16681715
iparam->nulls_ordering=SORTBY_NULLS_DEFAULT;

‎src/include/nodes/parsenodes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,10 @@ typedef struct SelectStmt
10581058
* can be coerced to the output column type.) Also, if it's not UNION ALL,
10591059
* information about the types' sort/group semantics is provided in the form
10601060
* of a SortGroupClause list (same representation as, eg, DISTINCT).
1061+
* The resolved common column collations are provided too; but note that if
1062+
* it's not UNION ALL, it's okay for a column to not have a common collation,
1063+
* so a member of the colCollations list could be InvalidOid even though the
1064+
* column has a collatable type.
10611065
* ----------------------
10621066
*/
10631067
typedefstructSetOperationStmt

‎src/include/nodes/plannodes.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,11 @@ typedef struct NestLoopParam
508508
*merge join node
509509
*
510510
* The expected ordering of each mergeable column is described by a btree
511-
* opfamily OID, a direction (BTLessStrategyNumber or BTGreaterStrategyNumber)
512-
* and a nulls-first flag.Note that the two sides of each mergeclause may
513-
* be of different datatypes, but they are ordered the same way according to
514-
* the common opfamily. The operator in each mergeclause must be an equality
515-
* operator of the indicated opfamily.
511+
* opfamily OID, acollation OID, adirection (BTLessStrategyNumber or
512+
*BTGreaterStrategyNumber)and a nulls-first flag.Note that the two sides
513+
*of each mergeclause maybe of different datatypes, but they are ordered the
514+
*same way according tothe common opfamily and collation. The operator in
515+
*each mergeclause must be an equalityoperator of the indicated opfamily.
516516
* ----------------
517517
*/
518518
typedefstructMergeJoin

‎src/include/nodes/primnodes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,9 +1047,9 @@ typedef struct CoerceToDomain
10471047
* constraint.This is effectively like a Param, but can be implemented more
10481048
* simply since we need only one replacement value at a time.
10491049
*
1050-
* Note: the typeId/typeMod will be set from the domain's base type, not
1051-
* the domain itself. This is because we shouldn't consider the value to
1052-
* be a member of the domain if we haven't yet checked its constraints.
1050+
* Note: the typeId/typeMod/collation will be set from the domain's base type,
1051+
*notthe domain itself. This is because we shouldn't consider the value
1052+
*tobe a member of the domain if we haven't yet checked its constraints.
10531053
*/
10541054
typedefstructCoerceToDomainValue
10551055
{

‎src/include/nodes/relation.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ typedef struct RelOptInfo
423423
* IndexOptInfo
424424
*Per-index information for planning/optimization
425425
*
426-
*opfamily[], indexkeys[], and opcintype[] each have ncolumns entries.
426+
*indexkeys[], indexcollations[], opfamily[], and opcintype[]
427+
*each have ncolumns entries.
428+
*
427429
*sortopfamily[], reverse_sort[], and nulls_first[] likewise have
428430
*ncolumns entries, if the index is ordered; but if it is unordered,
429431
*those pointers are NULL.
@@ -453,9 +455,9 @@ typedef struct IndexOptInfo
453455

454456
/* index descriptor information */
455457
intncolumns;/* number of columns in index */
456-
Oid*opfamily;/* OIDs of operator families for columns */
457458
int*indexkeys;/* column numbers of index's keys, or 0 */
458459
Oid*indexcollations;/* OIDs of collations of index columns */
460+
Oid*opfamily;/* OIDs of operator families for columns */
459461
Oid*opcintype;/* OIDs of opclass declared input data types */
460462
Oid*sortopfamily;/* OIDs of btree opfamilies, if orderable */
461463
bool*reverse_sort;/* is sort order descending? */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp