* arraycontsel -- restriction selectivity for array @>, &&, <@ operators */
| 239 | * arraycontsel -- restriction selectivity for array @>, &&, <@ operators |
| 240 | */ |
| 241 | Datum |
| 242 | arraycontsel(PG_FUNCTION_ARGS) |
| 243 | { |
| 244 | PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0); |
| 245 | Oid operator = PG_GETARG_OID(1); |
| 246 | List *args = (List *) PG_GETARG_POINTER(2); |
| 247 | int varRelid = PG_GETARG_INT32(3); |
| 248 | VariableStatData vardata; |
| 249 | Node *other; |
| 250 | bool varonleft; |
| 251 | Selectivity selec; |
| 252 | Oid element_typeid; |
| 253 | |
| 254 | /* |
| 255 | * If expression is not (variable op something) or (something op |
| 256 | * variable), then punt and return a default estimate. |
| 257 | */ |
| 258 | if (!get_restriction_variable(root, args, varRelid, |
| 259 | &vardata, &other, &varonleft)) |
| 260 | PG_RETURN_FLOAT8(DEFAULT_SEL(operator)); |
| 261 | |
| 262 | /* |
| 263 | * Can't do anything useful if the something is not a constant, either. |
| 264 | */ |
| 265 | if (!IsA(other, Const)) |
| 266 | { |
| 267 | ReleaseVariableStats(vardata); |
| 268 | PG_RETURN_FLOAT8(DEFAULT_SEL(operator)); |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * The "&&", "@>" and "<@" operators are strict, so we can cope with a |
| 273 | * NULL constant right away. |
| 274 | */ |
| 275 | if (((Const *) other)->constisnull) |
| 276 | { |
| 277 | ReleaseVariableStats(vardata); |
| 278 | PG_RETURN_FLOAT8(0.0); |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * If var is on the right, commute the operator, so that we can assume the |
| 283 | * var is on the left in what follows. |
| 284 | */ |
| 285 | if (!varonleft) |
| 286 | { |
| 287 | if (operator == OID_ARRAY_CONTAINS_OP) |
| 288 | operator = OID_ARRAY_CONTAINED_OP; |
| 289 | else if (operator == OID_ARRAY_CONTAINED_OP) |
| 290 | operator = OID_ARRAY_CONTAINS_OP; |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | * OK, there's a Var and a Const we're dealing with here. We need the |
| 295 | * Const to be an array with same element type as column, else we can't do |
| 296 | * anything useful. (Such cases will likely fail at runtime, but here |
| 297 | * we'd rather just return a default estimate.) |
| 298 | */ |
nothing calls this directly
no test coverage detected