patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -25,15 +25,16 @@ using namespace oceanbase::common;
using namespace oceanbase::json;
using namespace oceanbase::share::schema;
namespace test {
namespace test
{
static const int64_t BUKET_NUM = 102400;
static const int64_t HIGH_WATER_MARK = 10 * 100 * 1024; // 10 plans
static const int64_t LOW_WATER_MARK = 5 * 100 * 1024; // 5 plans
static const int64_t TEST_PLAN_NUM = 3;
static TestSQL* test_sql = NULL;
static ObPlanCache* plan_cache = NULL;
static ObPlanCacheValue* plan_cache_value = NULL;
static TestSQL *test_sql = NULL;
static ObPlanCache *plan_cache = NULL;
static ObPlanCacheValue *plan_cache_value = NULL;
void init_pcv()
{
@ -44,7 +45,7 @@ void init_pcv()
}
if (NULL == plan_cache) {
plan_cache = new ObPlanCache;
plan_cache->init(BUKET_NUM, test_sql->get_addr(), test_sql->get_part_cache(), OB_SYS_TENANT_ID);
plan_cache->init(BUKET_NUM, test_sql->get_addr(), test_sql->get_part_cache(), OB_SYS_TENANT_ID, NULL);
plan_cache->set_host(test_sql->get_addr());
plan_cache->set_location_cache(test_sql->get_part_cache());
plan_cache->set_mem_limit_pct(20);
@ -53,56 +54,52 @@ void init_pcv()
}
}
class TestPlanCacheValue : public ::testing::Test {
class TestPlanCacheValue : public ::testing::Test
{
public:
TestPlanCacheValue()
{}
virtual ~TestPlanCacheValue()
{}
void SetUp()
{}
void TearDown()
{}
TestPlanCacheValue() {}
virtual ~TestPlanCacheValue() {}
void SetUp() {}
void TearDown() {}
private:
// disallow copy
TestPlanCacheValue(const TestPlanCacheValue& other);
TestPlanCacheValue& operator=(const TestPlanCacheValue& other);
//disallow copy
TestPlanCacheValue(const TestPlanCacheValue &other);
TestPlanCacheValue& operator=(const TestPlanCacheValue &other);
};
void generate_plan(TestSqlCtx& test_sql_ctx, const char* query, ParamStore& params, ObLogPlan*& logical_plan,
ObPhysicalPlan*& phy_plan, const ObSQLSessionInfo& session)
void generate_plan(TestSqlCtx &test_sql_ctx, const char *query,
ParamStore &params, ObLogPlan *&logical_plan,
ObPhysicalPlan *&phy_plan, const ObSQLSessionInfo &session)
{
LOG_INFO("generate_plan!");
ParseResult parse_result;
ObStmt* stmt = NULL;
ObStmt *stmt = NULL;
// parse
//parse
test_sql->do_parse(*test_sql_ctx.allocator_, query, parse_result);
LOG_INFO("tree", "tree", CSJ(ObParserResultPrintWrapper(*(parse_result.result_tree_))));
// replace const expt with ? in syntax tree; get params;
//replace const expt with ? in syntax tree; get params;
SqlInfo not_param_info;
ObMaxConcurrentParam::FixParamStore fixed_param_store(
OB_MALLOC_NORMAL_BLOCK_SIZE, ObWrapperAllocator(test_sql_ctx.allocator_));
ObMaxConcurrentParam::FixParamStore fixed_param_store(OB_MALLOC_NORMAL_BLOCK_SIZE,
ObWrapperAllocator(test_sql_ctx.allocator_));
bool is_transform_outline = false;
ObSqlParameterization::transform_syntax_tree(*test_sql_ctx.allocator_,
session,
NULL,
0,
parse_result.result_tree_,
not_param_info,
params,
NULL,
fixed_param_store,
is_transform_outline);
session,
NULL,
parse_result.result_tree_,
not_param_info,
params,
NULL,
fixed_param_store,
is_transform_outline);
LOG_INFO("tree", "tree trans", CSJ(ObParserResultPrintWrapper(*(parse_result.result_tree_))));
// resolve
//resolve
test_sql->do_resolve(test_sql_ctx, parse_result, stmt, &params);
// logical_plan
//logical_plan
test_sql->generate_logical_plan(test_sql_ctx, &params, stmt, logical_plan);
// physical plan
//physical plan
test_sql->generate_physical_plan(logical_plan, phy_plan);
}
@ -124,9 +121,9 @@ TEST_F(TestPlanCacheValue, basic)
// just empty array to avoid failure while adding plan
ObSEArray<ObPCConstParamInfo, 4> plan_const_param_constraints;
ObSEArray<ObPCConstParamInfo, 4> all_const_param_constraints;
int64_t merged_version = test_sql->get_merged_version();
for (int i = 0; i < TEST_PLAN_NUM; i++) {
sql_ctx[i].schema_guard_ = &(test_sql->get_schema_guard());
sql_ctx[i].merged_version_ = test_sql->get_merged_version();
sql_ctx[i].session_info_ = &(session[i]);
sql_ctx[i].all_plan_const_param_constraints_ = &plan_const_param_constraints;
sql_ctx[i].all_possible_const_param_constraints_ = &all_const_param_constraints;
@ -136,44 +133,41 @@ TEST_F(TestPlanCacheValue, basic)
exec_ctx[i].create_physical_plan_ctx();
exec_ctx[i].set_my_session(&(session[i]));
exec_ctx[i].set_sql_ctx(&sql_ctx[i]);
exec_ctx[i].get_task_executor_ctx()->set_partition_service(&partition_service);
GCTX.par_ser_ = &partition_service;
exec_ctx[i].get_task_executor_ctx()->set_min_cluster_version(CLUSTER_VERSION_1500);
}
ObLogPlan* logical_plan[TEST_PLAN_NUM];
ObPhysicalPlan* phy_plan[TEST_PLAN_NUM];
ObLogPlan *logical_plan[TEST_PLAN_NUM];
ObPhysicalPlan *phy_plan[TEST_PLAN_NUM];
ASSERT_EQ(OB_SUCCESS, ObPreProcessSysVars::init_sys_var());
for (int64_t i = 0; i < TEST_PLAN_NUM; ++i) {
ASSERT_EQ(OB_SUCCESS, session[i].load_default_sys_variable(false, true));
}
// when add generate_plan() , change TEST_PLAN_NUM
generate_plan(test_sql_ctx,
"select /*no_use_px*/ * from t1 where c1 = 1",
exec_ctx[0].get_physical_plan_ctx()->get_param_store_for_update(),
logical_plan[0],
phy_plan[0],
session[0]);
"select /*no_use_px*/ * from t1 where c1 = 1",
exec_ctx[0].get_physical_plan_ctx()->get_param_store_for_update(),
logical_plan[0], phy_plan[0], session[0]);
generate_plan(test_sql_ctx,
"select /*no_use_px*/ * from t1 where c1 = '1'",
exec_ctx[1].get_physical_plan_ctx()->get_param_store_for_update(),
logical_plan[1],
phy_plan[1],
session[1]);
"select /*no_use_px*/ * from t1 where c1 = '1'",
exec_ctx[1].get_physical_plan_ctx()->get_param_store_for_update(),
logical_plan[1], phy_plan[1], session[1]);
generate_plan(test_sql_ctx,
"select /*no_use_px*/ * from t1 where c1=1 and c2=2",
exec_ctx[2].get_physical_plan_ctx()->get_param_store_for_update(),
logical_plan[2],
phy_plan[2],
session[2]);
"select /*no_use_px*/ * from t1 where c1=1 and c2=2",
exec_ctx[2].get_physical_plan_ctx()->get_param_store_for_update(),
logical_plan[2], phy_plan[2], session[2]);
common::ObSEArray<ObTablePartitionInfo*, 4> table_partition_info;
common::ObSEArray<ObTablePartitionInfo *, 4> table_partition_info;
// for (int i = 0; i < TEST_PLAN_NUM; i++) {
// phy_plan[i]->set_plan_id(i);
// }
for (int i = 0; i < TEST_PLAN_NUM; i++) {
table_partition_info.reset();
ASSERT_EQ(OB_SUCCESS, logical_plan[i]->get_global_table_partition_info(table_partition_info));
ASSERT_EQ(OB_SUCCESS, exec_ctx[i].get_sql_ctx()->set_partition_infos(table_partition_info, allocator));
ASSERT_EQ(OB_SUCCESS, exec_ctx[i].get_task_executor_ctx()->set_table_locations(table_partition_info));
ASSERT_EQ(OB_SUCCESS, exec_ctx[i].get_sql_ctx()->set_partition_infos(
table_partition_info,
allocator));
ASSERT_EQ(OB_SUCCESS, exec_ctx[i].get_task_executor_ctx()->set_table_locations(
table_partition_info));
}
ObString sql_0 = ObString::make_string("select /*no_use_px*/ * from t1 where c1 = 1");
@ -190,17 +184,17 @@ TEST_F(TestPlanCacheValue, basic)
pcv_set.create_new_pcv(plan_cache_value);
plan_cache_value->init(&pcv_set, phy_plan[0], pc_ctx_0);
// test reset()
//test reset()
plan_cache_value->reset();
pcv_set.free_pcv(plan_cache_value);
}
} // namespace test
}
int main(int argc, char** argv)
int main(int argc, char **argv)
{
system("rm -rf test_plan_cache_value.log");
::oceanbase::sql::init_sql_factories();
::testing::InitGoogleTest(&argc, argv);
::testing::InitGoogleTest(&argc,argv);
OB_LOGGER.set_log_level("DEBUG");
OB_LOGGER.set_file_name("test_plan_cache_value.log", true);