@@ -453,6 +453,7 @@ select_range_partitions(const Datum value,
453
453
const RangeEntry * ranges ,
454
454
const int nranges ,
455
455
const int strategy ,
456
+ Oid collid ,
456
457
WrapperNode * result )
457
458
{
458
459
const RangeEntry * current_re ;
@@ -487,9 +488,9 @@ select_range_partitions(const Datum value,
487
488
488
489
/* Corner cases */
489
490
cmp_min = IsInfinite (& ranges [startidx ].min ) ?
490
- 1 : DatumGetInt32 (FunctionCall2 (cmp_func , value , BoundGetValue (& ranges [startidx ].min )));
491
+ 1 : DatumGetInt32 (FunctionCall2Coll (cmp_func , collid , value , BoundGetValue (& ranges [startidx ].min )));
491
492
cmp_max = IsInfinite (& ranges [endidx ].max ) ?
492
- -1 : DatumGetInt32 (FunctionCall2 (cmp_func , value , BoundGetValue (& ranges [endidx ].max )));
493
+ -1 : DatumGetInt32 (FunctionCall2Coll (cmp_func , collid , value , BoundGetValue (& ranges [endidx ].max )));
493
494
494
495
if ((cmp_min <= 0 && strategy == BTLessStrategyNumber ) ||
495
496
(cmp_min < 0 && (strategy == BTLessEqualStrategyNumber ||
@@ -745,8 +746,10 @@ walk_expr_tree(Expr *expr, WalkerContext *context)
745
746
* This function determines which partitions should appear in query plan.
746
747
*/
747
748
static void
748
- handle_binary_opexpr (WalkerContext * context , WrapperNode * result ,
749
- const Node * varnode , const Const * c )
749
+ handle_binary_opexpr (WalkerContext * context ,
750
+ WrapperNode * result ,
751
+ const Node * varnode ,
752
+ const Const * c )
750
753
{
751
754
int strategy ;
752
755
TypeCacheEntry * tce ;
@@ -795,7 +798,20 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
795
798
796
799
case PT_RANGE :
797
800
{
798
- FmgrInfo cmp_func ;
801
+ FmgrInfo cmp_func ;
802
+ Oid collid ;
803
+
804
+ /*
805
+ * If operator collation is different from default attribute
806
+ * collation then we cannot guarantee that we return correct
807
+ * partitions. So in this case we just return all of them
808
+ */
809
+ if (expr -> opcollid != prel -> attcollid && strategy != BTEqualStrategyNumber )
810
+ goto binary_opexpr_return ;
811
+
812
+ collid = OidIsValid (expr -> opcollid ) ?
813
+ expr -> opcollid :
814
+ prel -> attcollid ;
799
815
800
816
fill_type_cmp_fmgr_info (& cmp_func ,
801
817
getBaseType (c -> consttype ),
@@ -806,6 +822,7 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
806
822
PrelGetRangesArray (context -> prel ),
807
823
PrelChildrenCount (context -> prel ),
808
824
strategy ,
825
+ collid ,
809
826
result ); /* output */
810
827
811
828
result -> paramsel = estimate_paramsel_using_prel (prel , strategy );
@@ -893,6 +910,7 @@ search_range_partition_eq(const Datum value,
893
910
ranges ,
894
911
nranges ,
895
912
BTEqualStrategyNumber ,
913
+ prel -> attcollid ,
896
914
& result ); /* output */
897
915
898
916
if (result .found_gap )
@@ -1001,6 +1019,7 @@ handle_const(const Const *c, WalkerContext *context)
1001
1019
PrelGetRangesArray (context -> prel ),
1002
1020
PrelChildrenCount (context -> prel ),
1003
1021
strategy ,
1022
+ prel -> attcollid ,
1004
1023
result ); /* output */
1005
1024
1006
1025
result -> paramsel = estimate_paramsel_using_prel (prel , strategy );
0 commit comments