patch 4.0
This commit is contained in:
@ -22,7 +22,9 @@ using namespace oceanbase::common;
|
||||
using namespace oceanbase::json;
|
||||
using namespace oceanbase::share::schema;
|
||||
|
||||
namespace test {
|
||||
|
||||
namespace test
|
||||
{
|
||||
static int MAX_THREAD_COUNT = 1;
|
||||
static int LOOP_PER_CASE = 10;
|
||||
static bool PREPARE_PLAN_CACHE = false;
|
||||
@ -35,10 +37,10 @@ static bool OUTPUT_PHY_PLAN = false;
|
||||
static const int64_t BUKET_NUM = 102400;
|
||||
static const int64_t MAX_FILE_NAME_LEN = 1024;
|
||||
static const int64_t HIGH_WATER_MARK = 500 * 1024; // 10 plans
|
||||
static const int64_t LOW_WATER_MARK = 500 * 1024; // 5 plans
|
||||
static const int64_t LOW_WATER_MARK = 500 * 1024; // 5 plans
|
||||
|
||||
static TestSQL* test_sql = NULL;
|
||||
static ObPlanCache* plan_cache = NULL;
|
||||
static TestSQL *test_sql = NULL;
|
||||
static ObPlanCache *plan_cache = NULL;
|
||||
|
||||
void init_pc()
|
||||
{
|
||||
@ -54,26 +56,22 @@ void init_pc()
|
||||
}
|
||||
}
|
||||
|
||||
class TestPlanCache : public ::testing::Test {
|
||||
class TestPlanCache : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
TestPlanCache()
|
||||
{}
|
||||
virtual ~TestPlanCache()
|
||||
{}
|
||||
void SetUp()
|
||||
{}
|
||||
void TearDown()
|
||||
{}
|
||||
|
||||
TestPlanCache() {}
|
||||
virtual ~TestPlanCache() {}
|
||||
void SetUp() {}
|
||||
void TearDown() {}
|
||||
private:
|
||||
// disallow copy
|
||||
TestPlanCache(const TestPlanCache& other);
|
||||
TestPlanCache& operator=(const TestPlanCache& other);
|
||||
TestPlanCache(const TestPlanCache &other);
|
||||
TestPlanCache& operator=(const TestPlanCache &other);
|
||||
};
|
||||
|
||||
void do_operation(const char* query, std::ofstream& of_result)
|
||||
void do_operation(const char *query, std::ofstream &of_result)
|
||||
{
|
||||
of_result << "*************** Case Start" << test_sql->next_case_id() << " ***************" << std::endl;
|
||||
of_result << "*************** Case Start"<< test_sql->next_case_id() << " ***************" << std::endl;
|
||||
of_result << std::endl;
|
||||
of_result << "SQL: " << query << std::endl;
|
||||
of_result << std::endl;
|
||||
@ -84,9 +82,9 @@ void do_operation(const char* query, std::ofstream& of_result)
|
||||
ObLogPlanFactory log_plan_factory(allocator);
|
||||
ObExecContext exec_ctx;
|
||||
ParseResult parse_result;
|
||||
ObStmt* stmt = NULL;
|
||||
ObLogPlan* logical_plan = NULL;
|
||||
ObPhysicalPlan* phy_plan = NULL;
|
||||
ObStmt *stmt = NULL;
|
||||
ObLogPlan *logical_plan = NULL;
|
||||
ObPhysicalPlan *phy_plan = NULL;
|
||||
|
||||
int64_t time_1 = 0;
|
||||
int64_t time_2 = 0;
|
||||
@ -106,14 +104,19 @@ void do_operation(const char* query, std::ofstream& of_result)
|
||||
int ret = OB_SUCCESS;
|
||||
ObSQLSessionInfo session;
|
||||
ObSqlCtx context;
|
||||
// context.schema_manager_ = test_sql->get_schema_manager();
|
||||
//context.schema_manager_ = test_sql->get_schema_manager();
|
||||
context.schema_guard_ = &(test_sql->get_schema_guard());
|
||||
// test error
|
||||
//test error
|
||||
ObPlanCacheKey key;
|
||||
exec_ctx.reset();
|
||||
exec_ctx.get_task_executor_ctx()->set_min_cluster_version(CLUSTER_VERSION_1500);
|
||||
context.session_info_ = &session;
|
||||
ret = plan_cache->get_plan(allocator, context, ObString::make_string(query), exec_ctx, phy_plan, key);
|
||||
ret = plan_cache->get_plan(allocator,
|
||||
context,
|
||||
ObString::make_string(query),
|
||||
exec_ctx,
|
||||
phy_plan,
|
||||
key);
|
||||
|
||||
TestSqlCtx test_sql_ctx;
|
||||
test_sql_ctx.allocator_ = &allocator;
|
||||
@ -129,10 +132,7 @@ void do_operation(const char* query, std::ofstream& of_result)
|
||||
// resolve
|
||||
ret = test_sql->do_resolve(test_sql_ctx, parse_result, stmt, ¶ms);
|
||||
EXPECT_EQ(OB_SUCCESS, ret);
|
||||
SQL_PC_LOG(INFO,
|
||||
"after do_resolve",
|
||||
"parse_result.result_tree_",
|
||||
CSJ(ObParserResultPrintWrapper(*parse_result.result_tree_)));
|
||||
SQL_PC_LOG(INFO, "after do_resolve","parse_result.result_tree_", CSJ(ObParserResultPrintWrapper(*parse_result.result_tree_)));
|
||||
time_4 = TestSQL::get_usec();
|
||||
// logical plan
|
||||
test_sql->generate_logical_plan(test_sql_ctx, ¶ms, stmt, logical_plan);
|
||||
@ -147,41 +147,44 @@ void do_operation(const char* query, std::ofstream& of_result)
|
||||
test_sql->generate_physical_plan(logical_plan, phy_plan);
|
||||
phy_plan->set_plan_id(plan_cache->allocate_plan_id());
|
||||
time_6 = TestSQL::get_usec();
|
||||
SQL_PC_LOG(
|
||||
INFO, "phy_plan size", K(phy_plan->get_mem_size()), K(sizeof(ObPhysicalPlan)) /*K(phy_plan->total_mem_size_)*/);
|
||||
// add_plan error
|
||||
ret = plan_cache->add_plan(key, ObString::make_string(query), NULL, logical_plan->get_table_partition_info());
|
||||
SQL_PC_LOG(INFO, "phy_plan size", K(phy_plan->get_mem_size()), K(sizeof(ObPhysicalPlan))/*K(phy_plan->total_mem_size_)*/);
|
||||
//add_plan error
|
||||
ret = plan_cache->add_plan(key,
|
||||
ObString::make_string(query),
|
||||
NULL,
|
||||
logical_plan->get_table_partition_info());
|
||||
EXPECT_TRUE(OB_FAIL(ret));
|
||||
|
||||
ret = plan_cache->add_plan(key, ObString::make_string(query), phy_plan, logical_plan->get_table_partition_info());
|
||||
EXPECT_TRUE(OB_SUCCESS == ret || OB_SQL_PC_PLAN_DUPLICATE == ret || OB_NOT_SUPPORTED == ret ||
|
||||
OB_REACH_MEMORY_LIMIT == ret);
|
||||
ret = plan_cache->add_plan(key,
|
||||
ObString::make_string(query),
|
||||
phy_plan,
|
||||
logical_plan->get_table_partition_info());
|
||||
EXPECT_TRUE(OB_SUCCESS == ret
|
||||
|| OB_SQL_PC_PLAN_DUPLICATE == ret
|
||||
|| OB_NOT_SUPPORTED == ret
|
||||
|| OB_REACH_MEMORY_LIMIT == ret);
|
||||
time_7 = TestSQL::get_usec();
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
SQL_PC_LOG(WARN, "failed to add plan to plan cache", K(ret));
|
||||
} else {
|
||||
SQL_PC_LOG(INFO, "succeed to add physical plan", K(ret));
|
||||
SQL_PC_LOG(INFO,
|
||||
"memory usage",
|
||||
"mem used",
|
||||
plan_cache->get_mem_used(),
|
||||
"hwm",
|
||||
plan_cache->get_mem_hwm(),
|
||||
"lwm",
|
||||
plan_cache->get_mem_lwm());
|
||||
SQL_PC_LOG(INFO, "memory usage", "mem used", plan_cache->get_mem_used(),
|
||||
"hwm", plan_cache->get_mem_hwm(),
|
||||
"lwm", plan_cache->get_mem_lwm());
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
SQL_PC_LOG(WARN, "failed to add plan statistic to plan cache", K(ret));
|
||||
}
|
||||
ret = plan_cache->remove_plan_stat_entry(phy_plan->get_plan_id());
|
||||
EXPECT_TRUE(OB_SUCC(ret));
|
||||
ret = plan_cache->add_plan_stat(test_sql->get_database_id(), ObString::make_string(query), phy_plan);
|
||||
ret = plan_cache->add_plan_stat(test_sql->get_database_id(), ObString::make_string(query),
|
||||
phy_plan);
|
||||
EXPECT_TRUE(OB_SUCC(ret));
|
||||
}
|
||||
} else { // get plan from plan cache success
|
||||
} else {//get plan from plan cache success
|
||||
SQL_PC_LOG(INFO, "get plan from pc", K(*phy_plan), "ref_count", phy_plan->get_ref_count());
|
||||
// plan_id->stat may_be erase by other thread
|
||||
//plan_id->stat may_be erase by other thread
|
||||
plan_cache->update_plan_stat(phy_plan->get_plan_id(), 100 * 1000);
|
||||
|
||||
ObPlanStat plan_stat;
|
||||
@ -197,11 +200,11 @@ void do_operation(const char* query, std::ofstream& of_result)
|
||||
}
|
||||
time_8 = TestSQL::get_usec();
|
||||
ObCacheObjectFactory::free(phy_plan);
|
||||
// ObPhysicalPlan::free(phy_plan);
|
||||
//ObPhysicalPlan::free(phy_plan);
|
||||
time_9 = TestSQL::get_usec();
|
||||
|
||||
if (OUTPUT_EXEC_TIME) {
|
||||
// of_result << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
|
||||
//of_result << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
|
||||
of_result << "parse: " << time_2 - time_1 << std::endl;
|
||||
of_result << "pc_get: " << time_3 - time_2 << std::endl;
|
||||
if (time_4 != 0) {
|
||||
@ -211,19 +214,19 @@ void do_operation(const char* query, std::ofstream& of_result)
|
||||
of_result << "pc_add: " << time_7 - time_6 << std::endl;
|
||||
}
|
||||
of_result << "plan_free: " << time_9 - time_8 << std::endl;
|
||||
// of_result << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
|
||||
//of_result << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
|
||||
}
|
||||
|
||||
of_result << "*************** Case END ************** " << std::endl;
|
||||
of_result << "*************** Case END" << test_sql->get_case_id() << " ***************" << std::endl;
|
||||
of_result << "*************** Case END"<< test_sql->get_case_id() << " ***************" << std::endl;
|
||||
of_result << std::endl;
|
||||
}
|
||||
|
||||
void test_plan_cache(obsys::CThread* thread)
|
||||
void test_plan_cache(obsys::CThread *thread)
|
||||
{
|
||||
const char* test_file = "test_plan_cache.sql";
|
||||
const char* result_file = "test_plan_cache.result";
|
||||
const char* tmp_file = "test_plan_cache.temp";
|
||||
const char *test_file = "test_plan_cache.sql";
|
||||
const char *result_file = "test_plan_cache.result";
|
||||
const char *tmp_file = "test_plan_cache.temp";
|
||||
if (NULL != thread) {
|
||||
char temp_buffer[MAX_FILE_NAME_LEN];
|
||||
sprintf(temp_buffer, "test_plan_cache.temp.%d", thread->getpid());
|
||||
@ -237,17 +240,14 @@ void test_plan_cache(obsys::CThread* thread)
|
||||
std::string total_line;
|
||||
while (std::getline(if_tests, line)) {
|
||||
// allow human readable formatting
|
||||
if (line.size() <= 0)
|
||||
continue;
|
||||
if (line.size() <= 0) continue;
|
||||
std::size_t begin = line.find_first_not_of('\t');
|
||||
if (line.at(begin) == '#')
|
||||
continue;
|
||||
if (line.at(begin) == '#') continue;
|
||||
std::size_t end = line.find_last_not_of('\t');
|
||||
std::string exact_line = line.substr(begin, end - begin + 1);
|
||||
total_line += exact_line;
|
||||
total_line += " ";
|
||||
if (exact_line.at(exact_line.length() - 1) != ';')
|
||||
continue;
|
||||
if (exact_line.at(exact_line.length() - 1) != ';') continue;
|
||||
else {
|
||||
do_operation(total_line.c_str(), of_result);
|
||||
total_line = "";
|
||||
@ -271,38 +271,39 @@ void test_plan_cache(obsys::CThread* thread)
|
||||
void alter_schema_mgr_version()
|
||||
{
|
||||
// schema mgr's version
|
||||
// ObSchemaManager *schema_mgr = test_sql->get_schema_manager();
|
||||
// int64_t schema_version = schema_mgr->get_schema_version();
|
||||
// schema_mgr->set_schema_version(schema_version + 1);
|
||||
//ObSchemaManager *schema_mgr = test_sql->get_schema_manager();
|
||||
//int64_t schema_version = schema_mgr->get_schema_version();
|
||||
//schema_mgr->set_schema_version(schema_version + 1);
|
||||
}
|
||||
|
||||
void alter_table_schema_version()
|
||||
{
|
||||
// schema mgr's version
|
||||
ObSchemaGetterGuard& schema_guard = test_sql->get_schema_guard();
|
||||
ObSchemaGetterGuard &schema_guard = test_sql->get_schema_guard();
|
||||
// table's version; table t1's id is 1
|
||||
int64_t tid = combine_id(OB_SYS_TENANT_ID, 50000);
|
||||
const ObTableSchema* table_schema = NULL;
|
||||
const ObTableSchema *table_schema = NULL;
|
||||
OK(schema_guard.get_table_schema(tid, table_schema));
|
||||
ObTableSchema* table_schema1 = const_cast<ObTableSchema*>(table_schema);
|
||||
ObTableSchema *table_schema1 = const_cast<ObTableSchema *>(table_schema);
|
||||
OK(test_sql->add_table_schema(*table_schema1));
|
||||
// if (table_schema) {
|
||||
//if (table_schema) {
|
||||
// int64_t schema_version = table_schema->get_schema_version();
|
||||
// table_schema->set_schema_version(schema_version + 1);
|
||||
//}
|
||||
}
|
||||
|
||||
class PlanCacheRunnable : public share::ObThreadPool {
|
||||
class PlanCacheRunnable : public share::ObThreadPool
|
||||
{
|
||||
public:
|
||||
void run1()
|
||||
{
|
||||
UNUSED(arg);
|
||||
// TestPlanCache *test_pc = reinterpret_cast<TestPlanCache *>(arg);
|
||||
//TestPlanCache *test_pc = reinterpret_cast<TestPlanCache *>(arg);
|
||||
LOG_INFO("start thread", K(thread));
|
||||
|
||||
// alter schema
|
||||
if (WITH_SCHEMA_ALTER) {
|
||||
// alter_schema_mgr_version();
|
||||
//alter_schema_mgr_version();
|
||||
alter_table_schema_version();
|
||||
}
|
||||
int64_t count = LOOP_PER_CASE;
|
||||
@ -359,56 +360,56 @@ TEST_F(TestPlanCache, basic)
|
||||
plan_cache->dec_ref_count();
|
||||
|
||||
time_2 = ::test::TestSQL::get_usec();
|
||||
std::cout << "total time: " << time_2 - time_1 << std::endl;
|
||||
std::cout<<"total time: "<<time_2 - time_1<<std::endl;
|
||||
}
|
||||
}
|
||||
} // namespace test
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::oceanbase::sql::init_sql_factories();
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::InitGoogleTest(&argc,argv);
|
||||
|
||||
int c = 0;
|
||||
while (-1 != (c = getopt(argc, argv, "t::n::pl::oev012"))) {
|
||||
while(-1 != (c = getopt(argc, argv, "t::n::pl::oev012"))) {
|
||||
switch (c) {
|
||||
case 't':
|
||||
if (NULL != optarg) {
|
||||
test::MAX_THREAD_COUNT = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (NULL != optarg) {
|
||||
test::LOOP_PER_CASE = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
test::PREPARE_PLAN_CACHE = true;
|
||||
break;
|
||||
case 'l':
|
||||
if (NULL != optarg) {
|
||||
OB_LOGGER.set_log_level(optarg);
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
test::WITH_SCHEMA_ALTER = true;
|
||||
break;
|
||||
case 'e':
|
||||
test::WITH_CACHE_EVICT = true;
|
||||
break;
|
||||
case 'v':
|
||||
test::WITH_PLAN_VERIFY = true;
|
||||
break;
|
||||
case '0':
|
||||
test::OUTPUT_EXEC_TIME = true;
|
||||
break;
|
||||
case '1':
|
||||
test::OUTPUT_LOGIC_PLAN = true;
|
||||
break;
|
||||
case '2':
|
||||
test::OUTPUT_PHY_PLAN = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case 't':
|
||||
if (NULL != optarg) {
|
||||
test::MAX_THREAD_COUNT = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (NULL != optarg) {
|
||||
test::LOOP_PER_CASE = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
test::PREPARE_PLAN_CACHE = true;
|
||||
break;
|
||||
case 'l':
|
||||
if (NULL != optarg) {
|
||||
OB_LOGGER.set_log_level(optarg);
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
test::WITH_SCHEMA_ALTER = true;
|
||||
break;
|
||||
case 'e':
|
||||
test::WITH_CACHE_EVICT = true;
|
||||
break;
|
||||
case 'v':
|
||||
test::WITH_PLAN_VERIFY = true;
|
||||
break;
|
||||
case '0':
|
||||
test::OUTPUT_EXEC_TIME = true;
|
||||
break;
|
||||
case '1':
|
||||
test::OUTPUT_LOGIC_PLAN = true;
|
||||
break;
|
||||
case '2':
|
||||
test::OUTPUT_PHY_PLAN = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user