Skip to content
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

[Enhancement] avoid to extract constant expr as common expr in array_map #52541

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion be/src/exprs/lambda_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Status LambdaFunction::extract_outer_common_exprs(RuntimeState* state, Expr* exp

RETURN_IF_ERROR(extract_outer_common_exprs(state, child, ctx));
// if child is a slotref or a lambda function or a literal, we can't replace it.
if (child->is_slotref() || child->is_lambda_function() || child->is_literal()) {
if (child->is_slotref() || child->is_lambda_function() || child->is_literal() || child->is_constant()) {
continue;
}

Expand Down
7 changes: 7 additions & 0 deletions test/sql/test_array_fn/R/test_array_map_2
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,11 @@ select array_map(arg0 -> array_map(arg1 -> array_map(arg2 -> array_map(arg3 -> a
select array_map(arg0 -> array_map(arg1 -> array_map(arg2 -> array_map(arg3 -> array_map(arg4->array_length(arg2) + arg4, arg3), arg2), arg1), arg0), [[[[[1,2]]]]] );
-- result:
[[[[[2,3]]]]]
-- !result
set @arr=array_generate(1,10000);
-- result:
-- !result
select /*+ SET_VAR(query_mem_limit=104857600)*/array_sum(array_map(x->array_contains(@arr,x), array_generate(1,100000)));
-- result:
10000
-- !result
2 changes: 2 additions & 0 deletions test/sql/test_array_fn/T/test_array_map_2
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ select array_map(arg0 -> array_map(arg1 -> array_map(arg2 -> array_map(arg3 -> a
select array_map(arg0 -> array_map(arg1 -> array_map(arg2 -> array_map(arg3 -> array_length(arg2) + arg3, arg2), arg1), arg0), [[[[1,2]]]]);
select array_map(arg0 -> array_map(arg1 -> array_map(arg2 -> array_map(arg3 -> array_map(arg4->array_length(arg2) + arg4, arg3), arg2), arg1), arg0), [[[[[1,2]]]]] );

set @arr=array_generate(1,10000);
select /*+ SET_VAR(query_mem_limit=104857600)*/array_sum(array_map(x->array_contains(@arr,x), array_generate(1,100000)));
Loading