-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BugFix] fix invalid expression usage #56064
[BugFix] fix invalid expression usage #56064
Conversation
@ZiheLiu could you please review |
regression introduced in StarRocks#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]>
9852011
to
0b14ed1
Compare
be/src/exec/olap_scan_prepare.cpp
Outdated
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks a lot for your contribution.
Should use get_root_expr(expr_context->root())
instead of expr_context->root()
.
Maybe it's better to modify BoxedExpr::root()
as follows and call _exprs[i].root()
instead of expr_context->root()
.
Expr* BoxedExpr::root() const {
if (new_expr_ctx == nullptr) {
return get_root_expr(root_expr);
} else {
return get_root_expr(new_expr_ctx);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use get_root_expr(expr_context->root()) instead of expr_context->root().
ok, will update
Maybe it's better to modify BoxedExpr::root() as follows and call _exprs[i].root() instead of expr_context->root().
i think it will be more error prone, because need to keep in mind about side effects of expr_context
and root()
will return different results before and after expr_context()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it will be more error prone, because need to keep in mind about side effects of expr_context
and root() will return different results before and after expr_context()
Make sense. How about making expr_context()
return std::pair<ExprContext*, Expr*> [ctx, root]
instead of ExprContext*
? Then we can use this new root
and ctx
, which gives a better way to avoid using the new ctx
with the old root
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see at least one place where we need just context, without second part
so as fix i think it have to be enough, but for future refactoring can discuss
Signed-off-by: Aliaksei Dziomin <[email protected]>
a678ab6
to
5795a73
Compare
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[BE Incremental Coverage Report]❌ fail : 3 / 4 (75.00%) file detail
|
@Mergifyio backport branch-3.4 |
✅ Backports have been created
|
Signed-off-by: Aliaksei Dziomin <[email protected]> (cherry picked from commit 0fc6efc)
regression introduced in
#44588
expr_context(...)
create copy of
root_expr
asnew_expr
andnew ExprContext
pupulateExprContext._fn_contexts
and updateVectorizedFunctionCallExpr._fn_context_index
insidenew_expr
after return from function we do call of
get_predicate_value
withnew_expr_ctx
+root_expr
insideroot_expr
we can have incorrectVectorizedFunctionCallExpr._fn_context_index
, because indexes apply for another contextas result later we have errors
for our case
_fn_context_index = 3
and_fn_contexts.size() = 2
after fix we will use proper updated expressions with correct expression context
Why I'm doing:
What I'm doing:
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check:
The feature introduced only from 3.4 version and unavailable in previous releases