From 442f969e4ba3faf0f64bd5c017c86103b8bdb2ce Mon Sep 17 00:00:00 2001 From: eyes_on_me Date: Mon, 4 Nov 2024 10:09:20 +0800 Subject: [PATCH] [Enhancement] avoid to extract constant expr as common expr in array_map (#52541) Signed-off-by: silverbullet233 <3675229+silverbullet233@users.noreply.github.com> --- be/src/exprs/lambda_function.cpp | 2 +- test/sql/test_array_fn/R/test_array_map_2 | 7 +++++++ test/sql/test_array_fn/T/test_array_map_2 | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/be/src/exprs/lambda_function.cpp b/be/src/exprs/lambda_function.cpp index 16100d59497e7..943296eea6cfb 100644 --- a/be/src/exprs/lambda_function.cpp +++ b/be/src/exprs/lambda_function.cpp @@ -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; } diff --git a/test/sql/test_array_fn/R/test_array_map_2 b/test/sql/test_array_fn/R/test_array_map_2 index 8c1b56c718ea5..ef781a65626a4 100644 --- a/test/sql/test_array_fn/R/test_array_map_2 +++ b/test/sql/test_array_fn/R/test_array_map_2 @@ -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 \ No newline at end of file diff --git a/test/sql/test_array_fn/T/test_array_map_2 b/test/sql/test_array_fn/T/test_array_map_2 index 7543157075b72..4fd398e805d6f 100644 --- a/test/sql/test_array_fn/T/test_array_map_2 +++ b/test/sql/test_array_fn/T/test_array_map_2 @@ -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))); \ No newline at end of file