Skip to content

Commit

Permalink
[Enhancement] avoid to extract constant expr as common expr in array_…
Browse files Browse the repository at this point in the history
…map (#52541)

Signed-off-by: silverbullet233 <[email protected]>
  • Loading branch information
silverbullet233 authored Nov 4, 2024
1 parent 6e5e594 commit 442f969
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
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)));

0 comments on commit 442f969

Please sign in to comment.