Skip to content

Commit 20fae01

Browse files
committed
handle NULL arrays in handle_arrexpr()
1 parent 9e4b730 commit 20fae01

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/pg_pathman.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,11 +1011,11 @@ handle_arrexpr(const ScalarArrayOpExpr *expr,
10111011

10121012
/* Check if expression tree is a partitioning expression */
10131013
if (!match_expr_to_operand(context->prel_expr, part_expr))
1014-
goto handle_arrexpr_return;
1014+
goto handle_arrexpr_all;
10151015

10161016
/* Check if we can work with this strategy */
10171017
if (strategy == 0)
1018-
goto handle_arrexpr_return;
1018+
goto handle_arrexpr_all;
10191019

10201020
/* Examine the array node */
10211021
switch (nodeTag(array))
@@ -1026,7 +1026,7 @@ handle_arrexpr(const ScalarArrayOpExpr *expr,
10261026

10271027
/* Array is NULL */
10281028
if (c->constisnull)
1029-
goto handle_arrexpr_return;
1029+
goto handle_arrexpr_none;
10301030

10311031
/* Examine array */
10321032
handle_array(DatumGetArrayTypeP(c->constvalue),
@@ -1048,7 +1048,7 @@ handle_arrexpr(const ScalarArrayOpExpr *expr,
10481048
ListCell *lc;
10491049

10501050
if (list_length(arr_expr->elements) == 0)
1051-
goto handle_arrexpr_return;
1051+
goto handle_arrexpr_all;
10521052

10531053
/* Set default ranges for OR | AND */
10541054
ranges = expr->useOr ? NIL : list_make1_irange_full(prel, IR_COMPLETE);
@@ -1068,21 +1068,19 @@ handle_arrexpr(const ScalarArrayOpExpr *expr,
10681068
{
10691069
Const *c = ExtractConst(elem, context);
10701070

1071-
/* Is this an array?.. */
1072-
if (c->consttype != elem_type)
1071+
/* Is this an array?. */
1072+
if (c->consttype != elem_type && !c->constisnull)
10731073
{
1074-
/* Array is NULL */
1075-
if (c->constisnull)
1076-
goto handle_arrexpr_return;
1077-
1078-
/* Examine array */
10791074
handle_array(DatumGetArrayTypeP(c->constvalue),
10801075
expr->inputcollid, strategy,
10811076
expr->useOr, context, &wrap);
10821077
}
10831078
/* ... or a single element? */
1084-
else handle_const(c, expr->inputcollid,
1085-
strategy, context, &wrap);
1079+
else
1080+
{
1081+
handle_const(c, expr->inputcollid,
1082+
strategy, context, &wrap);
1083+
}
10861084

10871085
/* Should we use OR | AND? */
10881086
ranges = expr->useOr ?
@@ -1097,7 +1095,7 @@ handle_arrexpr(const ScalarArrayOpExpr *expr,
10971095
{
10981096
/* We can't say anything if PARAMs + ANY */
10991097
if (expr->useOr)
1100-
goto handle_arrexpr_return;
1098+
goto handle_arrexpr_all;
11011099

11021100
/* Recheck condition on a narrowed set of partitions */
11031101
ranges = irange_list_set_lossiness(ranges, IR_LOSSY);
@@ -1116,12 +1114,23 @@ handle_arrexpr(const ScalarArrayOpExpr *expr,
11161114
break;
11171115
}
11181116

1119-
handle_arrexpr_return:
1117+
handle_arrexpr_all:
11201118
result->rangeset = list_make1_irange_full(prel, IR_LOSSY);
11211119
result->paramsel = estimate_paramsel_using_prel(prel, strategy);
11221120

11231121
/* Save expression */
11241122
result->orig = (const Node *) expr;
1123+
1124+
return;
1125+
1126+
handle_arrexpr_none:
1127+
result->rangeset = NIL;
1128+
result->paramsel = 0.0;
1129+
1130+
/* Save expression */
1131+
result->orig = (const Node *) expr;
1132+
1133+
return;
11251134
}
11261135

11271136
/* Operator expression handler */

0 commit comments

Comments
 (0)