* canonicalize_ec_expression * * This function ensures that the expression exposes the expected type and * collation, so that it will be equal() to other equivalence-class expressions * that it ought to be equal() to. * * The rule for datatypes is that the exposed type should match what it would * be for an input to an operator of the EC's opfamilies; which is usually * the declared input
| 497 | * right answer for a sort key.) |
| 498 | */ |
| 499 | Expr * |
| 500 | canonicalize_ec_expression(Expr *expr, Oid req_type, Oid req_collation) |
| 501 | { |
| 502 | Oid expr_type = exprType((Node *) expr); |
| 503 | |
| 504 | /* |
| 505 | * For a polymorphic-input-type opclass, just keep the same exposed type. |
| 506 | * RECORD opclasses work like polymorphic-type ones for this purpose. |
| 507 | */ |
| 508 | if (IsPolymorphicType(req_type) || req_type == RECORDOID) |
| 509 | req_type = expr_type; |
| 510 | |
| 511 | /* |
| 512 | * No work if the expression exposes the right type/collation already. |
| 513 | */ |
| 514 | if (expr_type != req_type || |
| 515 | exprCollation((Node *) expr) != req_collation) |
| 516 | { |
| 517 | /* |
| 518 | * If we have to change the type of the expression, set typmod to -1, |
| 519 | * since the new type may not have the same typmod interpretation. |
| 520 | * When we only have to change collation, preserve the exposed typmod. |
| 521 | */ |
| 522 | int32 req_typmod; |
| 523 | |
| 524 | if (expr_type != req_type) |
| 525 | req_typmod = -1; |
| 526 | else |
| 527 | req_typmod = exprTypmod((Node *) expr); |
| 528 | |
| 529 | /* |
| 530 | * Use applyRelabelType so that we preserve const-flatness. This is |
| 531 | * important since eval_const_expressions has already been applied. |
| 532 | */ |
| 533 | expr = (Expr *) applyRelabelType((Node *) expr, |
| 534 | req_type, req_typmod, req_collation, |
| 535 | COERCE_IMPLICIT_CAST, -1, false); |
| 536 | } |
| 537 | |
| 538 | return expr; |
| 539 | } |
| 540 | |
| 541 | /* |
| 542 | * add_eq_member - build a new EquivalenceMember and add it to an EC |
no test coverage detected