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

Commitcb37c29

Browse files
committed
Fix index matching for operators with mixed collatable/noncollatable inputs.
If an indexable operator for a non-collatable indexed datatype has acollatable right-hand input type, any OpExpr for it will be marked with anonzero inputcollid (since having one collatable input is sufficient tomake that happen). However, an index on a non-collatable column certainlydoesn't have any collation. This caused us to fail to match such operatorsto their indexes, because indxpath.c required an exact match of indexcollation and clause collation. It seems correct to allow a match when theindex is collation-less regardless of the clause's inputcollid: an operatorwith both noncollatable and collatable inputs could perhaps depend on thecollation of the collatable input, but it could hardly expect the index forthe noncollatable input to have that same collation.Per bug #6232 from Pierre Ducroquet. His example is specifically about"hstore ? text" but the problem seems quite generic.
1 parent5e59584 commitcb37c29

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

‎src/backend/optimizer/path/indxpath.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#defineIsBooleanOpfamily(opfamily) \
4242
((opfamily) == BOOL_BTREE_FAM_OID || (opfamily) == BOOL_HASH_FAM_OID)
4343

44+
#defineIndexCollMatchesExprColl(idxcollation,exprcollation) \
45+
((idxcollation) == InvalidOid || (idxcollation) == (exprcollation))
46+
4447
/* Whether to use ScalarArrayOpExpr to build index qualifications */
4548
typedefenum
4649
{
@@ -1181,6 +1184,13 @@ group_clauses_by_indexkey(IndexOptInfo *index,
11811184
* We do not actually do the commuting here, but we check whether a
11821185
* suitable commutator operator is available.
11831186
*
1187+
* If the index has a collation, the clause must have the same collation.
1188+
* For collation-less indexes, we assume it doesn't matter; this is
1189+
* necessary for cases like "hstore ? text", wherein hstore's operators
1190+
* don't care about collation but the clause will get marked with a
1191+
* collation anyway because of the text argument. (This logic is
1192+
* embodied in the macro IndexCollMatchesExprColl.)
1193+
*
11841194
* It is also possible to match RowCompareExpr clauses to indexes (but
11851195
* currently, only btree indexes handle this). In this routine we will
11861196
* report a match if the first column of the row comparison matches the
@@ -1303,7 +1313,7 @@ match_clause_to_indexcol(IndexOptInfo *index,
13031313
bms_is_subset(right_relids,outer_relids)&&
13041314
!contain_volatile_functions(rightop))
13051315
{
1306-
if (idxcollation==expr_coll&&
1316+
if (IndexCollMatchesExprColl(idxcollation,expr_coll)&&
13071317
is_indexable_operator(expr_op,opfamily, true))
13081318
return true;
13091319

@@ -1322,7 +1332,7 @@ match_clause_to_indexcol(IndexOptInfo *index,
13221332
bms_is_subset(left_relids,outer_relids)&&
13231333
!contain_volatile_functions(leftop))
13241334
{
1325-
if (idxcollation==expr_coll&&
1335+
if (IndexCollMatchesExprColl(idxcollation,expr_coll)&&
13261336
is_indexable_operator(expr_op,opfamily, false))
13271337
return true;
13281338

@@ -1398,8 +1408,8 @@ match_rowcompare_to_indexcol(IndexOptInfo *index,
13981408
expr_op=linitial_oid(clause->opnos);
13991409
expr_coll=linitial_oid(clause->inputcollids);
14001410

1401-
/* Collations must match */
1402-
if (expr_coll!=idxcollation)
1411+
/* Collations must match, if relevant */
1412+
if (!IndexCollMatchesExprColl(idxcollation,expr_coll))
14031413
return false;
14041414

14051415
/*
@@ -1571,7 +1581,7 @@ match_clause_to_ordering_op(IndexOptInfo *index,
15711581
/*
15721582
* We can forget the whole thing right away if wrong collation.
15731583
*/
1574-
if (expr_coll!=idxcollation)
1584+
if (!IndexCollMatchesExprColl(idxcollation,expr_coll))
15751585
returnNULL;
15761586

15771587
/*
@@ -1862,7 +1872,7 @@ eclass_matches_any_index(EquivalenceClass *ec, EquivalenceMember *em,
18621872
*/
18631873
if ((index->relam!=BTREE_AM_OID||
18641874
list_member_oid(ec->ec_opfamilies,curFamily))&&
1865-
ec->ec_collation==curCollation&&
1875+
IndexCollMatchesExprColl(curCollation,ec->ec_collation)&&
18661876
match_index_to_operand((Node*)em->em_expr,indexcol,index))
18671877
return true;
18681878
}
@@ -2967,7 +2977,8 @@ expand_indexqual_rowcompare(RestrictInfo *rinfo,
29672977
break;
29682978

29692979
/* Does collation match? */
2970-
if (lfirst_oid(collids_cell)!=index->indexcollations[i])
2980+
if (!IndexCollMatchesExprColl(index->indexcollations[i],
2981+
lfirst_oid(collids_cell)))
29712982
break;
29722983

29732984
/* Add opfamily and datatypes to lists */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp