Extract an Inequality if possible, derived from "less", "greater", "less_equal", and "greater_equal" expressions, possibly disjuncted with an "is_null" Expression. cmp(a, 2) cmp(a, 2) or is_null(a)
| 1168 | // cmp(a, 2) |
| 1169 | // cmp(a, 2) or is_null(a) |
| 1170 | static std::optional<Inequality> ExtractOne(const Expression& guarantee) { |
| 1171 | auto call = guarantee.call(); |
| 1172 | if (!call) return std::nullopt; |
| 1173 | |
| 1174 | if (call->function_name == "or_kleene") { |
| 1175 | // expect the LHS to be a usable field inequality |
| 1176 | auto out = ExtractOneFromComparison(call->arguments[0]); |
| 1177 | if (!out) return std::nullopt; |
| 1178 | |
| 1179 | // expect the RHS to be an is_null expression |
| 1180 | auto call_rhs = call->arguments[1].call(); |
| 1181 | if (!call_rhs) return std::nullopt; |
| 1182 | if (call_rhs->function_name != "is_null") return std::nullopt; |
| 1183 | |
| 1184 | // ... and that it references the same target |
| 1185 | auto target = call_rhs->arguments[0].field_ref(); |
| 1186 | if (!target) return std::nullopt; |
| 1187 | if (*target != out->target) return std::nullopt; |
| 1188 | |
| 1189 | out->nullable = true; |
| 1190 | return out; |
| 1191 | } |
| 1192 | |
| 1193 | // fall back to a simple comparison with no "is_null" |
| 1194 | return ExtractOneFromComparison(guarantee); |
| 1195 | } |
| 1196 | |
| 1197 | static std::optional<Inequality> ExtractOneFromComparison(const Expression& guarantee) { |
| 1198 | auto call = guarantee.call(); |