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

Commitb310b6e

Browse files
committed
Revise collation derivation method and expression-tree representation.
All expression nodes now have an explicit output-collation field, unlessthey are known to only return a noncollatable data type (such as booleanor record). Also, nodes that can invoke collation-aware functions storea separate field that is the collation value to pass to the function.This avoids confusion that arises when a function has collatable inputsand noncollatable output type, or vice versa.Also, replace the parser's on-the-fly collation assignment method witha post-pass over the completed expression tree. This allows us to usea more complex (and hopefully more nearly spec-compliant) assignmentrule without paying for it in extra storage in every expression node.Fix assorted bugs in the planner's handling of collations by makingcollation one of the defining properties of an EquivalenceClass andby converting CollateExprs into discardable RelabelType nodes duringexpression preprocessing.
1 parent025f4c7 commitb310b6e

File tree

73 files changed

+2341
-1060
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2341
-1060
lines changed

‎src/backend/access/gin/ginutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ initGinState(GinState *state, Relation index)
6161
fmgr_info_copy(&(state->compareFn[i]),
6262
index_getprocinfo(index,i+1,GIN_COMPARE_PROC),
6363
CurrentMemoryContext);
64-
fmgr_info_collation(get_typcollation(index->rd_att->attrs[i]->atttypid),
64+
fmgr_info_set_collation(get_typcollation(index->rd_att->attrs[i]->atttypid),
6565
&(state->compareFn[i]));
6666
fmgr_info_copy(&(state->extractValueFn[i]),
6767
index_getprocinfo(index,i+1,GIN_EXTRACTVALUE_PROC),

‎src/backend/access/index/indexam.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ index_getprocinfo(Relation irel,
872872
procnum,attnum,RelationGetRelationName(irel));
873873

874874
fmgr_info_cxt(procId,locinfo,irel->rd_indexcxt);
875-
fmgr_info_collation(irel->rd_indcollation[attnum-1],locinfo);
875+
fmgr_info_set_collation(irel->rd_indcollation[attnum-1],locinfo);
876876
}
877877

878878
returnlocinfo;

‎src/backend/catalog/dependency.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,9 +1506,9 @@ find_expr_references_walker(Node *node,
15061506
add_object_address(OCLASS_TYPE,param->paramtype,0,
15071507
context->addrs);
15081508
/* and its collation, just as for Consts */
1509-
if (OidIsValid(param->paramcollation)&&
1510-
param->paramcollation!=DEFAULT_COLLATION_OID)
1511-
add_object_address(OCLASS_COLLATION,param->paramcollation,0,
1509+
if (OidIsValid(param->paramcollid)&&
1510+
param->paramcollid!=DEFAULT_COLLATION_OID)
1511+
add_object_address(OCLASS_COLLATION,param->paramcollid,0,
15121512
context->addrs);
15131513
}
15141514
elseif (IsA(node,FuncExpr))
@@ -1535,19 +1535,19 @@ find_expr_references_walker(Node *node,
15351535
context->addrs);
15361536
/* fall through to examine arguments */
15371537
}
1538-
elseif (IsA(node,ScalarArrayOpExpr))
1538+
elseif (IsA(node,NullIfExpr))
15391539
{
1540-
ScalarArrayOpExpr*opexpr= (ScalarArrayOpExpr*)node;
1540+
NullIfExpr*nullifexpr= (NullIfExpr*)node;
15411541

1542-
add_object_address(OCLASS_OPERATOR,opexpr->opno,0,
1542+
add_object_address(OCLASS_OPERATOR,nullifexpr->opno,0,
15431543
context->addrs);
15441544
/* fall through to examine arguments */
15451545
}
1546-
elseif (IsA(node,NullIfExpr))
1546+
elseif (IsA(node,ScalarArrayOpExpr))
15471547
{
1548-
NullIfExpr*nullifexpr= (NullIfExpr*)node;
1548+
ScalarArrayOpExpr*opexpr= (ScalarArrayOpExpr*)node;
15491549

1550-
add_object_address(OCLASS_OPERATOR,nullifexpr->opno,0,
1550+
add_object_address(OCLASS_OPERATOR,opexpr->opno,0,
15511551
context->addrs);
15521552
/* fall through to examine arguments */
15531553
}
@@ -1579,6 +1579,11 @@ find_expr_references_walker(Node *node,
15791579
/* since there is no function dependency, need to depend on type */
15801580
add_object_address(OCLASS_TYPE,relab->resulttype,0,
15811581
context->addrs);
1582+
/* the collation might not be referenced anywhere else, either */
1583+
if (OidIsValid(relab->resultcollid)&&
1584+
relab->resultcollid!=DEFAULT_COLLATION_OID)
1585+
add_object_address(OCLASS_COLLATION,relab->resultcollid,0,
1586+
context->addrs);
15821587
}
15831588
elseif (IsA(node,CoerceViaIO))
15841589
{

‎src/backend/catalog/heap.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include"nodes/nodeFuncs.h"
5959
#include"optimizer/var.h"
6060
#include"parser/parse_coerce.h"
61+
#include"parser/parse_collate.h"
6162
#include"parser/parse_expr.h"
6263
#include"parser/parse_relation.h"
6364
#include"storage/bufmgr.h"
@@ -2387,6 +2388,11 @@ cookDefault(ParseState *pstate,
23872388
errhint("You will need to rewrite or cast the expression.")));
23882389
}
23892390

2391+
/*
2392+
* Finally, take care of collations in the finished expression.
2393+
*/
2394+
assign_expr_collations(pstate,expr);
2395+
23902396
returnexpr;
23912397
}
23922398

@@ -2414,6 +2420,11 @@ cookConstraint(ParseState *pstate,
24142420
*/
24152421
expr=coerce_to_boolean(pstate,expr,"CHECK");
24162422

2423+
/*
2424+
* Take care of collations.
2425+
*/
2426+
assign_expr_collations(pstate,expr);
2427+
24172428
/*
24182429
* Make sure no outside relations are referred to.
24192430
*/

‎src/backend/commands/analyze.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,7 @@ compute_minimal_stats(VacAttrStatsP stats,
19311931

19321932
fmgr_info(mystats->eqfunc,&f_cmpeq);
19331933
/* We always use the default collation for statistics */
1934-
fmgr_info_collation(DEFAULT_COLLATION_OID,&f_cmpeq);
1934+
fmgr_info_set_collation(DEFAULT_COLLATION_OID,&f_cmpeq);
19351935

19361936
for (i=0;i<samplerows;i++)
19371937
{
@@ -2254,7 +2254,7 @@ compute_scalar_stats(VacAttrStatsP stats,
22542254
SelectSortFunction(mystats->ltopr, false,&cmpFn,&cmpFlags);
22552255
fmgr_info(cmpFn,&f_cmpfn);
22562256
/* We always use the default collation for statistics */
2257-
fmgr_info_collation(DEFAULT_COLLATION_OID,&f_cmpfn);
2257+
fmgr_info_set_collation(DEFAULT_COLLATION_OID,&f_cmpfn);
22582258

22592259
/* Initial scan to find sortable values */
22602260
for (i=0;i<samplerows;i++)

‎src/backend/commands/functioncmds.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include"miscadmin.h"
5252
#include"optimizer/var.h"
5353
#include"parser/parse_coerce.h"
54+
#include"parser/parse_collate.h"
5455
#include"parser/parse_expr.h"
5556
#include"parser/parse_func.h"
5657
#include"parser/parse_type.h"
@@ -334,6 +335,7 @@ examine_parameter_list(List *parameters, Oid languageOid,
334335

335336
def=transformExpr(pstate,fp->defexpr);
336337
def=coerce_to_specific_type(pstate,def,toid,"DEFAULT");
338+
assign_expr_collations(pstate,def);
337339

338340
/*
339341
* Make sure no variables are referred to.

‎src/backend/commands/indexcmds.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -883,17 +883,34 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
883883
}
884884

885885
/*
886-
*Collationoverride
886+
*Apply collationoverride if any
887887
*/
888888
if (attribute->collation)
889+
attcollation=get_collation_oid(attribute->collation, false);
890+
891+
/*
892+
* Check we have a collation iff it's a collatable type. The only
893+
* expected failures here are (1) COLLATE applied to a noncollatable
894+
* type, or (2) index expression had an unresolved collation. But
895+
* we might as well code this to be a complete consistency check.
896+
*/
897+
if (type_is_collatable(atttype))
898+
{
899+
if (!OidIsValid(attcollation))
900+
ereport(ERROR,
901+
(errcode(ERRCODE_INDETERMINATE_COLLATION),
902+
errmsg("no collation was derived for the index expression"),
903+
errhint("Use the COLLATE clause to set the collation explicitly.")));
904+
}
905+
else
889906
{
890-
if (!type_is_collatable(atttype))
907+
if (OidIsValid(attcollation))
891908
ereport(ERROR,
892-
(errcode(ERRCODE_SYNTAX_ERROR),
909+
(errcode(ERRCODE_DATATYPE_MISMATCH),
893910
errmsg("collations are not supported by type %s",
894911
format_type_be(atttype))));
895-
attcollation=get_collation_oid(attribute->collation, false);
896912
}
913+
897914
collationOidP[attn]=attcollation;
898915

899916
/*

‎src/backend/commands/prepare.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include"nodes/nodeFuncs.h"
2424
#include"parser/analyze.h"
2525
#include"parser/parse_coerce.h"
26+
#include"parser/parse_collate.h"
2627
#include"parser/parse_expr.h"
2728
#include"parser/parse_type.h"
2829
#include"rewrite/rewriteHandler.h"
@@ -368,6 +369,9 @@ EvaluateParams(PreparedStatement *pstmt, List *params,
368369
format_type_be(expected_type_id)),
369370
errhint("You will need to rewrite or cast the expression.")));
370371

372+
/* Take care of collations in the finished expression. */
373+
assign_expr_collations(pstate,expr);
374+
371375
lfirst(l)=expr;
372376
i++;
373377
}

‎src/backend/commands/tablecmds.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include"optimizer/clauses.h"
5959
#include"parser/parse_clause.h"
6060
#include"parser/parse_coerce.h"
61+
#include"parser/parse_collate.h"
6162
#include"parser/parse_expr.h"
6263
#include"parser/parse_oper.h"
6364
#include"parser/parse_relation.h"
@@ -6598,6 +6599,9 @@ ATPrepAlterColumnType(List **wqueue,
65986599
errmsg("column \"%s\" cannot be cast to type %s",
65996600
colName,format_type_be(targettype))));
66006601

6602+
/* Fix collations after all else */
6603+
assign_expr_collations(pstate,transform);
6604+
66016605
/*
66026606
* Add a work queue item to make ATRewriteTable update the column
66036607
* contents.

‎src/backend/commands/typecmds.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include"optimizer/planner.h"
5555
#include"optimizer/var.h"
5656
#include"parser/parse_coerce.h"
57+
#include"parser/parse_collate.h"
5758
#include"parser/parse_expr.h"
5859
#include"parser/parse_func.h"
5960
#include"parser/parse_type.h"
@@ -2341,6 +2342,7 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
23412342
domVal=makeNode(CoerceToDomainValue);
23422343
domVal->typeId=baseTypeOid;
23432344
domVal->typeMod=typMod;
2345+
domVal->collation=get_typcollation(baseTypeOid);
23442346
domVal->location=-1;/* will be set when/if used */
23452347

23462348
pstate->p_value_substitute= (Node*)domVal;
@@ -2352,6 +2354,11 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
23522354
*/
23532355
expr=coerce_to_boolean(pstate,expr,"CHECK");
23542356

2357+
/*
2358+
* Fix up collation information.
2359+
*/
2360+
assign_expr_collations(pstate,expr);
2361+
23552362
/*
23562363
* Make sure no outside relations are referred to.
23572364
*/

‎src/backend/commands/view.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,22 @@ DefineVirtualRelation(const RangeVar *relation, List *tlist, bool replace)
129129
def->raw_default=NULL;
130130
def->cooked_default=NULL;
131131
def->collClause=NULL;
132+
def->collOid=exprCollation((Node*)tle->expr);
132133
/*
133-
*XXX Temporary kluge to make regression tests pass. We should
134-
*be able to trust the result of exprCollation more than this.
134+
*It's possible that the column is of a collatable type but the
135+
*collation could not be resolved, so double-check.
135136
*/
136137
if (type_is_collatable(exprType((Node*)tle->expr)))
137-
def->collOid=exprCollation((Node*)tle->expr);
138+
{
139+
if (!OidIsValid(def->collOid))
140+
ereport(ERROR,
141+
(errcode(ERRCODE_INDETERMINATE_COLLATION),
142+
errmsg("no collation was derived for view column \"%s\"",
143+
def->colname),
144+
errhint("Use the COLLATE clause to set the collation explicitly.")));
145+
}
138146
else
139-
def->collOid=InvalidOid;
147+
Assert(!OidIsValid(def->collOid));
140148
def->constraints=NIL;
141149

142150
attrList=lappend(attrList,def);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp