Skip to content

Commit

Permalink
[BugFix] fix invalid expression usage
Browse files Browse the repository at this point in the history
regression introduced in
#44588

expr_context(...)
```
        // Copy expr to prevent two ExprContexts from owning the same Expr, which will cause the same Expr to be
        // closed twice.
        // - The ExprContext in the `original _opts.conjunct_ctxs_ptr` will own an Expr and all its children.
        // - The newly created ExprContext here will also own this Expr.
        auto* new_expr = Expr::copy(obj_pool, root_expr);
        new_expr_ctx = obj_pool->add(new ExprContext(new_expr));
        RETURN_IF_ERROR(new_expr_ctx->prepare(state));
        RETURN_IF_ERROR(new_expr_ctx->open(state));
```

create copy of root_expr as new_expr and new ExprContext
pupulate ExprContext._fn_contexts and update VectorizedFunctionCallExpr._fn_context_index inside new_expr

after return from function we do call of get_predicate_value with new_expr_ctx + root_expr
inside root_expr we can have incorrect VectorizedFunctionCallExpr._fn_context_index, because indexes apply for another context

as result later we have errors

    @         0x16c18359 google::LogMessageFatal::~LogMessageFatal()
    @         0x104f7c96 starrocks::ExprContext::fn_context(int)
    @         0x105b4c11 starrocks::VectorizedFunctionCallExpr::evaluate_checked(starrocks::ExprContext*, starrocks::Chunk*)
    @         0x103a737a starrocks::VectorizedCastToStringExpr<(starrocks::LogicalType)51, false>::evaluate_checked(starrocks::ExprContext*, starrocks::Chunk*)

```
    FunctionContext* fn_context(int i) {
        DCHECK_GE(i, 0);
        DCHECK_LT(i, _fn_contexts.size());
        return _fn_contexts[i];
    }
```

for our case _fn_context_index = 3 and _fn_contexts.size() = 2

after fix we will use proper updated expressions with correct expression context

Signed-off-by: Aliaksei Dziomin <[email protected]>
  • Loading branch information
xhumanoid committed Feb 19, 2025
1 parent 1c19057 commit 0b14ed1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions be/src/exec/olap_scan_prepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ requires(!lt_is_date<SlotType>) Status ChunkPredicateBuilder<E, Type>::normalize
ValueType value;
ASSIGN_OR_RETURN(auto* expr_context, _exprs[i].expr_context(_opts.obj_pool, _opts.runtime_state));
bool ok =
get_predicate_value<Negative>(_opts.obj_pool, slot, root_expr, expr_context, &value, &op, &status);
get_predicate_value<Negative>(_opts.obj_pool, slot, expr_context->root(), expr_context, &value, &op, &status);
if (ok && range->add_fixed_values(FILTER_IN, std::set<RangeValueType>{value}).ok()) {
_normalized_exprs[i] = true;
}
Expand Down Expand Up @@ -535,7 +535,7 @@ requires lt_is_date<SlotType> Status ChunkPredicateBuilder<E, Type>::normalize_i
DateValue value{0};
ASSIGN_OR_RETURN(auto* expr_context, _exprs[i].expr_context(_opts.obj_pool, _opts.runtime_state));
bool ok =
get_predicate_value<Negative>(_opts.obj_pool, slot, root_expr, expr_context, &value, &op, &status);
get_predicate_value<Negative>(_opts.obj_pool, slot, expr_context->root(), expr_context, &value, &op, &status);
if (ok && range->add_fixed_values(FILTER_IN, std::set<DateValue>{value}).ok()) {
_normalized_exprs[i] = true;
}
Expand Down Expand Up @@ -568,7 +568,7 @@ Status ChunkPredicateBuilder<E, Type>::normalize_binary_predicate(const SlotDesc
SQLFilterOp op;
ValueType value;
ASSIGN_OR_RETURN(auto* expr_context, _exprs[i].expr_context(_opts.obj_pool, _opts.runtime_state));
bool ok = get_predicate_value<Negative>(_opts.obj_pool, slot, root_expr, expr_context, &value, &op, &status);
bool ok = get_predicate_value<Negative>(_opts.obj_pool, slot, expr_context->root(), expr_context, &value, &op, &status);
if (ok && range->add_range(op, static_cast<RangeValueType>(value)).ok()) {
_normalized_exprs[i] = true;
}
Expand Down Expand Up @@ -772,7 +772,7 @@ Status ChunkPredicateBuilder<E, Type>::normalize_not_in_or_not_equal_predicate(
ValueType value;
ASSIGN_OR_RETURN(auto* expr_context, _exprs[i].expr_context(_opts.obj_pool, _opts.runtime_state));
bool ok =
get_predicate_value<Negative>(_opts.obj_pool, slot, root_expr, expr_context, &value, &op, &status);
get_predicate_value<Negative>(_opts.obj_pool, slot, expr_context->root(), expr_context, &value, &op, &status);
if (ok && range->add_fixed_values(FILTER_NOT_IN, std::set<RangeValueType>{value}).ok()) {
_normalized_exprs[i] = true;
}
Expand Down

0 comments on commit 0b14ed1

Please sign in to comment.