englefly commented on code in PR #69760:
URL: https://github.com/apache/doris/pull/69760#discussion_r4677849366
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateNotNull.java:
##########
@@ -77,24 +88,42 @@ public List<Rule> buildRules() {
);
}
- private List<Expression> removeGeneratedNotNull(Collection<Expression>
exprs, CascadesContext ctx) {
+ /**
+ * Remove the generated `is not null` predicates, but keep the ones worth
pruning the scan.
+ *
+ * @param filterChild the child plan of the filter which owns the
predicates, the generated
+ * `is not null` predicate can only be kept when the
predicates are evaluated
+ * directly on a scan; empty if the predicates are join
conditions.
+ */
+ private List<Expression> removeGeneratedNotNull(Collection<Expression>
exprs, CascadesContext ctx,
+ Optional<Plan> filterChild) {
// Example: `id > 0 and id is not null and name is not null(generated)`
// predicatesNotContainIsNotNull: `id > 0`
// predicatesNotContainIsNotNull infer nonNullable slots: `id`
// slotsFromIsNotNull: `id`, `name`
// remove `name` (it's generated), remove `id` (because `id > 0`
already contains it)
Set<Expression> predicatesNotContainIsNotNull =
Sets.newLinkedHashSet();
List<Slot> slotsFromIsNotNull = Lists.newArrayList();
+ OlapScan scan = filterChild.filter(OlapScan.class::isInstance)
+ .map(OlapScan.class::cast)
+ .orElse(null);
+ long numNullsThreshold = scan == null ? -1 : getNumNullsThreshold(ctx);
for (Expression expr : exprs) {
- // remove generated `is not null`
- if (!(expr instanceof Not) || !((Not)
expr).isGeneratedIsNotNull()) {
+ // remove generated `is not null`, unless it is worth keeping for
the scan pruning
+ if (expr instanceof Not && ((Not) expr).isGeneratedIsNotNull()) {
Optional<Slot> notNullSlot = TypeUtils.isNotNull(expr);
- if (notNullSlot.isPresent()) {
+ if (notNullSlot.isPresent() && isWorthKeepingForScan(
Review Comment:
Fixed in `ee1c8cc24cc`. The MINMAX implementation can now omit a sole IS NOT
NULL filter when every aggregate reads MIN or MAX of that same underlying
column. The regular scan candidate retains the filter.
The regression reproduced `pushAggOp=NONE` before the fix and selects
`MINMAX` afterward. It also checks explicit filters, projected aliases, the
ordinary scan fallback, and cases where removing the filter would change the
result.
##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -2168,6 +2172,13 @@ public boolean isEnableHboNonStrictMatchingMode() {
@VarAttrDef.VarAttr(name = REWRITE_OR_TO_IN_PREDICATE_THRESHOLD, fuzzy =
true)
private int rewriteOrToInPredicateThreshold = 2;
+ @VarAttrDef.VarAttr(name = KEEP_IS_NOT_NULL_NUM_NULLS_THRESHOLD, fuzzy =
true,
Review Comment:
Fixed in `cb89e5920aa` by adding `needForward = true` to
`keep_is_not_null_num_nulls_threshold`. The FE unit test and a round trip
against the final FE package both verified that the master receives the
follower's values `1` and `-1`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]