| 1095 | } |
| 1096 | |
| 1097 | static Node * |
| 1098 | transformAExprIn(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 | * |
no test coverage detected