MCPcopy Create free account
hub / github.com/apache/cloudberry / transformAExprIn

Function transformAExprIn

src/backend/parser/parse_expr.c:1097–1253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1095}
1096
1097static Node *
1098transformAExprIn(ParseState *pstate, A_Expr *a)
1099{
1100 Node *result = NULL;
1101 Node *lexpr;
1102 List *rexprs;
1103 List *rvars;
1104 List *rnonvars;
1105 bool useOr;
1106 ListCell *l;
1107
1108 /*
1109 * If the operator is <>, combine with AND not OR.
1110 */
1111 if (strcmp(strVal(linitial(a->name)), "<>") == 0)
1112 useOr = false;
1113 else
1114 useOr = true;
1115
1116 /*
1117 * We try to generate a ScalarArrayOpExpr from IN/NOT IN, but this is only
1118 * possible if there is a suitable array type available. If not, we fall
1119 * back to a boolean condition tree with multiple copies of the lefthand
1120 * expression. Also, any IN-list items that contain Vars are handled as
1121 * separate boolean conditions, because that gives the planner more scope
1122 * for optimization on such clauses.
1123 *
1124 * First step: transform all the inputs, and detect whether any contain
1125 * Vars.
1126 */
1127 lexpr = transformExprRecurse(pstate, a->lexpr);
1128 rexprs = rvars = rnonvars = NIL;
1129 foreach(l, (List *) a->rexpr)
1130 {
1131 Node *rexpr = transformExprRecurse(pstate, lfirst(l));
1132
1133 rexprs = lappend(rexprs, rexpr);
1134 if (contain_vars_of_level(rexpr, 0))
1135 rvars = lappend(rvars, rexpr);
1136 else
1137 rnonvars = lappend(rnonvars, rexpr);
1138 }
1139
1140 /*
1141 * ScalarArrayOpExpr is only going to be useful if there's more than one
1142 * non-Var righthand item.
1143 */
1144 if (list_length(rnonvars) > 1)
1145 {
1146 List *allexprs;
1147 Oid scalar_type;
1148 Oid array_type;
1149
1150 /*
1151 * Try to select a common type for the array elements. Note that
1152 * since the LHS' type is first in the list, it will be preferred when
1153 * there is doubt (eg, when all the RHS items are unknown literals).
1154 *

Callers 1

transformExprRecurseFunction · 0.85

Calls 15

transformExprRecurseFunction · 0.85
lappendFunction · 0.85
contain_vars_of_levelFunction · 0.85
list_lengthFunction · 0.85
list_concatFunction · 0.85
select_common_typeFunction · 0.85
verify_common_typeFunction · 0.85
get_array_typeFunction · 0.85
coerce_to_common_typeFunction · 0.85
make_scalar_array_opFunction · 0.85
make_row_comparison_opFunction · 0.85
make_opFunction · 0.85

Tested by

no test coverage detected