From 352998fa316e16c07bfec84a0b297ccb6aee7198 Mon Sep 17 00:00:00 2001 From: jingtaoye35 <1255153887@qq.com> Date: Fri, 15 Sep 2023 04:43:48 +0000 Subject: [PATCH] add _enable_values_table_folding config param --- src/share/parameter/ob_parameter_seed.ipp | 3 +++ src/sql/plan_cache/ob_plan_cache.cpp | 14 +++++++++++--- src/sql/plan_cache/ob_plan_cache.h | 3 ++- .../plan_cache/ob_values_table_compression.cpp | 16 +++++++++------- .../mysql/all_virtual_sys_parameter_stat.result | 1 + 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/share/parameter/ob_parameter_seed.ipp b/src/share/parameter/ob_parameter_seed.ipp index 307c03779..6c60850d5 100755 --- a/src/share/parameter/ob_parameter_seed.ipp +++ b/src/share/parameter/ob_parameter_seed.ipp @@ -268,6 +268,9 @@ DEF_INT(_max_malloc_sample_interval, OB_CLUSTER_PARAMETER, "256", "[1, 10000]", "which is not less than _min_malloc_sample_interval. " "1 means to sample all malloc, Range: [1, 10000]", ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE)); +DEF_BOOL(_enable_values_table_folding, OB_CLUSTER_PARAMETER, "True", + "whether enable values statement folds self params", + ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE)); //// tenant config DEF_TIME_WITH_CHECKER(max_stale_time_for_weak_consistency, OB_TENANT_PARAMETER, "5s", common::ObConfigStaleTimeChecker, diff --git a/src/sql/plan_cache/ob_plan_cache.cpp b/src/sql/plan_cache/ob_plan_cache.cpp index e7c917019..1da02b03f 100644 --- a/src/sql/plan_cache/ob_plan_cache.cpp +++ b/src/sql/plan_cache/ob_plan_cache.cpp @@ -707,6 +707,7 @@ int ObPlanCache::construct_fast_parser_result(common::ObIAllocator &allocator, bool can_do_batch_insert = false; ObString first_truncated_sql; int64_t batch_count = 0; + bool is_insert_values = false; if (OB_FAIL(ObSqlParameterization::fast_parser(allocator, fp_ctx, raw_sql, @@ -717,7 +718,8 @@ int ObPlanCache::construct_fast_parser_result(common::ObIAllocator &allocator, fp_result, can_do_batch_insert, batch_count, - first_truncated_sql))) { + first_truncated_sql, + is_insert_values))) { LOG_WARN("fail to do insert optimization", K(ret)); } else if (can_do_batch_insert) { if (OB_FAIL(rebuild_raw_params(allocator, @@ -745,7 +747,8 @@ int ObPlanCache::construct_fast_parser_result(common::ObIAllocator &allocator, LOG_DEBUG("print new fp_result.pc_key_.name_", K(fp_result.pc_key_.name_)); } } - } else if (OB_FAIL(ObValuesTableCompression::try_batch_exec_params(allocator, pc_ctx, + } else if (!is_insert_values && + OB_FAIL(ObValuesTableCompression::try_batch_exec_params(allocator, pc_ctx, *pc_ctx.sql_ctx_.session_info_, fp_result))) { LOG_WARN("failed to check fold params valid", K(ret)); } @@ -955,7 +958,8 @@ int ObPlanCache::check_can_do_insert_opt(common::ObIAllocator &allocator, ObFastParserResult &fp_result, bool &can_do_batch, int64_t &batch_count, - ObString &first_truncated_sql) + ObString &first_truncated_sql, + bool &is_insert_values) { int ret = OB_SUCCESS; can_do_batch = false; @@ -1001,6 +1005,10 @@ int ObPlanCache::check_can_do_insert_opt(common::ObIAllocator &allocator, pc_ctx.insert_batch_opt_info_.update_params_count_ = upd_params_count; pc_ctx.insert_batch_opt_info_.sql_delta_length_ = delta_length; } + // if batch_count >= 1, then sql is a insert into .. values ()...; + if (batch_count >= 1) { + is_insert_values = true; + } } if (ret != OB_SUCCESS) { diff --git a/src/sql/plan_cache/ob_plan_cache.h b/src/sql/plan_cache/ob_plan_cache.h index 276262bf9..da9997275 100644 --- a/src/sql/plan_cache/ob_plan_cache.h +++ b/src/sql/plan_cache/ob_plan_cache.h @@ -242,7 +242,8 @@ public: ObFastParserResult &fp_result, bool &can_do_batch, int64_t &batch_count, - ObString &first_truncated_sql); + ObString &first_truncated_sql, + bool &is_insert_values); static int rebuild_raw_params(common::ObIAllocator &allocator, ObPlanCacheCtx &pc_ctx, ObFastParserResult &fp_result, diff --git a/src/sql/plan_cache/ob_values_table_compression.cpp b/src/sql/plan_cache/ob_values_table_compression.cpp index e0fe41109..065117892 100644 --- a/src/sql/plan_cache/ob_values_table_compression.cpp +++ b/src/sql/plan_cache/ob_values_table_compression.cpp @@ -251,14 +251,16 @@ int ObValuesTableCompression::try_batch_exec_params(ObIAllocator &allocator, ObSEArray raw_pos; ObPhysicalPlanCtx *phy_ctx = NULL; uint64_t data_version = 0; - if (OB_FAIL(GET_MIN_DATA_VERSION(session_info.get_effective_tenant_id(), data_version))) { + if (pc_ctx.sql_ctx_.handle_batched_multi_stmt() || + lib::is_oracle_mode() || + session_info.is_inner() || + session_info.get_is_in_retry() || + fp_result.values_tokens_.empty() || + !GCONF._enable_values_table_folding) { + /* do nothing */ + } else if (OB_FAIL(GET_MIN_DATA_VERSION(session_info.get_effective_tenant_id(), data_version))) { LOG_WARN("get tenant data version failed", K(ret), K(session_info.get_effective_tenant_id())); - } else if (pc_ctx.sql_ctx_.handle_batched_multi_stmt() || - lib::is_oracle_mode() || - session_info.is_inner() || - session_info.get_is_in_retry() || - fp_result.values_tokens_.empty() || - data_version < DATA_VERSION_4_2_1_0 || + } else if (data_version < DATA_VERSION_4_2_1_0 || !is_support_compress_values_table(pc_ctx.raw_sql_)) { /* do nothing */ } else if (OB_ISNULL(phy_ctx = pc_ctx.exec_ctx_.get_physical_plan_ctx())) { diff --git a/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/all_virtual_sys_parameter_stat.result b/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/all_virtual_sys_parameter_stat.result index 4488737d5..ed5e3dcfc 100644 --- a/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/all_virtual_sys_parameter_stat.result +++ b/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/all_virtual_sys_parameter_stat.result @@ -289,6 +289,7 @@ _enable_system_tenant_memory_limit _enable_tenant_sql_net_thread _enable_trace_session_leak _enable_transaction_internal_routing +_enable_values_table_folding _endpoint_tenant_mapping _fast_commit_callback_count _follower_snapshot_read_retry_duration