mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
Improve predtest.c's internal docs, and enhance its functionality a bit.
Commitb08df9cab
left things rather poorly documented as far as the exact semantics of "clause_is_check" mode went. Also, that mode did not really work correctly for predicate_refuted_by; although given the lack of specification as to what it should do, as well as the lack of any actual use-case, that's perhaps not surprising. Rename "clause_is_check" to "weak" proof mode, and provide specifications for what it should do. I defined weak refutation as meaning "truth of A implies non-truth of B", which makes it possible to use the mode in the part of relation_excluded_by_constraints that checks for mutually contradictory WHERE clauses. Fix up several places that did things wrong for that definition. (As far as I can see, these errors would only lead to failure-to-prove, not incorrect claims of proof, making them not serious bugs even aside from the fact that v10 contains no use of this mode. So there seems no need for back-patching.) In addition, teach predicate_refuted_by_recurse that it can use predicate_implied_by_recurse after all when processing a strong NOT-clause, so long as it asks for the correct proof strength. This is an optimization that could have been included in commitb08df9cab
, but wasn't. Also, simplify and generalize the logic that checks for whether nullness of the argument of IS [NOT] NULL would force overall nullness of the predicate or clause. (This results in a change in the partition_prune test's output, as it is now able to prune an all-nulls partition that it did not recognize before.) In passing, in PartConstraintImpliedByRelConstraint, remove bogus conversion of the constraint list to explicit-AND form and then right back again; that accomplished nothing except forcing a useless extra level of recursion inside predicate_implied_by. Discussion: https://postgr.es/m/5983.1520487191@sss.pgh.pa.us
This commit is contained in:
@ -13651,10 +13651,11 @@ ComputePartitionAttrs(Relation rel, List *partParams, AttrNumber *partattrs,
|
||||
|
||||
/*
|
||||
* PartConstraintImpliedByRelConstraint
|
||||
* Does scanrel's existing constraints imply the partition constraint?
|
||||
* Do scanrel's existing constraints imply the partition constraint?
|
||||
*
|
||||
* Existing constraints includes its check constraints and column-level
|
||||
* NOT NULL constraints and partConstraint describes the partition constraint.
|
||||
* "Existing constraints" include its check constraints and column-level
|
||||
* NOT NULL constraints. partConstraint describes the partition constraint,
|
||||
* in implicit-AND form.
|
||||
*/
|
||||
bool
|
||||
PartConstraintImpliedByRelConstraint(Relation scanrel,
|
||||
@ -13724,10 +13725,15 @@ PartConstraintImpliedByRelConstraint(Relation scanrel,
|
||||
make_ands_implicit((Expr *) cexpr));
|
||||
}
|
||||
|
||||
if (existConstraint != NIL)
|
||||
existConstraint = list_make1(make_ands_explicit(existConstraint));
|
||||
|
||||
/* And away we go ... */
|
||||
/*
|
||||
* Try to make the proof. Since we are comparing CHECK constraints, we
|
||||
* need to use weak implication, i.e., we assume existConstraint is
|
||||
* not-false and try to prove the same for partConstraint.
|
||||
*
|
||||
* Note that predicate_implied_by assumes its first argument is known
|
||||
* immutable. That should always be true for partition constraints, so we
|
||||
* don't test it here.
|
||||
*/
|
||||
return predicate_implied_by(partConstraint, existConstraint, true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user