Skip to content

Commit 484551a

Browse files
committed
collation support (not finished)
1 parent d98e1af commit 484551a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/pathman.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ void select_range_partitions(const Datum value,
167167
const RangeEntry *ranges,
168168
const int nranges,
169169
const int strategy,
170+
Oid collid,
170171
WrapperNode *result);
171172

172173
/* Examine expression in order to select partitions. */

src/pg_pathman.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ select_range_partitions(const Datum value,
453453
const RangeEntry *ranges,
454454
const int nranges,
455455
const int strategy,
456+
Oid collid,
456457
WrapperNode *result)
457458
{
458459
const RangeEntry *current_re;
@@ -487,9 +488,9 @@ select_range_partitions(const Datum value,
487488

488489
/* Corner cases */
489490
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)));
491492
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)));
493494

494495
if ((cmp_min <= 0 && strategy == BTLessStrategyNumber) ||
495496
(cmp_min < 0 && (strategy == BTLessEqualStrategyNumber ||
@@ -745,8 +746,10 @@ walk_expr_tree(Expr *expr, WalkerContext *context)
745746
* This function determines which partitions should appear in query plan.
746747
*/
747748
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)
750753
{
751754
int strategy;
752755
TypeCacheEntry *tce;
@@ -795,7 +798,20 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
795798

796799
case PT_RANGE:
797800
{
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;
799815

800816
fill_type_cmp_fmgr_info(&cmp_func,
801817
getBaseType(c->consttype),
@@ -806,6 +822,7 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
806822
PrelGetRangesArray(context->prel),
807823
PrelChildrenCount(context->prel),
808824
strategy,
825+
collid,
809826
result); /* output */
810827

811828
result->paramsel = estimate_paramsel_using_prel(prel, strategy);
@@ -893,6 +910,7 @@ search_range_partition_eq(const Datum value,
893910
ranges,
894911
nranges,
895912
BTEqualStrategyNumber,
913+
prel->attcollid,
896914
&result); /* output */
897915

898916
if (result.found_gap)
@@ -1001,6 +1019,7 @@ handle_const(const Const *c, WalkerContext *context)
10011019
PrelGetRangesArray(context->prel),
10021020
PrelChildrenCount(context->prel),
10031021
strategy,
1022+
prel->attcollid,
10041023
result); /* output */
10051024

10061025
result->paramsel = estimate_paramsel_using_prel(prel, strategy);

0 commit comments

Comments
 (0)