[FEAT MERGE]adaptive cost model

This commit is contained in:
zzg19950727 2024-02-07 11:01:37 +00:00 committed by ob-robot
parent 1ee1ad37e4
commit 9a22f3ea88
85 changed files with 21899 additions and 18832 deletions

View File

@ -224,6 +224,7 @@ public:
share::schema::ObMultiVersionSchemaService &get_schema_service() { return schema_service_; }
ObInOutBandwidthThrottle &get_bandwidth_throttle() { return bandwidth_throttle_; }
uint64_t get_cpu_frequency_khz() { return cpu_frequency_; }
int64_t get_network_speed() const { return ethernet_speed_; }
const common::ObAddr &get_self() const { return self_addr_; }
const ObGlobalContext &get_gctx() const { return gctx_; }
ObGlobalContext &get_gctx() { return gctx_; }

View File

@ -338,6 +338,9 @@
INTERFACE_DEF(INTERFACE_DBMS_STATS_SET_INDEX_STATS, "SET_INDEX_STATS", (ObDbmsStats::set_index_stats))
INTERFACE_DEF(INTERFACE_DBMS_STATS_EXPORT_INDEX_STATS, "EXPORT_INDEX_STATS", (ObDbmsStats::export_index_stats))
INTERFACE_DEF(INTERFACE_DBMS_STATS_IMPORT_INDEX_STATS, "IMPORT_INDEX_STATS", (ObDbmsStats::import_index_stats))
INTERFACE_DEF(INTERFACE_DBMS_STATS_GATHER_SYSTEM_STATS, "GATHER_SYSTEM_STATS", (ObDbmsStats::gather_system_stats))
INTERFACE_DEF(INTERFACE_DBMS_STATS_DELETE_SYSTEM_STATS, "DELETE_SYSTEM_STATS", (ObDbmsStats::delete_system_stats))
INTERFACE_DEF(INTERFACE_DBMS_STATS_SET_SYSTEM_STATS, "SET_SYSTEM_STATS", (ObDbmsStats::set_system_stats))
//end of dbms_stat
#ifdef OB_BUILD_ORACLE_PL

View File

@ -31,6 +31,7 @@
#include "storage/ob_locality_manager.h"
#include "share/stat/ob_opt_stat_gather_stat.h"
#include "sql/engine/expr/ob_expr_uuid.h"
#include "sql/privilege_check/ob_ora_priv_check.h"
namespace oceanbase
{
@ -6274,6 +6275,7 @@ int ObDbmsStats::init_column_group_stat_param(const share::schema::ObTableSchema
return ret;
}
//Avoid holding schema guard for a long time to caused dynamic leakage of schema memory, we need refresh tenant schema guard
int ObDbmsStats::refresh_tenant_schema_guard(ObExecContext &ctx, const uint64_t tenant_id)
{
@ -6292,5 +6294,216 @@ int ObDbmsStats::refresh_tenant_schema_guard(ObExecContext &ctx, const uint64_t
return ret;
}
/**
* @brief ObDbmsStats::gather_system_stats
* @param ctx
* @param params
* @param result
* @return
*/
int ObDbmsStats::gather_system_stats(sql::ObExecContext &ctx,
sql::ParamStore &params,
common::ObObj &result)
{
int ret = OB_SUCCESS;
UNUSED(result);
ObSQLSessionInfo *session = ctx.get_my_session();
if (OB_ISNULL(session)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("params have null", K(ret), K(session));
} else if (OB_FAIL(check_modify_system_stats_pri(*session))) {
LOG_WARN("failed to check is unix connection", K(ret));
} else if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(check_system_stat_table_ready(session->get_effective_tenant_id()))) {
LOG_WARN("failed to check system stat table ready", K(ret));
} else if (OB_FAIL(ObDbmsStatsExecutor::gather_system_stats(ctx, session->get_effective_tenant_id()))) {
LOG_WARN("failed to gather system stats", K(ret));
} else if (OB_FAIL(update_system_stats_cache(session->get_rpc_tenant_id(),
session->get_effective_tenant_id()))) {
LOG_WARN("failed to update system stat cache", K(ret));
}
return ret;
}
/**
* @brief ObDbmsStats::delete_system_stats
* @param ctx
* @param params
* @param result
* @return
*/
int ObDbmsStats::delete_system_stats(sql::ObExecContext &ctx,
sql::ParamStore &params,
common::ObObj &result)
{
int ret = OB_SUCCESS;
UNUSED(result);
ObSQLSessionInfo *session = ctx.get_my_session();
if (OB_ISNULL(session)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("params have null", K(ret), K(session));
} else if (OB_FAIL(check_modify_system_stats_pri(*session))) {
LOG_WARN("failed to check is unix connection", K(ret));
} else if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(check_system_stat_table_ready(session->get_effective_tenant_id()))) {
LOG_WARN("failed to check system stat table ready", K(ret));
} else if (OB_FAIL(ObDbmsStatsExecutor::delete_system_stats(ctx, session->get_effective_tenant_id()))) {
LOG_WARN("failed to delete system stats", K(ret));
} else if (OB_FAIL(update_system_stats_cache(session->get_rpc_tenant_id(),
session->get_effective_tenant_id()))) {
LOG_WARN("failed to update system stat cache", K(ret));
}
return ret;
}
/**
* @brief ObDbmsStats::set_system_stats
* @param ctx
* @param params
* pname VARCHAR2,
* pvalue NUMBER,
* @param result
* @return
*/
int ObDbmsStats::set_system_stats(sql::ObExecContext &ctx,
sql::ParamStore &params,
common::ObObj &result)
{
int ret = OB_SUCCESS;
UNUSED(result);
ObString name;
bool is_valid = false;
number::ObNumber num_value;
ObSQLSessionInfo *session = ctx.get_my_session();
ObSetSystemStatParam param;
if (OB_ISNULL(session)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("params have null", K(ret), K(session));
} else if (OB_FAIL(check_modify_system_stats_pri(*session))) {
LOG_WARN("failed to check is unix connection", K(ret));
} else if (OB_FAIL(check_statistic_table_writeable(ctx))) {
LOG_WARN("failed to check tenant is restore", K(ret));
} else if (OB_FAIL(check_system_stat_table_ready(session->get_effective_tenant_id()))) {
LOG_WARN("failed to check system stat table ready", K(ret));
} else if (2 != params.count()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("unexpect argument count", K(ret));
} else if (params.at(0).is_null()) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_USER_ERROR(OB_ERR_DBMS_STATS_PL, "unknown system stats name");
} else if (OB_FAIL(params.at(0).get_string(name))) {
LOG_WARN("failed to get string", K(ret));
} else if (OB_FAIL(check_system_stats_name_valid(name, is_valid))) {
LOG_WARN("failed to check system stats name valid", K(ret));
} else if (!is_valid) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_USER_ERROR(OB_ERR_DBMS_STATS_PL, "unknown system stats name");
} else if (OB_FAIL(ob_write_string(ctx.get_allocator(),
name,
param.name_))) {
LOG_WARN("failed to write stats name", K(ret));
} else if (!params.at(1).is_null() &&
OB_FAIL(params.at(1).get_number(num_value))) {
LOG_WARN("failed to get number", K(ret));
} else if (OB_FAIL(num_value.extract_valid_int64_with_trunc(param.value_))) {
LOG_WARN("failed to cast number to double" , K(ret));
} else if (OB_FALSE_IT(param.tenant_id_ = session->get_effective_tenant_id())) {
} else if (OB_FAIL(ObDbmsStatsExecutor::set_system_stats(ctx,
param))) {
LOG_WARN("failed to set system stats", K(param), K(ret));
} else if (OB_FAIL(update_system_stats_cache(session->get_rpc_tenant_id(),
session->get_effective_tenant_id()))) {
LOG_WARN("failed to update system stat cache", K(ret));
}
return ret;
}
int ObDbmsStats::update_system_stats_cache(const uint64_t rpc_tenant_id,
const uint64_t tenant_id)
{
int ret = OB_SUCCESS;
obrpc::ObUpdateStatCacheArg stat_arg;
stat_arg.tenant_id_ = tenant_id;
stat_arg.update_system_stats_only_ = true;
int64_t timeout = -1;
bool has_read_only_zone = false; // UNUSED;
ObSEArray<ObServerLocality, 4> all_server_arr;
ObSEArray<ObServerLocality, 4> failed_server_arr;
LOG_TRACE("update system stat cache", K(stat_arg));
if (OB_ISNULL(GCTX.srv_rpc_proxy_) || OB_ISNULL(GCTX.locality_manager_)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("rpc_proxy or session is null", K(ret), K(GCTX.srv_rpc_proxy_), K(GCTX.locality_manager_));
} else if (OB_FAIL(GCTX.locality_manager_->get_server_locality_array(all_server_arr,
has_read_only_zone))) {
LOG_WARN("fail to get server locality", K(ret));
}
for (int64_t i = 0; OB_SUCC(ret) && i < all_server_arr.count(); i++) {
if (!all_server_arr.at(i).is_active()
|| ObServerStatus::OB_SERVER_ACTIVE != all_server_arr.at(i).get_server_status()
|| 0 == all_server_arr.at(i).get_start_service_time()
|| 0 != all_server_arr.at(i).get_server_stop_time()) {
//server may not serving
} else if (0 >= (timeout = THIS_WORKER.get_timeout_remain())) {
ret = OB_TIMEOUT;
LOG_WARN("query timeout is reached", K(ret), K(timeout));
} else if (OB_FAIL(GCTX.srv_rpc_proxy_->to(all_server_arr.at(i).get_addr())
.timeout(timeout)
.by(rpc_tenant_id)
.update_local_stat_cache(stat_arg))) {
LOG_WARN("failed to update local stat cache caused by unknow error",
K(ret), K(all_server_arr.at(i).get_addr()), K(stat_arg));
if (OB_FAIL(failed_server_arr.push_back(all_server_arr.at(i)))) {
LOG_WARN("failed to push back", K(ret));
}
}
}
LOG_TRACE("update stat cache", K(stat_arg), K(failed_server_arr), K(all_server_arr));
return ret;
}
int ObDbmsStats::check_system_stats_name_valid(const ObString& name, bool &is_valid)
{
int ret = OB_SUCCESS;
is_valid = false;
static const char* system_stats_names[] = {
"cpu_speed",
"disk_seq_read_speed",
"disk_rnd_read_speed",
"network_speed"
};
for (int64_t i = 0; OB_SUCC(ret) && !is_valid && i < 4; ++i) {
if (ObCharset::case_insensitive_equal(name, system_stats_names[i])) {
is_valid = true;
}
}
return ret;
}
int ObDbmsStats::check_modify_system_stats_pri(const ObSQLSessionInfo& session)
{
int ret = OB_SUCCESS;
if (!ObOraSysChecker::is_super_user(session.get_user_id())) {
ret = OB_ERR_DBMS_STATS_PL;
LOG_WARN("current user has no privilege to modify system stats", K(ret));
LOG_USER_ERROR(OB_ERR_DBMS_STATS_PL, "current user has no privilege to modify system stats");
}
return ret;
}
int ObDbmsStats::check_system_stat_table_ready(int64_t tenant_id)
{
int ret = OB_SUCCESS;
uint64_t data_version = 0;
if (OB_FAIL(GET_MIN_DATA_VERSION(tenant_id, data_version))) {
LOG_WARN("failed to get data version", K(ret));
} else if (data_version < DATA_VERSION_4_3_0_0) {
ret = OB_NOT_SUPPORTED;
LOG_USER_ERROR(OB_NOT_SUPPORTED, "aux stat table not ready for system stats");
}
return ret;
}
}
}

View File

@ -493,6 +493,21 @@ public:
static int init_column_group_stat_param(const share::schema::ObTableSchema &table_schema,
ObIArray<ObColumnGroupStatParam> &column_group_params);
static int gather_system_stats(sql::ObExecContext &ctx,
sql::ParamStore &params,
common::ObObj &result);
static int delete_system_stats(sql::ObExecContext &ctx,
sql::ParamStore &params,
common::ObObj &result);
static int set_system_stats(sql::ObExecContext &ctx,
sql::ParamStore &params,
common::ObObj &result);
static int update_system_stats_cache(const uint64_t rpc_tenant_id,
const uint64_t tenant_id);
private:
static int check_statistic_table_writeable(sql::ObExecContext &ctx);
@ -578,6 +593,12 @@ private:
static int refresh_tenant_schema_guard(ObExecContext &ctx, const uint64_t tenant_id);
static int check_system_stats_name_valid(const ObString& name, bool &is_valid);
static int check_modify_system_stats_pri(const ObSQLSessionInfo& session);
static int check_system_stat_table_ready(int64_t tenant_id);
};
}

View File

@ -477,6 +477,8 @@ ob_set_subtarget(ob_share stat
stat/ob_opt_stat_gather_stat.cpp
stat/ob_opt_ds_stat.cpp
stat/ob_opt_ds_stat_cache.cpp
stat/ob_opt_system_stat.cpp
stat/ob_opt_system_stat_cache.cpp
)
ob_set_subtarget(ob_share external_table

View File

@ -6092,6 +6092,185 @@ int ObInnerTableSchema::all_virtual_import_table_task_history_schema(ObTableSche
return ret;
}
int ObInnerTableSchema::all_virtual_aux_stat_schema(ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;
uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1;
//generated fields:
table_schema.set_tenant_id(OB_SYS_TENANT_ID);
table_schema.set_tablegroup_id(OB_INVALID_ID);
table_schema.set_database_id(OB_SYS_DATABASE_ID);
table_schema.set_table_id(OB_ALL_VIRTUAL_AUX_STAT_TID);
table_schema.set_rowkey_split_pos(0);
table_schema.set_is_use_bloomfilter(false);
table_schema.set_progressive_merge_num(0);
table_schema.set_rowkey_column_num(1);
table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK);
table_schema.set_table_type(VIRTUAL_TABLE);
table_schema.set_index_type(INDEX_TYPE_IS_NOT);
table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL);
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_table_name(OB_ALL_VIRTUAL_AUX_STAT_TNAME))) {
LOG_ERROR("fail to set table_name", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) {
LOG_ERROR("fail to set compress_func_name", K(ret));
}
}
table_schema.set_part_level(PARTITION_LEVEL_ZERO);
table_schema.set_charset_type(ObCharset::get_default_charset());
table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("tenant_id", //column_name
++column_id, //column_id
1, //rowkey_id
0, //index_id
0, //part_key_pos
ObIntType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(int64_t), //column_length
20, //column_precision
0, //column_scale
false, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA_TS("gmt_create", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObTimestampType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(ObPreciseDateTime), //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false, //is_autoincrement
false); //is_on_update_for_timestamp
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA_TS("gmt_modified", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObTimestampType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(ObPreciseDateTime), //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false, //is_autoincrement
false); //is_on_update_for_timestamp
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA_TS("last_analyzed", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObTimestampType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(ObPreciseDateTime), //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false, //is_autoincrement
false); //is_on_update_for_timestamp
}
if (OB_SUCC(ret)) {
ObObj cpu_speed_default;
cpu_speed_default.set_int(2500);
ADD_COLUMN_SCHEMA_T("cpu_speed", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObIntType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(int64_t), //column_length
20, //column_precision
0, //column_scale
true, //is_nullable
false, //is_autoincrement
cpu_speed_default,
cpu_speed_default); //default_value
}
if (OB_SUCC(ret)) {
ObObj disk_seq_read_speed_default;
disk_seq_read_speed_default.set_int(2000);
ADD_COLUMN_SCHEMA_T("disk_seq_read_speed", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObIntType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(int64_t), //column_length
20, //column_precision
0, //column_scale
true, //is_nullable
false, //is_autoincrement
disk_seq_read_speed_default,
disk_seq_read_speed_default); //default_value
}
if (OB_SUCC(ret)) {
ObObj disk_rnd_read_speed_default;
disk_rnd_read_speed_default.set_int(150);
ADD_COLUMN_SCHEMA_T("disk_rnd_read_speed", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObIntType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(int64_t), //column_length
20, //column_precision
0, //column_scale
true, //is_nullable
false, //is_autoincrement
disk_rnd_read_speed_default,
disk_rnd_read_speed_default); //default_value
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("network_speed", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObIntType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(int64_t), //column_length
20, //column_precision
0, //column_scale
1000, //is_nullable
false); //is_autoincrement
}
table_schema.set_index_using_type(USING_BTREE);
table_schema.set_row_store_type(ENCODING_ROW_STORE);
table_schema.set_store_format(OB_STORE_FORMAT_DYNAMIC_MYSQL);
table_schema.set_progressive_merge_round(1);
table_schema.set_storage_format_version(3);
table_schema.set_tablet_id(0);
table_schema.set_max_used_column_id(column_id);
return ret;
}
} // end namespace share
} // end namespace oceanbase

View File

@ -4659,6 +4659,170 @@ int ObInnerTableSchema::all_virtual_ls_info_ora_schema(ObTableSchema &table_sche
return ret;
}
int ObInnerTableSchema::all_virtual_aux_stat_real_agent_ora_schema(ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;
uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1;
//generated fields:
table_schema.set_tenant_id(OB_SYS_TENANT_ID);
table_schema.set_tablegroup_id(OB_INVALID_ID);
table_schema.set_database_id(OB_ORA_SYS_DATABASE_ID);
table_schema.set_table_id(OB_ALL_VIRTUAL_AUX_STAT_REAL_AGENT_ORA_TID);
table_schema.set_rowkey_split_pos(0);
table_schema.set_is_use_bloomfilter(false);
table_schema.set_progressive_merge_num(0);
table_schema.set_rowkey_column_num(1);
table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK);
table_schema.set_table_type(VIRTUAL_TABLE);
table_schema.set_index_type(INDEX_TYPE_IS_NOT);
table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL);
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_table_name(OB_ALL_VIRTUAL_AUX_STAT_REAL_AGENT_ORA_TNAME))) {
LOG_ERROR("fail to set table_name", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) {
LOG_ERROR("fail to set compress_func_name", K(ret));
}
}
table_schema.set_part_level(PARTITION_LEVEL_ZERO);
table_schema.set_charset_type(ObCharset::get_default_charset());
table_schema.set_collation_type(ObCollationType::CS_TYPE_UTF8MB4_BIN);
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("TENANT_ID", //column_name
++column_id, //column_id
1, //rowkey_id
0, //index_id
0, //part_key_pos
ObNumberType, //column_type
CS_TYPE_INVALID, //column_collation_type
38, //column_length
38, //column_precision
0, //column_scale
false, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("LAST_ANALYZED", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObTimestampLTZType, //column_type
CS_TYPE_INVALID, //column_collation_type
0, //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("CPU_SPEED", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObNumberType, //column_type
CS_TYPE_INVALID, //column_collation_type
38, //column_length
38, //column_precision
0, //column_scale
true, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("DISK_SEQ_READ_SPEED", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObNumberType, //column_type
CS_TYPE_INVALID, //column_collation_type
38, //column_length
38, //column_precision
0, //column_scale
true, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("DISK_RND_READ_SPEED", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObNumberType, //column_type
CS_TYPE_INVALID, //column_collation_type
38, //column_length
38, //column_precision
0, //column_scale
true, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("NETWORK_SPEED", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObNumberType, //column_type
CS_TYPE_INVALID, //column_collation_type
38, //column_length
38, //column_precision
0, //column_scale
1000, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("GMT_CREATE", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObTimestampLTZType, //column_type
CS_TYPE_INVALID, //column_collation_type
0, //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("GMT_MODIFIED", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObTimestampLTZType, //column_type
CS_TYPE_INVALID, //column_collation_type
0, //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false); //is_autoincrement
}
table_schema.set_index_using_type(USING_BTREE);
table_schema.set_row_store_type(ENCODING_ROW_STORE);
table_schema.set_store_format(OB_STORE_FORMAT_DYNAMIC_MYSQL);
table_schema.set_progressive_merge_round(1);
table_schema.set_storage_format_version(3);
table_schema.set_tablet_id(0);
table_schema.set_max_used_column_id(column_id);
return ret;
}
} // end namespace share
} // end namespace oceanbase

View File

@ -725,6 +725,106 @@ int ObInnerTableSchema::v_ob_tenant_runtime_info_schema(ObTableSchema &table_sch
return ret;
}
int ObInnerTableSchema::dba_ob_aux_statistics_schema(ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;
uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1;
//generated fields:
table_schema.set_tenant_id(OB_SYS_TENANT_ID);
table_schema.set_tablegroup_id(OB_INVALID_ID);
table_schema.set_database_id(OB_SYS_DATABASE_ID);
table_schema.set_table_id(OB_DBA_OB_AUX_STATISTICS_TID);
table_schema.set_rowkey_split_pos(0);
table_schema.set_is_use_bloomfilter(false);
table_schema.set_progressive_merge_num(0);
table_schema.set_rowkey_column_num(0);
table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK);
table_schema.set_table_type(SYSTEM_VIEW);
table_schema.set_index_type(INDEX_TYPE_IS_NOT);
table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL);
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_table_name(OB_DBA_OB_AUX_STATISTICS_TNAME))) {
LOG_ERROR("fail to set table_name", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) {
LOG_ERROR("fail to set compress_func_name", K(ret));
}
}
table_schema.set_part_level(PARTITION_LEVEL_ZERO);
table_schema.set_charset_type(ObCharset::get_default_charset());
table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_view_definition(R"__( select LAST_ANALYZED, CPU_SPEED AS `CPU_SPEED(MHZ)`, DISK_SEQ_READ_SPEED AS `DISK_SEQ_READ_SPEED(MB/S)`, DISK_RND_READ_SPEED AS `DISK_RND_READ_SPEED(MB/S)`, NETWORK_SPEED AS `NETWORK_SPEED(MB/S)` from oceanbase.__all_aux_stat; )__"))) {
LOG_ERROR("fail to set view_definition", K(ret));
}
}
table_schema.set_index_using_type(USING_BTREE);
table_schema.set_row_store_type(ENCODING_ROW_STORE);
table_schema.set_store_format(OB_STORE_FORMAT_DYNAMIC_MYSQL);
table_schema.set_progressive_merge_round(1);
table_schema.set_storage_format_version(3);
table_schema.set_tablet_id(0);
table_schema.set_max_used_column_id(column_id);
return ret;
}
int ObInnerTableSchema::cdb_ob_aux_statistics_schema(ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;
uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1;
//generated fields:
table_schema.set_tenant_id(OB_SYS_TENANT_ID);
table_schema.set_tablegroup_id(OB_INVALID_ID);
table_schema.set_database_id(OB_SYS_DATABASE_ID);
table_schema.set_table_id(OB_CDB_OB_AUX_STATISTICS_TID);
table_schema.set_rowkey_split_pos(0);
table_schema.set_is_use_bloomfilter(false);
table_schema.set_progressive_merge_num(0);
table_schema.set_rowkey_column_num(0);
table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK);
table_schema.set_table_type(SYSTEM_VIEW);
table_schema.set_index_type(INDEX_TYPE_IS_NOT);
table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL);
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_table_name(OB_CDB_OB_AUX_STATISTICS_TNAME))) {
LOG_ERROR("fail to set table_name", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) {
LOG_ERROR("fail to set compress_func_name", K(ret));
}
}
table_schema.set_part_level(PARTITION_LEVEL_ZERO);
table_schema.set_charset_type(ObCharset::get_default_charset());
table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_view_definition(R"__( select TENANT_ID, LAST_ANALYZED, CPU_SPEED AS `CPU_SPEED(MHZ)`, DISK_SEQ_READ_SPEED AS `DISK_SEQ_READ_SPEED(MB/S)`, DISK_RND_READ_SPEED AS `DISK_RND_READ_SPEED(MB/S)`, NETWORK_SPEED AS `NETWORK_SPEED(MB/S)` from oceanbase.__all_virtual_aux_stat; )__"))) {
LOG_ERROR("fail to set view_definition", K(ret));
}
}
table_schema.set_index_using_type(USING_BTREE);
table_schema.set_row_store_type(ENCODING_ROW_STORE);
table_schema.set_store_format(OB_STORE_FORMAT_DYNAMIC_MYSQL);
table_schema.set_progressive_merge_round(1);
table_schema.set_storage_format_version(3);
table_schema.set_tablet_id(0);
table_schema.set_max_used_column_id(column_id);
return ret;
}
} // end namespace share
} // end namespace oceanbase

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -6946,6 +6946,201 @@ int ObInnerTableSchema::all_import_table_task_history_schema(ObTableSchema &tabl
return ret;
}
int ObInnerTableSchema::all_aux_stat_schema(ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;
uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1;
//generated fields:
table_schema.set_tenant_id(OB_SYS_TENANT_ID);
table_schema.set_tablegroup_id(OB_SYS_TABLEGROUP_ID);
table_schema.set_database_id(OB_SYS_DATABASE_ID);
table_schema.set_table_id(OB_ALL_AUX_STAT_TID);
table_schema.set_rowkey_split_pos(0);
table_schema.set_is_use_bloomfilter(false);
table_schema.set_progressive_merge_num(0);
table_schema.set_rowkey_column_num(1);
table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK);
table_schema.set_table_type(SYSTEM_TABLE);
table_schema.set_index_type(INDEX_TYPE_IS_NOT);
table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL);
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_table_name(OB_ALL_AUX_STAT_TNAME))) {
LOG_ERROR("fail to set table_name", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) {
LOG_ERROR("fail to set compress_func_name", K(ret));
}
}
table_schema.set_part_level(PARTITION_LEVEL_ZERO);
table_schema.set_charset_type(ObCharset::get_default_charset());
table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
if (OB_SUCC(ret)) {
ObObj gmt_create_default;
ObObj gmt_create_default_null;
gmt_create_default.set_ext(ObActionFlag::OP_DEFAULT_NOW_FLAG);
gmt_create_default_null.set_null();
ADD_COLUMN_SCHEMA_TS_T("gmt_create", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObTimestampType, //column_type
CS_TYPE_BINARY,//collation_type
0, //column length
-1, //column_precision
6, //column_scale
true,//is nullable
false, //is_autoincrement
false, //is_on_update_for_timestamp
gmt_create_default_null,
gmt_create_default)
}
if (OB_SUCC(ret)) {
ObObj gmt_modified_default;
ObObj gmt_modified_default_null;
gmt_modified_default.set_ext(ObActionFlag::OP_DEFAULT_NOW_FLAG);
gmt_modified_default_null.set_null();
ADD_COLUMN_SCHEMA_TS_T("gmt_modified", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObTimestampType, //column_type
CS_TYPE_BINARY,//collation_type
0, //column length
-1, //column_precision
6, //column_scale
true,//is nullable
false, //is_autoincrement
true, //is_on_update_for_timestamp
gmt_modified_default_null,
gmt_modified_default)
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("tenant_id", //column_name
++column_id, //column_id
1, //rowkey_id
0, //index_id
0, //part_key_pos
ObIntType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(int64_t), //column_length
20, //column_precision
0, //column_scale
false, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA_TS("last_analyzed", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObTimestampType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(ObPreciseDateTime), //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false, //is_autoincrement
false); //is_on_update_for_timestamp
}
if (OB_SUCC(ret)) {
ObObj cpu_speed_default;
cpu_speed_default.set_int(2500);
ADD_COLUMN_SCHEMA_T("cpu_speed", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObIntType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(int64_t), //column_length
20, //column_precision
0, //column_scale
true, //is_nullable
false, //is_autoincrement
cpu_speed_default,
cpu_speed_default); //default_value
}
if (OB_SUCC(ret)) {
ObObj disk_seq_read_speed_default;
disk_seq_read_speed_default.set_int(2000);
ADD_COLUMN_SCHEMA_T("disk_seq_read_speed", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObIntType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(int64_t), //column_length
20, //column_precision
0, //column_scale
true, //is_nullable
false, //is_autoincrement
disk_seq_read_speed_default,
disk_seq_read_speed_default); //default_value
}
if (OB_SUCC(ret)) {
ObObj disk_rnd_read_speed_default;
disk_rnd_read_speed_default.set_int(150);
ADD_COLUMN_SCHEMA_T("disk_rnd_read_speed", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObIntType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(int64_t), //column_length
20, //column_precision
0, //column_scale
true, //is_nullable
false, //is_autoincrement
disk_rnd_read_speed_default,
disk_rnd_read_speed_default); //default_value
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("network_speed", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObIntType, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(int64_t), //column_length
20, //column_precision
0, //column_scale
1000, //is_nullable
false); //is_autoincrement
}
table_schema.set_index_using_type(USING_BTREE);
table_schema.set_row_store_type(ENCODING_ROW_STORE);
table_schema.set_store_format(OB_STORE_FORMAT_DYNAMIC_MYSQL);
table_schema.set_progressive_merge_round(1);
table_schema.set_storage_format_version(3);
table_schema.set_tablet_id(OB_ALL_AUX_STAT_TID);
table_schema.set_aux_lob_meta_tid(OB_ALL_AUX_STAT_AUX_LOB_META_TID);
table_schema.set_aux_lob_piece_tid(OB_ALL_AUX_STAT_AUX_LOB_PIECE_TID);
table_schema.set_max_used_column_id(column_id);
return ret;
}
} // end namespace share
} // end namespace oceanbase

View File

@ -2455,6 +2455,141 @@ int ObInnerTableSchema::all_import_table_task_history_aux_lob_meta_schema(ObTabl
return ret;
}
int ObInnerTableSchema::all_aux_stat_aux_lob_meta_schema(ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;
uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1;
//generated fields:
table_schema.set_tenant_id(OB_SYS_TENANT_ID);
table_schema.set_tablegroup_id(OB_SYS_TABLEGROUP_ID);
table_schema.set_database_id(OB_SYS_DATABASE_ID);
table_schema.set_table_id(OB_ALL_AUX_STAT_AUX_LOB_META_TID);
table_schema.set_rowkey_split_pos(0);
table_schema.set_is_use_bloomfilter(false);
table_schema.set_progressive_merge_num(0);
table_schema.set_rowkey_column_num(2);
table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK);
table_schema.set_table_type(AUX_LOB_META);
table_schema.set_index_type(INDEX_TYPE_IS_NOT);
table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL);
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_table_name(OB_ALL_AUX_STAT_AUX_LOB_META_TNAME))) {
LOG_ERROR("fail to set table_name", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) {
LOG_ERROR("fail to set compress_func_name", K(ret));
}
}
table_schema.set_part_level(PARTITION_LEVEL_ZERO);
table_schema.set_charset_type(ObCharset::get_default_charset());
table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("lob_id", //column_name
++column_id, //column_id
1, //rowkey_id
0, //index_id
0, //part_key_pos
ObVarcharType, //column_type
CS_TYPE_BINARY, //column_collation_type
16, //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("seq_id", //column_name
++column_id, //column_id
2, //rowkey_id
0, //index_id
0, //part_key_pos
ObVarcharType, //column_type
CS_TYPE_BINARY, //column_collation_type
8192, //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("binary_len", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObUInt32Type, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(uint32_t), //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("char_len", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObUInt32Type, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(uint32_t), //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("piece_id", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObUInt64Type, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(uint64_t), //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("lob_data", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObVarcharType, //column_type
CS_TYPE_BINARY, //column_collation_type
262144, //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false); //is_autoincrement
}
table_schema.set_index_using_type(USING_BTREE);
table_schema.set_row_store_type(ENCODING_ROW_STORE);
table_schema.set_store_format(OB_STORE_FORMAT_DYNAMIC_MYSQL);
table_schema.set_progressive_merge_round(1);
table_schema.set_storage_format_version(3);
table_schema.set_tablet_id(OB_ALL_AUX_STAT_AUX_LOB_META_TID);
table_schema.set_data_table_id(OB_ALL_AUX_STAT_TID);
table_schema.set_max_used_column_id(column_id);
return ret;
}
} // end namespace share
} // end namespace oceanbase

View File

@ -1645,6 +1645,96 @@ int ObInnerTableSchema::all_import_table_task_history_aux_lob_piece_schema(ObTab
return ret;
}
int ObInnerTableSchema::all_aux_stat_aux_lob_piece_schema(ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;
uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1;
//generated fields:
table_schema.set_tenant_id(OB_SYS_TENANT_ID);
table_schema.set_tablegroup_id(OB_SYS_TABLEGROUP_ID);
table_schema.set_database_id(OB_SYS_DATABASE_ID);
table_schema.set_table_id(OB_ALL_AUX_STAT_AUX_LOB_PIECE_TID);
table_schema.set_rowkey_split_pos(0);
table_schema.set_is_use_bloomfilter(false);
table_schema.set_progressive_merge_num(0);
table_schema.set_rowkey_column_num(1);
table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK);
table_schema.set_table_type(AUX_LOB_PIECE);
table_schema.set_index_type(INDEX_TYPE_IS_NOT);
table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL);
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_table_name(OB_ALL_AUX_STAT_AUX_LOB_PIECE_TNAME))) {
LOG_ERROR("fail to set table_name", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) {
LOG_ERROR("fail to set compress_func_name", K(ret));
}
}
table_schema.set_part_level(PARTITION_LEVEL_ZERO);
table_schema.set_charset_type(ObCharset::get_default_charset());
table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("piece_id", //column_name
++column_id, //column_id
1, //rowkey_id
0, //index_id
0, //part_key_pos
ObUInt64Type, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(uint64_t), //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("data_len", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObUInt32Type, //column_type
CS_TYPE_INVALID, //column_collation_type
sizeof(uint32_t), //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false); //is_autoincrement
}
if (OB_SUCC(ret)) {
ADD_COLUMN_SCHEMA("lob_data", //column_name
++column_id, //column_id
0, //rowkey_id
0, //index_id
0, //part_key_pos
ObVarcharType, //column_type
CS_TYPE_BINARY, //column_collation_type
32, //column_length
-1, //column_precision
-1, //column_scale
false, //is_nullable
false); //is_autoincrement
}
table_schema.set_index_using_type(USING_BTREE);
table_schema.set_row_store_type(ENCODING_ROW_STORE);
table_schema.set_store_format(OB_STORE_FORMAT_DYNAMIC_MYSQL);
table_schema.set_progressive_merge_round(1);
table_schema.set_storage_format_version(3);
table_schema.set_tablet_id(OB_ALL_AUX_STAT_AUX_LOB_PIECE_TID);
table_schema.set_data_table_id(OB_ALL_AUX_STAT_TID);
table_schema.set_max_used_column_id(column_id);
return ret;
}
} // end namespace share
} // end namespace oceanbase

View File

@ -556,6 +556,7 @@ public:
static int all_import_table_job_history_schema(share::schema::ObTableSchema &table_schema);
static int all_import_table_task_schema(share::schema::ObTableSchema &table_schema);
static int all_import_table_task_history_schema(share::schema::ObTableSchema &table_schema);
static int all_aux_stat_schema(share::schema::ObTableSchema &table_schema);
static int tenant_virtual_all_table_schema(share::schema::ObTableSchema &table_schema);
static int tenant_virtual_table_column_schema(share::schema::ObTableSchema &table_schema);
static int tenant_virtual_table_index_schema(share::schema::ObTableSchema &table_schema);
@ -959,6 +960,7 @@ public:
static int all_virtual_import_table_job_history_schema(share::schema::ObTableSchema &table_schema);
static int all_virtual_import_table_task_schema(share::schema::ObTableSchema &table_schema);
static int all_virtual_import_table_task_history_schema(share::schema::ObTableSchema &table_schema);
static int all_virtual_aux_stat_schema(share::schema::ObTableSchema &table_schema);
static int all_virtual_sql_audit_ora_schema(share::schema::ObTableSchema &table_schema);
static int all_virtual_plan_stat_ora_schema(share::schema::ObTableSchema &table_schema);
static int all_virtual_plan_cache_plan_explain_ora_schema(share::schema::ObTableSchema &table_schema);
@ -1207,6 +1209,7 @@ public:
static int all_virtual_import_table_task_ora_schema(share::schema::ObTableSchema &table_schema);
static int all_virtual_import_table_task_history_ora_schema(share::schema::ObTableSchema &table_schema);
static int all_virtual_ls_info_ora_schema(share::schema::ObTableSchema &table_schema);
static int all_virtual_aux_stat_real_agent_ora_schema(share::schema::ObTableSchema &table_schema);
static int gv_ob_plan_cache_stat_schema(share::schema::ObTableSchema &table_schema);
static int gv_ob_plan_cache_plan_stat_schema(share::schema::ObTableSchema &table_schema);
static int schemata_schema(share::schema::ObTableSchema &table_schema);
@ -1574,6 +1577,8 @@ public:
static int dba_ob_import_table_task_history_schema(share::schema::ObTableSchema &table_schema);
static int gv_ob_tenant_runtime_info_schema(share::schema::ObTableSchema &table_schema);
static int v_ob_tenant_runtime_info_schema(share::schema::ObTableSchema &table_schema);
static int dba_ob_aux_statistics_schema(share::schema::ObTableSchema &table_schema);
static int cdb_ob_aux_statistics_schema(share::schema::ObTableSchema &table_schema);
static int dba_synonyms_schema(share::schema::ObTableSchema &table_schema);
static int dba_objects_ora_schema(share::schema::ObTableSchema &table_schema);
static int all_objects_schema(share::schema::ObTableSchema &table_schema);
@ -1996,6 +2001,7 @@ public:
static int v_ob_timestamp_service_ora_schema(share::schema::ObTableSchema &table_schema);
static int v_ob_ls_log_restore_status_ora_schema(share::schema::ObTableSchema &table_schema);
static int gv_ob_flt_trace_config_ora_schema(share::schema::ObTableSchema &table_schema);
static int dba_ob_aux_statistics_ora_schema(share::schema::ObTableSchema &table_schema);
static int all_table_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema);
static int all_column_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema);
static int all_ddl_operation_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema);
@ -2260,6 +2266,7 @@ public:
static int all_import_table_job_history_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema);
static int all_import_table_task_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema);
static int all_import_table_task_history_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema);
static int all_aux_stat_aux_lob_meta_schema(share::schema::ObTableSchema &table_schema);
static int all_table_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema);
static int all_column_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema);
static int all_ddl_operation_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema);
@ -2524,6 +2531,7 @@ public:
static int all_import_table_job_history_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema);
static int all_import_table_task_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema);
static int all_import_table_task_history_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema);
static int all_aux_stat_aux_lob_piece_schema(share::schema::ObTableSchema &table_schema);
static int all_virtual_ash_all_virtual_ash_i1_schema(share::schema::ObTableSchema &table_schema);
static int all_virtual_sql_plan_monitor_all_virtual_sql_plan_monitor_i1_schema(share::schema::ObTableSchema &table_schema);
static int all_virtual_sql_audit_all_virtual_sql_audit_i1_schema(share::schema::ObTableSchema &table_schema);
@ -2992,6 +3000,7 @@ const schema_create_func sys_table_schema_creators [] = {
ObInnerTableSchema::all_import_table_job_history_schema,
ObInnerTableSchema::all_import_table_task_schema,
ObInnerTableSchema::all_import_table_task_history_schema,
ObInnerTableSchema::all_aux_stat_schema,
NULL,};
const schema_create_func virtual_table_schema_creators [] = {
@ -3398,6 +3407,7 @@ const schema_create_func virtual_table_schema_creators [] = {
ObInnerTableSchema::all_virtual_import_table_job_history_schema,
ObInnerTableSchema::all_virtual_import_table_task_schema,
ObInnerTableSchema::all_virtual_import_table_task_history_schema,
ObInnerTableSchema::all_virtual_aux_stat_schema,
ObInnerTableSchema::all_virtual_ash_all_virtual_ash_i1_schema,
ObInnerTableSchema::all_virtual_sql_plan_monitor_all_virtual_sql_plan_monitor_i1_schema,
ObInnerTableSchema::all_virtual_sql_audit_all_virtual_sql_audit_i1_schema,
@ -3656,6 +3666,7 @@ const schema_create_func virtual_table_schema_creators [] = {
ObInnerTableSchema::all_virtual_import_table_task_ora_schema,
ObInnerTableSchema::all_virtual_import_table_task_history_ora_schema,
ObInnerTableSchema::all_virtual_ls_info_ora_schema,
ObInnerTableSchema::all_virtual_aux_stat_real_agent_ora_schema,
ObInnerTableSchema::all_virtual_table_real_agent_ora_idx_data_table_id_real_agent_schema,
ObInnerTableSchema::all_virtual_table_real_agent_ora_idx_db_tb_name_real_agent_schema,
ObInnerTableSchema::all_virtual_table_real_agent_ora_idx_tb_name_real_agent_schema,
@ -4107,6 +4118,8 @@ const schema_create_func sys_view_schema_creators [] = {
ObInnerTableSchema::dba_ob_import_table_task_history_schema,
ObInnerTableSchema::gv_ob_tenant_runtime_info_schema,
ObInnerTableSchema::v_ob_tenant_runtime_info_schema,
ObInnerTableSchema::dba_ob_aux_statistics_schema,
ObInnerTableSchema::cdb_ob_aux_statistics_schema,
ObInnerTableSchema::dba_synonyms_schema,
ObInnerTableSchema::dba_objects_ora_schema,
ObInnerTableSchema::all_objects_schema,
@ -4529,6 +4542,7 @@ const schema_create_func sys_view_schema_creators [] = {
ObInnerTableSchema::v_ob_timestamp_service_ora_schema,
ObInnerTableSchema::v_ob_ls_log_restore_status_ora_schema,
ObInnerTableSchema::gv_ob_flt_trace_config_ora_schema,
ObInnerTableSchema::dba_ob_aux_statistics_ora_schema,
NULL,};
const schema_create_func core_index_table_schema_creators [] = {
@ -4886,6 +4900,7 @@ const uint64_t tenant_space_tables [] = {
OB_ALL_IMPORT_TABLE_JOB_HISTORY_TID,
OB_ALL_IMPORT_TABLE_TASK_TID,
OB_ALL_IMPORT_TABLE_TASK_HISTORY_TID,
OB_ALL_AUX_STAT_TID,
OB_TENANT_VIRTUAL_ALL_TABLE_TID,
OB_TENANT_VIRTUAL_TABLE_COLUMN_TID,
OB_TENANT_VIRTUAL_TABLE_INDEX_TID,
@ -5341,6 +5356,7 @@ const uint64_t tenant_space_tables [] = {
OB_ALL_VIRTUAL_IMPORT_TABLE_TASK_ORA_TID,
OB_ALL_VIRTUAL_IMPORT_TABLE_TASK_HISTORY_ORA_TID,
OB_ALL_VIRTUAL_LS_INFO_ORA_TID,
OB_ALL_VIRTUAL_AUX_STAT_REAL_AGENT_ORA_TID,
OB_GV_OB_PLAN_CACHE_STAT_TID,
OB_GV_OB_PLAN_CACHE_PLAN_STAT_TID,
OB_SCHEMATA_TID,
@ -5604,6 +5620,7 @@ const uint64_t tenant_space_tables [] = {
OB_DBA_OB_IMPORT_TABLE_JOB_HISTORY_TID,
OB_DBA_OB_IMPORT_TABLE_TASKS_TID,
OB_DBA_OB_IMPORT_TABLE_TASK_HISTORY_TID,
OB_DBA_OB_AUX_STATISTICS_TID,
OB_DBA_SYNONYMS_TID,
OB_DBA_OBJECTS_ORA_TID,
OB_ALL_OBJECTS_TID,
@ -6026,6 +6043,7 @@ const uint64_t tenant_space_tables [] = {
OB_V_OB_TIMESTAMP_SERVICE_ORA_TID,
OB_V_OB_LS_LOG_RESTORE_STATUS_ORA_TID,
OB_GV_OB_FLT_TRACE_CONFIG_ORA_TID,
OB_DBA_OB_AUX_STATISTICS_ORA_TID,
OB_ALL_TABLE_IDX_DATA_TABLE_ID_TID,
OB_ALL_TABLE_IDX_DB_TB_NAME_TID,
OB_ALL_TABLE_IDX_TB_NAME_TID,
@ -6433,6 +6451,7 @@ const uint64_t tenant_space_tables [] = {
OB_ALL_IMPORT_TABLE_JOB_HISTORY_AUX_LOB_META_TID,
OB_ALL_IMPORT_TABLE_TASK_AUX_LOB_META_TID,
OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_META_TID,
OB_ALL_AUX_STAT_AUX_LOB_META_TID,
OB_ALL_TABLE_AUX_LOB_PIECE_TID,
OB_ALL_COLUMN_AUX_LOB_PIECE_TID,
OB_ALL_DDL_OPERATION_AUX_LOB_PIECE_TID,
@ -6675,7 +6694,8 @@ const uint64_t tenant_space_tables [] = {
OB_ALL_IMPORT_TABLE_JOB_AUX_LOB_PIECE_TID,
OB_ALL_IMPORT_TABLE_JOB_HISTORY_AUX_LOB_PIECE_TID,
OB_ALL_IMPORT_TABLE_TASK_AUX_LOB_PIECE_TID,
OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_PIECE_TID, };
OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_PIECE_TID,
OB_ALL_AUX_STAT_AUX_LOB_PIECE_TID, };
const uint64_t all_ora_mapping_virtual_table_org_tables [] = {
OB_ALL_VIRTUAL_SQL_AUDIT_TID,
@ -7211,6 +7231,7 @@ const char* const tenant_space_table_names [] = {
OB_ALL_IMPORT_TABLE_JOB_HISTORY_TNAME,
OB_ALL_IMPORT_TABLE_TASK_TNAME,
OB_ALL_IMPORT_TABLE_TASK_HISTORY_TNAME,
OB_ALL_AUX_STAT_TNAME,
OB_TENANT_VIRTUAL_ALL_TABLE_TNAME,
OB_TENANT_VIRTUAL_TABLE_COLUMN_TNAME,
OB_TENANT_VIRTUAL_TABLE_INDEX_TNAME,
@ -7666,6 +7687,7 @@ const char* const tenant_space_table_names [] = {
OB_ALL_VIRTUAL_IMPORT_TABLE_TASK_ORA_TNAME,
OB_ALL_VIRTUAL_IMPORT_TABLE_TASK_HISTORY_ORA_TNAME,
OB_ALL_VIRTUAL_LS_INFO_ORA_TNAME,
OB_ALL_VIRTUAL_AUX_STAT_REAL_AGENT_ORA_TNAME,
OB_GV_OB_PLAN_CACHE_STAT_TNAME,
OB_GV_OB_PLAN_CACHE_PLAN_STAT_TNAME,
OB_SCHEMATA_TNAME,
@ -7929,6 +7951,7 @@ const char* const tenant_space_table_names [] = {
OB_DBA_OB_IMPORT_TABLE_JOB_HISTORY_TNAME,
OB_DBA_OB_IMPORT_TABLE_TASKS_TNAME,
OB_DBA_OB_IMPORT_TABLE_TASK_HISTORY_TNAME,
OB_DBA_OB_AUX_STATISTICS_TNAME,
OB_DBA_SYNONYMS_TNAME,
OB_DBA_OBJECTS_ORA_TNAME,
OB_ALL_OBJECTS_TNAME,
@ -8351,6 +8374,7 @@ const char* const tenant_space_table_names [] = {
OB_V_OB_TIMESTAMP_SERVICE_ORA_TNAME,
OB_V_OB_LS_LOG_RESTORE_STATUS_ORA_TNAME,
OB_GV_OB_FLT_TRACE_CONFIG_ORA_TNAME,
OB_DBA_OB_AUX_STATISTICS_ORA_TNAME,
OB_ALL_TABLE_IDX_DATA_TABLE_ID_TNAME,
OB_ALL_TABLE_IDX_DB_TB_NAME_TNAME,
OB_ALL_TABLE_IDX_TB_NAME_TNAME,
@ -8758,6 +8782,7 @@ const char* const tenant_space_table_names [] = {
OB_ALL_IMPORT_TABLE_JOB_HISTORY_AUX_LOB_META_TNAME,
OB_ALL_IMPORT_TABLE_TASK_AUX_LOB_META_TNAME,
OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_META_TNAME,
OB_ALL_AUX_STAT_AUX_LOB_META_TNAME,
OB_ALL_TABLE_AUX_LOB_PIECE_TNAME,
OB_ALL_COLUMN_AUX_LOB_PIECE_TNAME,
OB_ALL_DDL_OPERATION_AUX_LOB_PIECE_TNAME,
@ -9000,7 +9025,8 @@ const char* const tenant_space_table_names [] = {
OB_ALL_IMPORT_TABLE_JOB_AUX_LOB_PIECE_TNAME,
OB_ALL_IMPORT_TABLE_JOB_HISTORY_AUX_LOB_PIECE_TNAME,
OB_ALL_IMPORT_TABLE_TASK_AUX_LOB_PIECE_TNAME,
OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_PIECE_TNAME, };
OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_PIECE_TNAME,
OB_ALL_AUX_STAT_AUX_LOB_PIECE_TNAME, };
const uint64_t only_rs_vtables [] = {
OB_ALL_VIRTUAL_CORE_META_TABLE_TID,
@ -11589,6 +11615,14 @@ LOBMapping const lob_aux_table_mappings [] = {
ObInnerTableSchema::all_import_table_task_history_aux_lob_piece_schema
},
{
OB_ALL_AUX_STAT_TID,
OB_ALL_AUX_STAT_AUX_LOB_META_TID,
OB_ALL_AUX_STAT_AUX_LOB_PIECE_TID,
ObInnerTableSchema::all_aux_stat_aux_lob_meta_schema,
ObInnerTableSchema::all_aux_stat_aux_lob_piece_schema
},
};
static inline bool get_sys_table_lob_aux_table_id(const uint64_t tid, uint64_t& meta_tid, uint64_t& piece_tid)
@ -11626,12 +11660,12 @@ static inline int get_sys_table_lob_aux_schema(const uint64_t tid,
}
const int64_t OB_CORE_TABLE_COUNT = 4;
const int64_t OB_SYS_TABLE_COUNT = 261;
const int64_t OB_VIRTUAL_TABLE_COUNT = 742;
const int64_t OB_SYS_VIEW_COUNT = 789;
const int64_t OB_SYS_TENANT_TABLE_COUNT = 1797;
const int64_t OB_SYS_TABLE_COUNT = 262;
const int64_t OB_VIRTUAL_TABLE_COUNT = 744;
const int64_t OB_SYS_VIEW_COUNT = 792;
const int64_t OB_SYS_TENANT_TABLE_COUNT = 1803;
const int64_t OB_CORE_SCHEMA_VERSION = 1;
const int64_t OB_BOOTSTRAP_SCHEMA_VERSION = 1800;
const int64_t OB_BOOTSTRAP_SCHEMA_VERSION = 1806;
} // end namespace share
} // end namespace oceanbase

View File

@ -21,7 +21,7 @@ inner_lob_map_t inner_lob_map;
bool lob_mapping_init()
{
int ret = OB_SUCCESS;
if (OB_FAIL(inner_lob_map.create(264, ObModIds::OB_INNER_LOB_HASH_SET))) {
if (OB_FAIL(inner_lob_map.create(265, ObModIds::OB_INNER_LOB_HASH_SET))) {
SERVER_LOG(WARN, "fail to create inner lob map", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < ARRAYSIZEOF(lob_aux_table_mappings); ++i) {

View File

@ -28,6 +28,13 @@ bool vt_mapping_init()
tmp_vt_mapping.is_real_vt_ = true;
}
{
int64_t idx = OB_ALL_VIRTUAL_AUX_STAT_REAL_AGENT_ORA_TID - start_idx;
VTMapping &tmp_vt_mapping = vt_mappings[idx];
tmp_vt_mapping.mapping_tid_ = OB_ALL_AUX_STAT_TID;
tmp_vt_mapping.is_real_vt_ = true;
}
{
int64_t idx = OB_ALL_VIRTUAL_BALANCE_JOB_HISTORY_REAL_AGENT_ORA_TID - start_idx;
VTMapping &tmp_vt_mapping = vt_mappings[idx];

View File

@ -292,6 +292,7 @@ const uint64_t OB_ALL_IMPORT_TABLE_JOB_TID = 477; // "__all_import_table_job"
const uint64_t OB_ALL_IMPORT_TABLE_JOB_HISTORY_TID = 478; // "__all_import_table_job_history"
const uint64_t OB_ALL_IMPORT_TABLE_TASK_TID = 479; // "__all_import_table_task"
const uint64_t OB_ALL_IMPORT_TABLE_TASK_HISTORY_TID = 480; // "__all_import_table_task_history"
const uint64_t OB_ALL_AUX_STAT_TID = 494; // "__all_aux_stat"
const uint64_t OB_TENANT_VIRTUAL_ALL_TABLE_TID = 10001; // "__tenant_virtual_all_table"
const uint64_t OB_TENANT_VIRTUAL_TABLE_COLUMN_TID = 10002; // "__tenant_virtual_table_column"
const uint64_t OB_TENANT_VIRTUAL_TABLE_INDEX_TID = 10003; // "__tenant_virtual_table_index"
@ -695,6 +696,7 @@ const uint64_t OB_ALL_VIRTUAL_IMPORT_TABLE_JOB_TID = 12424; // "__all_virtual_im
const uint64_t OB_ALL_VIRTUAL_IMPORT_TABLE_JOB_HISTORY_TID = 12425; // "__all_virtual_import_table_job_history"
const uint64_t OB_ALL_VIRTUAL_IMPORT_TABLE_TASK_TID = 12426; // "__all_virtual_import_table_task"
const uint64_t OB_ALL_VIRTUAL_IMPORT_TABLE_TASK_HISTORY_TID = 12427; // "__all_virtual_import_table_task_history"
const uint64_t OB_ALL_VIRTUAL_AUX_STAT_TID = 12447; // "__all_virtual_aux_stat"
const uint64_t OB_ALL_VIRTUAL_SQL_AUDIT_ORA_TID = 15009; // "ALL_VIRTUAL_SQL_AUDIT_ORA"
const uint64_t OB_ALL_VIRTUAL_PLAN_STAT_ORA_TID = 15010; // "ALL_VIRTUAL_PLAN_STAT_ORA"
const uint64_t OB_ALL_VIRTUAL_PLAN_CACHE_PLAN_EXPLAIN_ORA_TID = 15012; // "ALL_VIRTUAL_PLAN_CACHE_PLAN_EXPLAIN_ORA"
@ -943,6 +945,7 @@ const uint64_t OB_ALL_VIRTUAL_IMPORT_TABLE_JOB_HISTORY_ORA_TID = 15410; // "ALL_
const uint64_t OB_ALL_VIRTUAL_IMPORT_TABLE_TASK_ORA_TID = 15411; // "ALL_VIRTUAL_IMPORT_TABLE_TASK_ORA"
const uint64_t OB_ALL_VIRTUAL_IMPORT_TABLE_TASK_HISTORY_ORA_TID = 15412; // "ALL_VIRTUAL_IMPORT_TABLE_TASK_HISTORY_ORA"
const uint64_t OB_ALL_VIRTUAL_LS_INFO_ORA_TID = 15414; // "ALL_VIRTUAL_LS_INFO_ORA"
const uint64_t OB_ALL_VIRTUAL_AUX_STAT_REAL_AGENT_ORA_TID = 15427; // "ALL_VIRTUAL_AUX_STAT_REAL_AGENT_ORA"
const uint64_t OB_GV_OB_PLAN_CACHE_STAT_TID = 20001; // "GV$OB_PLAN_CACHE_STAT"
const uint64_t OB_GV_OB_PLAN_CACHE_PLAN_STAT_TID = 20002; // "GV$OB_PLAN_CACHE_PLAN_STAT"
const uint64_t OB_SCHEMATA_TID = 20003; // "SCHEMATA"
@ -1310,6 +1313,8 @@ const uint64_t OB_CDB_OB_IMPORT_TABLE_TASK_HISTORY_TID = 21473; // "CDB_OB_IMPOR
const uint64_t OB_DBA_OB_IMPORT_TABLE_TASK_HISTORY_TID = 21474; // "DBA_OB_IMPORT_TABLE_TASK_HISTORY"
const uint64_t OB_GV_OB_TENANT_RUNTIME_INFO_TID = 21477; // "GV$OB_TENANT_RUNTIME_INFO"
const uint64_t OB_V_OB_TENANT_RUNTIME_INFO_TID = 21478; // "V$OB_TENANT_RUNTIME_INFO"
const uint64_t OB_DBA_OB_AUX_STATISTICS_TID = 21497; // "DBA_OB_AUX_STATISTICS"
const uint64_t OB_CDB_OB_AUX_STATISTICS_TID = 21498; // "CDB_OB_AUX_STATISTICS"
const uint64_t OB_DBA_SYNONYMS_TID = 25001; // "DBA_SYNONYMS"
const uint64_t OB_DBA_OBJECTS_ORA_TID = 25002; // "DBA_OBJECTS_ORA"
const uint64_t OB_ALL_OBJECTS_TID = 25003; // "ALL_OBJECTS"
@ -1732,6 +1737,7 @@ const uint64_t OB_V_OB_ARBITRATION_SERVICE_STATUS_ORA_TID = 28192; // "V$OB_ARBI
const uint64_t OB_V_OB_TIMESTAMP_SERVICE_ORA_TID = 28193; // "V$OB_TIMESTAMP_SERVICE_ORA"
const uint64_t OB_V_OB_LS_LOG_RESTORE_STATUS_ORA_TID = 28194; // "V$OB_LS_LOG_RESTORE_STATUS_ORA"
const uint64_t OB_GV_OB_FLT_TRACE_CONFIG_ORA_TID = 28195; // "GV$OB_FLT_TRACE_CONFIG_ORA"
const uint64_t OB_DBA_OB_AUX_STATISTICS_ORA_TID = 28210; // "DBA_OB_AUX_STATISTICS_ORA"
const uint64_t OB_ALL_TABLE_AUX_LOB_META_TID = 50003; // "__all_table_aux_lob_meta"
const uint64_t OB_ALL_COLUMN_AUX_LOB_META_TID = 50004; // "__all_column_aux_lob_meta"
const uint64_t OB_ALL_DDL_OPERATION_AUX_LOB_META_TID = 50005; // "__all_ddl_operation_aux_lob_meta"
@ -1996,6 +2002,7 @@ const uint64_t OB_ALL_IMPORT_TABLE_JOB_AUX_LOB_META_TID = 50477; // "__all_impor
const uint64_t OB_ALL_IMPORT_TABLE_JOB_HISTORY_AUX_LOB_META_TID = 50478; // "__all_import_table_job_history_aux_lob_meta"
const uint64_t OB_ALL_IMPORT_TABLE_TASK_AUX_LOB_META_TID = 50479; // "__all_import_table_task_aux_lob_meta"
const uint64_t OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_META_TID = 50480; // "__all_import_table_task_history_aux_lob_meta"
const uint64_t OB_ALL_AUX_STAT_AUX_LOB_META_TID = 50494; // "__all_aux_stat_aux_lob_meta"
const uint64_t OB_ALL_TABLE_AUX_LOB_PIECE_TID = 60003; // "__all_table_aux_lob_piece"
const uint64_t OB_ALL_COLUMN_AUX_LOB_PIECE_TID = 60004; // "__all_column_aux_lob_piece"
const uint64_t OB_ALL_DDL_OPERATION_AUX_LOB_PIECE_TID = 60005; // "__all_ddl_operation_aux_lob_piece"
@ -2260,6 +2267,7 @@ const uint64_t OB_ALL_IMPORT_TABLE_JOB_AUX_LOB_PIECE_TID = 60477; // "__all_impo
const uint64_t OB_ALL_IMPORT_TABLE_JOB_HISTORY_AUX_LOB_PIECE_TID = 60478; // "__all_import_table_job_history_aux_lob_piece"
const uint64_t OB_ALL_IMPORT_TABLE_TASK_AUX_LOB_PIECE_TID = 60479; // "__all_import_table_task_aux_lob_piece"
const uint64_t OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_PIECE_TID = 60480; // "__all_import_table_task_history_aux_lob_piece"
const uint64_t OB_ALL_AUX_STAT_AUX_LOB_PIECE_TID = 60494; // "__all_aux_stat_aux_lob_piece"
const uint64_t OB_ALL_VIRTUAL_PLAN_CACHE_STAT_ALL_VIRTUAL_PLAN_CACHE_STAT_I1_TID = 14999; // "__all_virtual_plan_cache_stat"
const uint64_t OB_ALL_VIRTUAL_SESSION_EVENT_ALL_VIRTUAL_SESSION_EVENT_I1_TID = 14998; // "__all_virtual_session_event"
const uint64_t OB_ALL_VIRTUAL_SESSION_WAIT_ALL_VIRTUAL_SESSION_WAIT_I1_TID = 14997; // "__all_virtual_session_wait"
@ -2715,6 +2723,7 @@ const char *const OB_ALL_IMPORT_TABLE_JOB_TNAME = "__all_import_table_job";
const char *const OB_ALL_IMPORT_TABLE_JOB_HISTORY_TNAME = "__all_import_table_job_history";
const char *const OB_ALL_IMPORT_TABLE_TASK_TNAME = "__all_import_table_task";
const char *const OB_ALL_IMPORT_TABLE_TASK_HISTORY_TNAME = "__all_import_table_task_history";
const char *const OB_ALL_AUX_STAT_TNAME = "__all_aux_stat";
const char *const OB_TENANT_VIRTUAL_ALL_TABLE_TNAME = "__tenant_virtual_all_table";
const char *const OB_TENANT_VIRTUAL_TABLE_COLUMN_TNAME = "__tenant_virtual_table_column";
const char *const OB_TENANT_VIRTUAL_TABLE_INDEX_TNAME = "__tenant_virtual_table_index";
@ -3118,6 +3127,7 @@ const char *const OB_ALL_VIRTUAL_IMPORT_TABLE_JOB_TNAME = "__all_virtual_import_
const char *const OB_ALL_VIRTUAL_IMPORT_TABLE_JOB_HISTORY_TNAME = "__all_virtual_import_table_job_history";
const char *const OB_ALL_VIRTUAL_IMPORT_TABLE_TASK_TNAME = "__all_virtual_import_table_task";
const char *const OB_ALL_VIRTUAL_IMPORT_TABLE_TASK_HISTORY_TNAME = "__all_virtual_import_table_task_history";
const char *const OB_ALL_VIRTUAL_AUX_STAT_TNAME = "__all_virtual_aux_stat";
const char *const OB_ALL_VIRTUAL_SQL_AUDIT_ORA_TNAME = "ALL_VIRTUAL_SQL_AUDIT";
const char *const OB_ALL_VIRTUAL_PLAN_STAT_ORA_TNAME = "ALL_VIRTUAL_PLAN_STAT";
const char *const OB_ALL_VIRTUAL_PLAN_CACHE_PLAN_EXPLAIN_ORA_TNAME = "ALL_VIRTUAL_PLAN_CACHE_PLAN_EXPLAIN";
@ -3366,6 +3376,7 @@ const char *const OB_ALL_VIRTUAL_IMPORT_TABLE_JOB_HISTORY_ORA_TNAME = "ALL_VIRTU
const char *const OB_ALL_VIRTUAL_IMPORT_TABLE_TASK_ORA_TNAME = "ALL_VIRTUAL_IMPORT_TABLE_TASK";
const char *const OB_ALL_VIRTUAL_IMPORT_TABLE_TASK_HISTORY_ORA_TNAME = "ALL_VIRTUAL_IMPORT_TABLE_TASK_HISTORY";
const char *const OB_ALL_VIRTUAL_LS_INFO_ORA_TNAME = "ALL_VIRTUAL_LS_INFO";
const char *const OB_ALL_VIRTUAL_AUX_STAT_REAL_AGENT_ORA_TNAME = "ALL_VIRTUAL_AUX_STAT_REAL_AGENT";
const char *const OB_GV_OB_PLAN_CACHE_STAT_TNAME = "GV$OB_PLAN_CACHE_STAT";
const char *const OB_GV_OB_PLAN_CACHE_PLAN_STAT_TNAME = "GV$OB_PLAN_CACHE_PLAN_STAT";
const char *const OB_SCHEMATA_TNAME = "SCHEMATA";
@ -3733,6 +3744,8 @@ const char *const OB_CDB_OB_IMPORT_TABLE_TASK_HISTORY_TNAME = "CDB_OB_IMPORT_TAB
const char *const OB_DBA_OB_IMPORT_TABLE_TASK_HISTORY_TNAME = "DBA_OB_IMPORT_TABLE_TASK_HISTORY";
const char *const OB_GV_OB_TENANT_RUNTIME_INFO_TNAME = "GV$OB_TENANT_RUNTIME_INFO";
const char *const OB_V_OB_TENANT_RUNTIME_INFO_TNAME = "V$OB_TENANT_RUNTIME_INFO";
const char *const OB_DBA_OB_AUX_STATISTICS_TNAME = "DBA_OB_AUX_STATISTICS";
const char *const OB_CDB_OB_AUX_STATISTICS_TNAME = "CDB_OB_AUX_STATISTICS";
const char *const OB_DBA_SYNONYMS_TNAME = "DBA_SYNONYMS";
const char *const OB_DBA_OBJECTS_ORA_TNAME = "DBA_OBJECTS";
const char *const OB_ALL_OBJECTS_TNAME = "ALL_OBJECTS";
@ -4155,6 +4168,7 @@ const char *const OB_V_OB_ARBITRATION_SERVICE_STATUS_ORA_TNAME = "V$OB_ARBITRATI
const char *const OB_V_OB_TIMESTAMP_SERVICE_ORA_TNAME = "V$OB_TIMESTAMP_SERVICE";
const char *const OB_V_OB_LS_LOG_RESTORE_STATUS_ORA_TNAME = "V$OB_LS_LOG_RESTORE_STATUS";
const char *const OB_GV_OB_FLT_TRACE_CONFIG_ORA_TNAME = "GV$OB_FLT_TRACE_CONFIG";
const char *const OB_DBA_OB_AUX_STATISTICS_ORA_TNAME = "DBA_OB_AUX_STATISTICS";
const char *const OB_ALL_TABLE_AUX_LOB_META_TNAME = "__all_table_aux_lob_meta";
const char *const OB_ALL_COLUMN_AUX_LOB_META_TNAME = "__all_column_aux_lob_meta";
const char *const OB_ALL_DDL_OPERATION_AUX_LOB_META_TNAME = "__all_ddl_operation_aux_lob_meta";
@ -4419,6 +4433,7 @@ const char *const OB_ALL_IMPORT_TABLE_JOB_AUX_LOB_META_TNAME = "__all_import_tab
const char *const OB_ALL_IMPORT_TABLE_JOB_HISTORY_AUX_LOB_META_TNAME = "__all_import_table_job_history_aux_lob_meta";
const char *const OB_ALL_IMPORT_TABLE_TASK_AUX_LOB_META_TNAME = "__all_import_table_task_aux_lob_meta";
const char *const OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_META_TNAME = "__all_import_table_task_history_aux_lob_meta";
const char *const OB_ALL_AUX_STAT_AUX_LOB_META_TNAME = "__all_aux_stat_aux_lob_meta";
const char *const OB_ALL_TABLE_AUX_LOB_PIECE_TNAME = "__all_table_aux_lob_piece";
const char *const OB_ALL_COLUMN_AUX_LOB_PIECE_TNAME = "__all_column_aux_lob_piece";
const char *const OB_ALL_DDL_OPERATION_AUX_LOB_PIECE_TNAME = "__all_ddl_operation_aux_lob_piece";
@ -4683,6 +4698,7 @@ const char *const OB_ALL_IMPORT_TABLE_JOB_AUX_LOB_PIECE_TNAME = "__all_import_ta
const char *const OB_ALL_IMPORT_TABLE_JOB_HISTORY_AUX_LOB_PIECE_TNAME = "__all_import_table_job_history_aux_lob_piece";
const char *const OB_ALL_IMPORT_TABLE_TASK_AUX_LOB_PIECE_TNAME = "__all_import_table_task_aux_lob_piece";
const char *const OB_ALL_IMPORT_TABLE_TASK_HISTORY_AUX_LOB_PIECE_TNAME = "__all_import_table_task_history_aux_lob_piece";
const char *const OB_ALL_AUX_STAT_AUX_LOB_PIECE_TNAME = "__all_aux_stat_aux_lob_piece";
const char *const OB_ALL_VIRTUAL_PLAN_CACHE_STAT_ALL_VIRTUAL_PLAN_CACHE_STAT_I1_TNAME = "__idx_11003_all_virtual_plan_cache_stat_i1";
const char *const OB_ALL_VIRTUAL_SESSION_EVENT_ALL_VIRTUAL_SESSION_EVENT_I1_TNAME = "__idx_11013_all_virtual_session_event_i1";
const char *const OB_ALL_VIRTUAL_SESSION_WAIT_ALL_VIRTUAL_SESSION_WAIT_I1_TNAME = "__idx_11014_all_virtual_session_wait_i1";

View File

@ -6370,7 +6370,26 @@ def_table_schema(
# 491 : __all_routine_privilege_history
# 492 : __wr_sqlstat
# 493 : __all_ncomp_dll
# 494 : __all_aux_stat
def_table_schema(
owner = 'zhenling.zzg',
table_name = '__all_aux_stat',
table_id = '494',
table_type = 'SYSTEM_TABLE',
gm_columns = ['gmt_create', 'gmt_modified'],
rowkey_columns = [
('tenant_id', 'bigint'),
],
in_tenant_space = True,
is_cluster_private = False,
normal_columns = [
('last_analyzed', 'timestamp'),
('cpu_speed', 'bigint', 'true', '2500'),
('disk_seq_read_speed', 'bigint', 'true', '2000'),
('disk_rnd_read_speed', 'bigint', 'true', '150'),
('network_speed', 'bigint', '1000')
],
)
# 495 : __all_index_usage_info
# 496 : __all_detect_lock_info
# 497 : __all_client_to_server_session_info
@ -6386,9 +6405,6 @@ def_table_schema(
#
# 余留位置
################################################################################
# Virtual Table (10000, 20000]
# Normally, virtual table's index_using_type should be USING_HASH.
################################################################################
@ -13185,7 +13201,10 @@ def_table_schema(**gen_iterate_private_virtual_table_def(
# 12444: __all_virtual_routine_privilege_history
# 12445: __all_virtual_sqlstat
# 12446: __all_virtual_wr_sqlstat
# 12447 : __all_virtual_aux_stat
def_table_schema(**gen_iterate_virtual_table_def(
table_id = '12447',
table_name = '__all_virtual_aux_stat',
keywords = all_def_keywords['__all_aux_stat']))
# 12448: __all_virtual_detect_lock_info
# 12449: __all_virtual_client_to_server_session_info
# 12450: __all_virtual_sys_variable_default_value
@ -13611,7 +13630,7 @@ def_table_schema(**gen_oracle_mapping_virtual_table_def('15414', all_def_keyword
# 15424: __all_virtual_sqlstat
# 15425: __all_virtual_wr_sqlstat
# def_table_schema(**no_direct_access(gen_oracle_mapping_virtual_table_def('15426', all_def_keywords['__tenant_virtual_statname'])))
# 15427: __all_virtual_aux_stat
def_table_schema(**gen_oracle_mapping_real_virtual_table_def('15427', all_def_keywords['__all_aux_stat']))
# 15428: __all_virtual_sys_variable
# 15429: __all_virtual_sys_variable_default_value
# 15430: __all_transfer_partition_task
@ -30253,8 +30272,48 @@ def_table_schema(
#21494 V$SYS_TIME_MODEL
#21495 DBA_WR_SYS_TIME_MODEL
#21496 CDB_WR_SYS_TIME_MODEL
#21497 DBA_OB_AUX_STATISTICS
#21498 CDB_OB_AUX_STATISTICS
def_table_schema(
owner = 'zhenling.zzg',
table_name = 'DBA_OB_AUX_STATISTICS',
table_id = '21497',
table_type = 'SYSTEM_VIEW',
rowkey_columns = [],
normal_columns = [],
gm_columns = [],
in_tenant_space = True,
view_definition = """
select
LAST_ANALYZED,
CPU_SPEED AS `CPU_SPEED(MHZ)`,
DISK_SEQ_READ_SPEED AS `DISK_SEQ_READ_SPEED(MB/S)`,
DISK_RND_READ_SPEED AS `DISK_RND_READ_SPEED(MB/S)`,
NETWORK_SPEED AS `NETWORK_SPEED(MB/S)`
from oceanbase.__all_aux_stat;
""".replace("\n", " ")
)
def_table_schema(
owner = 'zhenling.zzg',
table_name = 'CDB_OB_AUX_STATISTICS',
table_id = '21498',
table_type = 'SYSTEM_VIEW',
rowkey_columns = [],
normal_columns = [],
gm_columns = [],
in_tenant_space = False,
view_definition = """
select
TENANT_ID,
LAST_ANALYZED,
CPU_SPEED AS `CPU_SPEED(MHZ)`,
DISK_SEQ_READ_SPEED AS `DISK_SEQ_READ_SPEED(MB/S)`,
DISK_RND_READ_SPEED AS `DISK_RND_READ_SPEED(MB/S)`,
NETWORK_SPEED AS `NETWORK_SPEED(MB/S)`
from oceanbase.__all_virtual_aux_stat;
""".replace("\n", " ")
)
#21499 DBA_OB_INDEX_USAGE
#21500 DBA_OB_SYS_VARIABLES
#21501 DBA_OB_TRANSFER_PARTITION_TASKS
@ -54932,7 +54991,29 @@ def_table_schema(
# 28207: GV$SYS_TIME_MODEL
# 28208: V$SYS_TIME_MODEL
# 28209: V$STATNAME
# 28210: DBA_OB_AUX_STATISTICS
def_table_schema(
owner = 'zhenling.zzg',
table_name = 'DBA_OB_AUX_STATISTICS',
name_postfix = '_ORA',
database_id = 'OB_ORA_SYS_DATABASE_ID',
table_id = '28210',
table_type = 'SYSTEM_VIEW',
rowkey_columns = [],
normal_columns = [],
gm_columns = [],
in_tenant_space = True,
view_definition = """
SELECT
LAST_ANALYZED,
CPU_SPEED AS \"CPU_SPEED(MHZ)\",
DISK_SEQ_READ_SPEED AS \"DISK_SEQ_READ_SPEED(MB/S)\",
DISK_RND_READ_SPEED AS \"DISK_RND_READ_SPEED(MB/S)\",
NETWORK_SPEED AS \"NETWORK_SPEED(MB/S)\"
FROM SYS.ALL_VIRTUAL_AUX_STAT_REAL_AGENT
WHERE TENANT_ID = EFFECTIVE_TENANT_ID();
""".replace("\n", " ")
)
# 28211: DBA_OB_SYS_VARIABLES
# 28212: GV$OB_ACTIVE_SESSION_HISTORY
# 28213: V$OB_ACTIVE_SESSION_HISTORY

View File

@ -1637,6 +1637,7 @@ case OB_ALL_VIRTUAL_ZONE_MERGE_INFO_TID:
#ifdef ITERATE_VIRTUAL_TABLE_LOCATION_SWITCH
case OB_ALL_VIRTUAL_AUTO_INCREMENT_TID:
case OB_ALL_VIRTUAL_AUX_STAT_TID:
case OB_ALL_VIRTUAL_BALANCE_JOB_TID:
case OB_ALL_VIRTUAL_BALANCE_JOB_HISTORY_TID:
case OB_ALL_VIRTUAL_BALANCE_TASK_TID:
@ -1809,6 +1810,21 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
break;
}
case OB_ALL_VIRTUAL_AUX_STAT_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
SERVER_LOG(WARN, "create virtual table iterator failed", K(ret));
} else if (OB_FAIL(iter->init(OB_ALL_AUX_STAT_TID, index_schema, params))) {
SERVER_LOG(WARN, "virtual table iter init failed", K(ret));
iter->~ObIterateVirtualTable();
allocator.free(iter);
iter = NULL;
} else {
vt_iter = iter;
}
break;
}
case OB_ALL_VIRTUAL_BALANCE_JOB_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -2078,7 +2094,9 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_DAM_LAST_ARCH_TS_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -2093,9 +2111,7 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_DATA_DICTIONARY_IN_LOG_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -2380,7 +2396,9 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_FOREIGN_KEY_HISTORY_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -2395,9 +2413,7 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_FREEZE_INFO_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -2682,7 +2698,9 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_OUTLINE_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -2697,9 +2715,7 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_OUTLINE_HISTORY_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -2984,7 +3000,9 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_RLS_SECURITY_COLUMN_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -2999,9 +3017,7 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_RLS_SECURITY_COLUMN_HISTORY_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -3286,7 +3302,9 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_SYSAUTH_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -3301,9 +3319,7 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_SYSAUTH_HISTORY_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -3588,7 +3604,9 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_TENANT_OLS_COMPONENT_HISTORY_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -3603,9 +3621,7 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_TENANT_OLS_LABEL_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -3890,7 +3906,9 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_TIME_ZONE_TRANSITION_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {
@ -3905,9 +3923,7 @@ case OB_ALL_VIRTUAL_USER_HISTORY_TID:
}
break;
}
END_CREATE_VT_ITER_SWITCH_LAMBDA
BEGIN_CREATE_VT_ITER_SWITCH_LAMBDA
case OB_ALL_VIRTUAL_TIME_ZONE_TRANSITION_TYPE_TID: {
ObIterateVirtualTable *iter = NULL;
if (OB_FAIL(NEW_VIRTUAL_TABLE(ObIterateVirtualTable, iter))) {

View File

@ -431,4 +431,16 @@ CREATE OR REPLACE PACKAGE BODY dbms_stats
);
PRAGMA INTERFACE(C, DELETE_TABLE_PREFS);
PROCEDURE GATHER_SYSTEM_STATS();
PRAGMA INTERFACE(C, GATHER_SYSTEM_STATS);
PROCEDURE DELETE_SYSTEM_STATS();
PRAGMA INTERFACE(C, DELETE_SYSTEM_STATS);
PROCEDURE SET_SYSTEM_STATS (
pname VARCHAR(65535),
pvalue DECIMAL
);
PRAGMA INTERFACE(C, SET_SYSTEM_STATS);
END dbms_stats;

View File

@ -388,4 +388,13 @@ create or replace PACKAGE dbms_stats AUTHID CURRENT_USER
pname VARCHAR(65535)
);
PROCEDURE GATHER_SYSTEM_STATS();
PROCEDURE DELETE_SYSTEM_STATS();
PROCEDURE SET_SYSTEM_STATS (
pname VARCHAR(65535),
pvalue DECIMAL
);
END dbms_stats;

View File

@ -23,6 +23,8 @@
#include "share/stat/ob_index_stats_estimator.h"
#include "pl/sys_package/ob_dbms_stats.h"
#include "share/stat/ob_opt_stat_gather_stat.h"
#include "src/observer/ob_server.h"
namespace oceanbase {
using namespace pl;
namespace common {
@ -869,6 +871,79 @@ int ObDbmsStatsExecutor::update_online_stat(ObExecContext &ctx,
return ret;
}
int ObDbmsStatsExecutor::gather_system_stats(ObExecContext &ctx, int64_t tenant_id)
{
int ret = OB_SUCCESS;
UNUSED(ctx);
int64_t cpu_mhz = OBSERVER.get_cpu_frequency_khz()/1000;
int64_t network_speed = OBSERVER.get_network_speed() / 1024.0 / 1024.0;
int64_t disk_seq_read_speed = 0;
int64_t disk_rnd_read_speed = 0;
OptSystemIoBenchmark &io_benchmark = OptSystemIoBenchmark::get_instance();
if (io_benchmark.is_init()) {
disk_seq_read_speed = io_benchmark.get_disk_seq_read_speed();
disk_rnd_read_speed = io_benchmark.get_disk_rnd_read_speed();
} else if (OB_FAIL(io_benchmark.run_benchmark(ctx.get_allocator()))) {
LOG_WARN("failed to run io benchmark", K(ret));
} else {
disk_seq_read_speed = io_benchmark.get_disk_seq_read_speed();
disk_rnd_read_speed = io_benchmark.get_disk_rnd_read_speed();
}
if (OB_SUCC(ret)) {
ObOptSystemStat system_stat;
ObOptStatManager &mgr = ObOptStatManager::get_instance();
int64_t current_time = ObTimeUtility::current_time();
system_stat.set_last_analyzed(current_time);
system_stat.set_cpu_speed(cpu_mhz);
system_stat.set_disk_seq_read_speed(disk_seq_read_speed);
system_stat.set_disk_rnd_read_speed(disk_rnd_read_speed);
system_stat.set_network_speed(network_speed);
if (OB_FAIL(mgr.update_system_stats(tenant_id,
&system_stat))) {
LOG_WARN("failed to update system stats", K(ret));
}
}
return ret;
}
int ObDbmsStatsExecutor::delete_system_stats(ObExecContext &ctx, int64_t tenant_id)
{
int ret = OB_SUCCESS;
UNUSED(ctx);
ObOptStatManager &mgr = ObOptStatManager::get_instance();
if (OB_FAIL(mgr.delete_system_stats(tenant_id))) {
LOG_WARN("failed to delete system stats", K(ret));
}
return ret;
}
int ObDbmsStatsExecutor::set_system_stats(ObExecContext &ctx, const ObSetSystemStatParam &param)
{
int ret = OB_SUCCESS;
UNUSED(ctx);
ObOptSystemStat system_stat;
ObOptStatManager &mgr = ObOptStatManager::get_instance();
if (OB_FAIL(mgr.get_system_stat(param.tenant_id_, system_stat))) {
LOG_WARN("failed to get table stat", K(ret));
} else if (ObCharset::case_insensitive_equal(param.name_, "cpu_speed")) {
system_stat.set_cpu_speed(param.value_);
} else if (ObCharset::case_insensitive_equal(param.name_, "disk_seq_read_speed")) {
system_stat.set_disk_seq_read_speed(param.value_);
} else if (ObCharset::case_insensitive_equal(param.name_, "disk_rnd_read_speed")) {
system_stat.set_disk_rnd_read_speed(param.value_);
} else if (ObCharset::case_insensitive_equal(param.name_, "network_speed")) {
system_stat.set_network_speed(param.value_);
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(mgr.update_system_stats(param.tenant_id_,
&system_stat))) {
LOG_WARN("failed to update system stats", K(ret));
} else {
LOG_TRACE("end set system stats", K(param), K(system_stat));
}
return ret;
}
} // namespace common
} // namespace oceanbase

View File

@ -51,6 +51,13 @@ public:
share::schema::ObSchemaGetterGuard *schema_guard,
const TabStatIndMap &online_table_stats,
const ColStatIndMap &online_column_stats);
static int gather_system_stats(ObExecContext &ctx, int64_t tenant_id);
static int delete_system_stats(ObExecContext &ctx, int64_t tenant_id);
static int set_system_stats(ObExecContext &ctx, const ObSetSystemStatParam &param);
private:
static int do_gather_stats(ObExecContext &ctx,

View File

@ -109,7 +109,11 @@ void ObOptStatManager::destroy()
int ObOptStatManager::add_refresh_stat_task(const obrpc::ObUpdateStatCacheArg &analyze_arg)
{
int ret = OB_SUCCESS;
if (OB_FAIL(handle_refresh_stat_task(analyze_arg))) {
if (analyze_arg.update_system_stats_only_) {
if (OB_FAIL(handle_refresh_system_stat_task(analyze_arg))) {
LOG_WARN("failed to handle refresh system stat cache", K(ret));
}
} else if (OB_FAIL(handle_refresh_stat_task(analyze_arg))) {
LOG_WARN("failed to handld refresh stat task", K(ret));
}
return ret;
@ -419,7 +423,7 @@ int ObOptStatManager::handle_refresh_stat_task(const obrpc::ObUpdateStatCacheArg
{
int ret = OB_SUCCESS;
uint64_t table_id = arg.table_id_;
for (int64_t i = 0; OB_SUCC(ret) && i < arg.partition_ids_.count(); ++i) {
for (int64_t i = 0; OB_SUCC(ret) && i < arg.partition_ids_.count(); ++i) {
ObOptTableStat::Key table_key(arg.tenant_id_,
table_id,
arg.partition_ids_.at(i));
@ -444,6 +448,31 @@ int ObOptStatManager::handle_refresh_stat_task(const obrpc::ObUpdateStatCacheArg
return ret;
}
int ObOptStatManager::handle_refresh_system_stat_task(const obrpc::ObUpdateStatCacheArg &arg)
{
int ret = OB_SUCCESS;
ObOptSystemStat::Key key(arg.tenant_id_);
if (OB_FAIL(stat_service_.erase_system_stat(key))) {
if (OB_ENTRY_NOT_EXIST != ret) {
LOG_WARN("failed to erase system stat", K(ret));
} else {
ret = OB_SUCCESS;
LOG_TRACE("failed to erase system stat", K(key));
}
}
if (OB_SUCC(ret)) {
MTL_SWITCH(arg.tenant_id_) {
sql::ObPlanCache *pc = MTL(sql::ObPlanCache*);
if (OB_FAIL(pc->flush_plan_cache())) {
LOG_WARN("failed to evict plan", K(ret));
// use OB_SQL_PC_NOT_EXIST represent evict plan failed
ret = OB_SQL_PC_NOT_EXIST;
}
}
}
return ret;
}
int ObOptStatManager::invalidate_plan(const uint64_t tenant_id, const uint64_t table_id)
{
int ret = OB_SUCCESS;
@ -560,6 +589,30 @@ int ObOptStatManager::check_opt_stat_validity(sql::ObExecContext &ctx,
return ret;
}
int ObOptStatManager::check_system_stat_validity(sql::ObExecContext *ctx,
const uint64_t tenant_id,
bool &is_valid)
{
int ret = OB_SUCCESS;
const share::schema::ObTableSchema *table_schema = NULL;
is_valid = false;
if (OB_ISNULL(ctx) ||
OB_ISNULL(ctx->get_virtual_table_ctx().schema_guard_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (OB_FAIL(ctx->get_virtual_table_ctx().schema_guard_->get_table_schema(
tenant_id,
share::OB_ALL_AUX_STAT_TID,
table_schema))) {
LOG_WARN("failed to get table schema", K(ret), K(table_schema));
} else if (OB_ISNULL(table_schema)) {
//do nothing
} else {
is_valid = true;
}
return ret;
}
int ObOptStatManager::get_table_stat(const uint64_t tenant_id,
const uint64_t table_ref_id,
const int64_t part_id,
@ -773,5 +826,45 @@ int ObOptStatManager::update_opt_stat_task_stat(const ObOptStatTaskInfo &task_in
return stat_service_.get_sql_service().update_opt_stat_task_stat(task_info);
}
int ObOptStatManager::get_system_stat(const uint64_t tenant_id,
ObOptSystemStat &stat)
{
int ret = OB_SUCCESS;
ObOptSystemStat::Key key(tenant_id);
if (!inited_) {
ret = OB_NOT_INIT;
LOG_WARN("optimizer statistics manager has not been initialized.", K(ret), K(inited_));
} else if (OB_FAIL(stat_service_.get_system_stat(tenant_id, key, stat))) {
LOG_WARN("get system stat failed", K(ret));
}
return ret;
}
int ObOptStatManager::update_system_stats(const uint64_t tenant_id,
const ObOptSystemStat *system_stats)
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(!inited_)) {
ret = OB_NOT_INIT;
LOG_WARN("not inited", K(ret));
} else if (OB_FAIL(stat_service_.get_sql_service().update_system_stats(tenant_id,
system_stats))) {
LOG_WARN("failed to update system stats", K(ret));
}
return ret;
}
int ObOptStatManager::delete_system_stats(const uint64_t tenant_id)
{
int ret = OB_SUCCESS;
if (!inited_) {
ret = OB_NOT_INIT;
LOG_WARN("optimizer statistics manager has not been initialized.", K(ret), K(inited_));
} else if (OB_FAIL(stat_service_.get_sql_service().delete_system_stats(tenant_id))) {
LOG_WARN("delete system stat failed", K(ret));
}
return ret;
}
}
}

View File

@ -23,6 +23,7 @@
#include "share/stat/ob_stat_define.h"
#include "share/stat/ob_opt_ds_stat.h"
#include "share/stat/ob_stat_item.h"
#include "share/stat/ob_opt_system_stat.h"
namespace oceanbase {
namespace common {
@ -50,6 +51,10 @@ public:
const ObIArray<int64_t> &part_ids,
bool &is_opt_stat_valid);
int check_system_stat_validity(sql::ObExecContext *ctx,
const uint64_t tenant_id,
bool &is_valid);
int check_opt_stat_validity(sql::ObExecContext &ctx,
const uint64_t tenant_id,
const uint64_t tab_ref_id,
@ -173,6 +178,8 @@ public:
int handle_refresh_stat_task(const obrpc::ObUpdateStatCacheArg &arg);
int handle_refresh_system_stat_task(const obrpc::ObUpdateStatCacheArg &arg);
int get_table_rowcnt(const uint64_t tenant_id,
const uint64_t table_id,
const ObIArray<ObTabletID> &all_tablet_ids,
@ -199,6 +206,11 @@ public:
ObOptDSStatHandle &ds_stat_handle);
int update_opt_stat_gather_stat(const ObOptStatGatherStat &gather_stat);
int update_opt_stat_task_stat(const ObOptStatTaskInfo &task_info);
int get_system_stat(const uint64_t tenant_id,
ObOptSystemStat &stat);
int update_system_stats(const uint64_t tenant_id,
const ObOptSystemStat *system_stats);
int delete_system_stats(const uint64_t tenant_id);
protected:
static const int64_t REFRESH_STAT_TASK_NUM = 5;
bool inited_;

View File

@ -247,6 +247,9 @@ int ObOptStatService::init(common::ObMySQLProxy *proxy, ObServerConfig *config)
} else if (OB_FAIL(ds_stat_cache_.init("opt_ds_stat_cache",
DEFAULT_DS_STAT_CACHE_PRIORITY))) {
LOG_WARN("fail to init table cache.", K(ret));
} else if (OB_FAIL(system_stat_cache_.init("opt_system_stat_cache",
DEFAULT_SYSTEM_STAT_CACHE_PRIORITY))) {
LOG_WARN("fail to init system stat cache.", K(ret));
} else {
inited_ = true;
}
@ -437,5 +440,64 @@ int ObOptStatService::erase_ds_stat(const ObOptDSStat::Key &key)
return ds_stat_cache_.erase(key);
}
int ObOptStatService::get_system_stat(const uint64_t tenant_id,
const ObOptSystemStat::Key &key,
ObOptSystemStat &stat)
{
int ret = OB_SUCCESS;
ObOptSystemStatHandle handle;
if (OB_UNLIKELY(!inited_)) {
ret = OB_NOT_INIT;
LOG_WARN("statistics service is not initialized. ", K(ret), K(key));
} else if (OB_FAIL(system_stat_cache_.get_value(key, handle))) {
// we need to fetch statistics from inner table if it is not yet available from cache
if (OB_ENTRY_NOT_EXIST != ret) {
LOG_WARN("get system stat from cache failed", K(ret), K(key));
} else if (OB_FAIL(load_system_stat_and_put_cache(tenant_id, key, handle))) {
LOG_WARN("load and put cache system stat failed.", K(ret), K(key));
}
}
if (OB_FAIL(ret)) {
// do nothing
} else if (OB_ISNULL(handle.stat_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("cache hit but value is NULL. BUG here.", K(ret), K(key));
} else {
stat = *handle.stat_;
}
return ret;
}
int ObOptStatService::load_system_stat_and_put_cache(const uint64_t tenant_id,
const ObOptSystemStat::Key &key,
ObOptSystemStatHandle &handle)
{
int ret = OB_SUCCESS;
ObOptSystemStat stat;
if (!inited_) {
ret = OB_NOT_INIT;
LOG_WARN("statistics service is not initialized. ", K(ret), K(key));
} else if (OB_FAIL(system_stat_cache_.put_and_fetch_value(key, stat, handle))) {
LOG_WARN("put and fetch table stat failed.", K(ret), K(key));
} else if (OB_FAIL(sql_service_.fetch_system_stat(tenant_id, key, stat))) {
system_stat_cache_.erase(key);
if (OB_ENTRY_NOT_EXIST != ret) {
LOG_WARN("fetch system stat failed. ", K(ret), K(key));
} else {
// it's not guaranteed that system stat exists.
stat.reset();
ret = OB_SUCCESS;
}
} else if (OB_FAIL(system_stat_cache_.put_and_fetch_value(key, stat, handle))) {
LOG_WARN("put and fetch table stat failed.", K(ret), K(key));
}
return ret;
}
int ObOptStatService::erase_system_stat(const ObOptSystemStat::Key &key)
{
return system_stat_cache_.erase(key);
}
}
}

View File

@ -19,6 +19,7 @@
#include "share/stat/ob_opt_stat_sql_service.h"
#include "share/stat/ob_opt_ds_stat.h"
#include "share/stat/ob_opt_ds_stat_cache.h"
#include "share/stat/ob_opt_system_stat_cache.h"
namespace oceanbase {
namespace common {
@ -60,6 +61,16 @@ public:
const ObIArray<share::ObLSID> &all_ls_ids,
int64_t &table_rowcnt);
int get_system_stat(const uint64_t tenant_id,
const ObOptSystemStat::Key &key,
ObOptSystemStat &stat);
int load_system_stat_and_put_cache(const uint64_t tenant_id,
const ObOptSystemStat::Key &key,
ObOptSystemStatHandle &handle);
int erase_system_stat(const ObOptSystemStat::Key &key);
private:
/**
* load_and_put_cache(key, handle)
@ -83,11 +94,13 @@ protected:
static const int64_t DEFAULT_TAB_STAT_CACHE_PRIORITY = 1;
static const int64_t DEFAULT_COL_STAT_CACHE_PRIORITY = 1;
static const int64_t DEFAULT_DS_STAT_CACHE_PRIORITY = 1;
static const int64_t DEFAULT_SYSTEM_STAT_CACHE_PRIORITY = 1;
ObOptStatSqlService sql_service_;
ObOptTableStatCache table_stat_cache_;
ObOptColumnStatCache column_stat_cache_;
ObOptDSStatCache ds_stat_cache_;
ObOptSystemStatCache system_stat_cache_;
};
}

View File

@ -299,6 +299,14 @@
"WHERE %.*s "\
"ORDER BY tenant_id, table_id, partition_id, column_id, endpoint_num;"
#define INSERT_SYSTEM_STAT_SQL "REPLACE INTO %s(tenant_id," \
"last_analyzed," \
"cpu_speed," \
"disk_seq_read_speed," \
"disk_rnd_read_speed," \
"network_speed) VALUES "
#define DELETE_SYSTEM_STAT_SQL "DELETE FROM %s WHERE TENANT_ID=%ld"
namespace oceanbase
{
@ -2255,6 +2263,155 @@ int ObOptStatSqlService::get_gather_stat_value(const ObOptStatGatherStat &gather
return ret;
}
int ObOptStatSqlService::update_system_stats(const uint64_t tenant_id,
const ObOptSystemStat *system_stat)
{
int ret = OB_SUCCESS;
ObSqlString system_stat_sql;
ObSqlString tmp;
int64_t current_time = ObTimeUtility::current_time();
int64_t affected_rows = 0;
if (OB_ISNULL(system_stat)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("table stat is null", K(ret), K(system_stat));
} else if (OB_FAIL(system_stat_sql.append_fmt(INSERT_SYSTEM_STAT_SQL, OB_ALL_AUX_STAT_TNAME))) {
LOG_WARN("failed to append sql", K(ret));
} else if (OB_FAIL(get_system_stat_sql(tenant_id, *system_stat, current_time, tmp))) {
LOG_WARN("failed to get table stat sql", K(ret));
} else if (OB_FAIL(system_stat_sql.append_fmt("(%s);", tmp.ptr()))) {
LOG_WARN("failed to append system stat sql", K(ret));
} else {
ObMySQLTransaction trans;
LOG_TRACE("sql string of system stat update", K(system_stat_sql));
if (OB_FAIL(trans.start(mysql_proxy_, tenant_id))) {
LOG_WARN("fail to start transaction", K(ret), K(tenant_id));
} else if (OB_FAIL(trans.write(tenant_id, system_stat_sql.ptr(), affected_rows))) {
LOG_WARN("failed to exec sql", K(ret));
} else {/*do nothing*/}
if (OB_SUCC(ret)) {
if (OB_FAIL(trans.end(true))) {
LOG_WARN("fail to commit transaction", K(ret));
}
} else {
int tmp_ret = OB_SUCCESS;
if (OB_SUCCESS != (tmp_ret = trans.end(false))) {
LOG_WARN("fail to roll back transaction", K(tmp_ret));
}
}
}
return ret;
}
int ObOptStatSqlService::get_system_stat_sql(const uint64_t tenant_id,
const ObOptSystemStat &stat,
const int64_t current_time,
ObSqlString &sql_string)
{
int ret = OB_SUCCESS;
share::ObDMLSqlSplicer dml_splicer;
uint64_t ext_tenant_id = ObSchemaUtils::get_extract_tenant_id(tenant_id, tenant_id);
if (OB_FAIL(dml_splicer.add_pk_column("tenant_id", ext_tenant_id)) ||
OB_FAIL(dml_splicer.add_time_column("last_analyzed", stat.get_last_analyzed() == 0 ?
current_time : stat.get_last_analyzed())) ||
OB_FAIL(dml_splicer.add_column("cpu_speed", stat.get_cpu_speed())) ||
OB_FAIL(dml_splicer.add_column("disk_seq_read_speed", stat.get_disk_seq_read_speed())) ||
OB_FAIL(dml_splicer.add_column("disk_rnd_read_speed", stat.get_disk_rnd_read_speed())) ||
OB_FAIL(dml_splicer.add_column("network_speed", stat.get_network_speed()))) {
LOG_WARN("failed to add dml splicer column", K(ret));
} else if (OB_FAIL(dml_splicer.splice_values(sql_string))) {
LOG_WARN("failed to get sql string", K(ret));
} else { /*do nothing*/ }
return ret;
}
int ObOptStatSqlService::fetch_system_stat(const uint64_t tenant_id,
const ObOptSystemStat::Key &key,
ObOptSystemStat &stat)
{
int ret = OB_SUCCESS;
uint64_t data_version = 0;
if (OB_FAIL(GET_MIN_DATA_VERSION(tenant_id, data_version))) {
LOG_WARN("failed to get data version", K(ret));
} else if (data_version >= DATA_VERSION_4_3_0_0) {
ObSQLClientRetryWeak sql_client_retry_weak(mysql_proxy_, false, OB_INVALID_TIMESTAMP, false);
int64_t ext_tenant_id = ObSchemaUtils::get_extract_tenant_id(tenant_id, tenant_id);
SMART_VAR(ObMySQLProxy::MySQLResult, res) {
sqlclient::ObMySQLResult *result = NULL;
ObSqlString sql;
uint64_t exec_tenant_id = ObSchemaUtils::get_exec_tenant_id(tenant_id);
if (!inited_) {
ret = OB_NOT_INIT;
LOG_WARN("sql service has not been initialized.", K(ret));
} else if (OB_FAIL(sql.append_fmt("SELECT * FROM %s ", share::OB_ALL_AUX_STAT_TNAME))) {
LOG_WARN("fail to append SQL stmt string.", K(sql), K(ret));
} else if (OB_FAIL(sql.append_fmt(" WHERE TENANT_ID = %ld", ext_tenant_id))) {
LOG_WARN("fail to append SQL where string.", K(ret));
} else if (OB_FAIL(sql_client_retry_weak.read(res, exec_tenant_id, sql.ptr()))) {
LOG_WARN("execute sql failed", "sql", sql.ptr(), K(ret));
} else if (NULL == (result = res.get_result())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("fail to execute ", "sql", sql.ptr(), K(ret));
} else if (OB_FAIL(result->next())) {
if (OB_ITER_END != ret) {
LOG_WARN("get next row failed", K(ret));
} else {
ret = OB_SUCCESS;
}
} else if (OB_FAIL(fill_system_stat(*result, stat))) {
LOG_WARN("failed to fill system stat", K(ret));
}
}
}
return ret;
}
int ObOptStatSqlService::fill_system_stat(sqlclient::ObMySQLResult &result, ObOptSystemStat &stat)
{
int ret = OB_SUCCESS;
if (!inited_) {
ret = OB_NOT_INIT;
LOG_WARN("sql service has not been initialized.", K(ret));
} else {
EXTRACT_INT_FIELD_TO_CLASS_MYSQL_WITH_DEFAULT_VALUE(result, cpu_speed, stat, int64_t, true, true, 0);
EXTRACT_INT_FIELD_TO_CLASS_MYSQL_WITH_DEFAULT_VALUE(result, disk_seq_read_speed, stat, int64_t, true, true, 0);
EXTRACT_INT_FIELD_TO_CLASS_MYSQL_WITH_DEFAULT_VALUE(result, disk_rnd_read_speed, stat, int64_t, true, true, 0);
EXTRACT_INT_FIELD_TO_CLASS_MYSQL_WITH_DEFAULT_VALUE(result, network_speed, stat, int64_t, true, true, 0);
}
return ret;
}
int ObOptStatSqlService::delete_system_stats(const uint64_t tenant_id)
{
int ret = OB_SUCCESS;
ObSqlString system_stat_sql;
int64_t current_time = ObTimeUtility::current_time();
int64_t affected_rows = 0;
int64_t ext_tenant_id = ObSchemaUtils::get_extract_tenant_id(tenant_id, tenant_id);
if (OB_FAIL(system_stat_sql.append_fmt(DELETE_SYSTEM_STAT_SQL, OB_ALL_AUX_STAT_TNAME, ext_tenant_id))) {
LOG_WARN("failed to append sql", K(ret));
} else {
ObMySQLTransaction trans;
LOG_TRACE("sql string of system stat delete", K(system_stat_sql));
if (OB_FAIL(trans.start(mysql_proxy_, tenant_id))) {
LOG_WARN("fail to start transaction", K(ret), K(tenant_id));
} else if (OB_FAIL(trans.write(tenant_id, system_stat_sql.ptr(), affected_rows))) {
LOG_WARN("failed to exec sql", K(ret));
} else {/*do nothing*/}
if (OB_SUCC(ret)) {
if (OB_FAIL(trans.end(true))) {
LOG_WARN("fail to commit transaction", K(ret));
}
} else {
int tmp_ret = OB_SUCCESS;
if (OB_SUCCESS != (tmp_ret = trans.end(false))) {
LOG_WARN("fail to roll back transaction", K(tmp_ret));
}
}
}
return ret;
}
} // end of namespace common
} // end of namespace oceanbase
@ -2271,3 +2428,5 @@ int ObOptStatSqlService::get_gather_stat_value(const ObOptStatGatherStat &gather
#undef INSERT_ONLINE_TABLE_STAT_DUPLICATE
#undef INSERT_ONLINE_COL_STAT_SQL
#undef INSERT_ONLINE_COL_STAT_DUPLICATE
#undef INERT_SYSTEM_STAT_SQL
#undef DELETE_SYSTEM_STAT_SQL

View File

@ -15,6 +15,7 @@
#include "share/stat/ob_opt_column_stat.h"
#include "share/stat/ob_opt_table_stat.h"
#include "share/stat/ob_opt_system_stat.h"
#include "share/stat/ob_stat_define.h"
#include "share/stat/ob_opt_stat_gather_stat.h"
#include "lib/mysqlclient/ob_mysql_transaction.h"
@ -170,6 +171,14 @@ public:
int update_opt_stat_gather_stat(const ObOptStatGatherStat &gather_stat);
int update_opt_stat_task_stat(const ObOptStatTaskInfo &task_info);
int update_system_stats(const uint64_t tenant_id,
const ObOptSystemStat *system_stat);
int fetch_system_stat(const uint64_t tenant_id,
const ObOptSystemStat::Key &key,
ObOptSystemStat &stat);
int delete_system_stats(const uint64_t tenant_id);
private:
int get_table_stat_sql(const uint64_t tenant_id,
const ObOptTableStat &stat,
@ -273,6 +282,13 @@ private:
int get_gather_stat_task_value(const ObOptStatTaskInfo &task_info,
ObSqlString &values_str);
int get_system_stat_sql(const uint64_t tenant_id,
const ObOptSystemStat &stat,
const int64_t current_time,
ObSqlString &sql_string);
int fill_system_stat(sqlclient::ObMySQLResult &result, ObOptSystemStat &stat);
static const char *bitmap_compress_lib_name;
bool inited_;

View File

@ -0,0 +1,171 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#define USING_LOG_PREFIX SQL_OPT
#include "share/stat/ob_opt_system_stat.h"
#include "lib/utility/ob_unify_serialize.h"
#include "lib/utility/ob_macro_utils.h"
#include "src/storage/blocksstable/ob_block_manager.h"
#include "src/share/io/ob_io_manager.h"
namespace oceanbase {
namespace common {
using namespace sql;
OB_DEF_SERIALIZE(ObOptSystemStat) {
int ret = OB_SUCCESS;
LST_DO_CODE(OB_UNIS_ENCODE,
last_analyzed_,
cpu_speed_,
disk_seq_read_speed_,
disk_rnd_read_speed_,
network_speed_
);
return ret;
}
OB_DEF_SERIALIZE_SIZE(ObOptSystemStat) {
int64_t len = 0;
LST_DO_CODE(OB_UNIS_ADD_LEN,
last_analyzed_,
cpu_speed_,
disk_seq_read_speed_,
disk_rnd_read_speed_,
network_speed_
);
return len;
}
OB_DEF_DESERIALIZE(ObOptSystemStat) {
int ret = OB_SUCCESS;
LST_DO_CODE(OB_UNIS_DECODE,
last_analyzed_,
cpu_speed_,
disk_seq_read_speed_,
disk_rnd_read_speed_,
network_speed_
);
return ret;
}
void OptSystemIoBenchmark::reset()
{
disk_seq_read_speed_ = 0;
disk_rnd_read_speed_ = 0;
init_ = false;
}
OptSystemIoBenchmark& OptSystemIoBenchmark::get_instance()
{
static OptSystemIoBenchmark benchmark;
return benchmark;
}
int OptSystemIoBenchmark::run_benchmark(ObIAllocator &allocator)
{
int ret = OB_SUCCESS;
int64_t load_size = 16 * 1024; //16k
int64_t io_count = 0;
int64_t rt_us = 0;
int64_t data_size = 0;
char *read_buf = NULL;
ObIOInfo io_info;
io_info.tenant_id_ = OB_SERVER_TENANT_ID;
io_info.size_ = load_size;
io_info.buf_ = nullptr;
io_info.flag_.set_mode(ObIOMode::READ);
io_info.flag_.set_group_id(ObIOModule::CALIBRATION_IO);
io_info.flag_.set_wait_event(ObWaitEventIds::DB_FILE_DATA_READ);
io_info.flag_.set_unlimited(true);
io_info.timeout_us_ = MAX_IO_WAIT_TIME_MS;
ObIOHandle io_handle;
// prepare io bench
ObSEArray<blocksstable::ObMacroBlockHandle, 16> block_handles;
const double MIN_FREE_SPACE_PERCENTAGE = 0.1; //
const int64_t MIN_CALIBRATION_BLOCK_COUNT = 1024L * 1024L * 1024L / OB_DEFAULT_MACRO_BLOCK_SIZE;
const int64_t MAX_CALIBRATION_BLOCK_COUNT = 20L * 1024L * 1024L * 1024L / OB_DEFAULT_MACRO_BLOCK_SIZE;
const int64_t free_block_count = OB_SERVER_BLOCK_MGR.get_free_macro_block_count();
const int64_t total_block_count = OB_SERVER_BLOCK_MGR.get_total_macro_block_count();
int64_t benchmark_block_count = free_block_count * 0.2;
if (free_block_count <= MIN_CALIBRATION_BLOCK_COUNT ||
1.0 * free_block_count / total_block_count < MIN_FREE_SPACE_PERCENTAGE) {
ret = OB_SERVER_OUTOF_DISK_SPACE;
LOG_WARN("out of space", K(ret), K(free_block_count), K(total_block_count));
} else if (OB_ISNULL(read_buf = static_cast<char *>(allocator.alloc(OB_DEFAULT_MACRO_BLOCK_SIZE)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("allocate read memory failed", K(ret));
} else {
benchmark_block_count = min(benchmark_block_count, MAX_CALIBRATION_BLOCK_COUNT);
benchmark_block_count = max(benchmark_block_count, MIN_CALIBRATION_BLOCK_COUNT);
io_info.user_data_buf_ = read_buf;
}
// prepare macro blocks
for (int64_t i = 0; OB_SUCC(ret) && i < benchmark_block_count; ++i) {
blocksstable::ObMacroBlockHandle block_handle;
if (OB_FAIL(OB_SERVER_BLOCK_MGR.alloc_block(block_handle))) {
LOG_WARN("alloc macro block failed", K(ret), K(i));
} else if (OB_FAIL(block_handles.push_back(block_handle))) {
LOG_WARN("push back block handle failed", K(ret), K(block_handle));
}
}
//test rnd io
while (OB_SUCC(ret) && io_count < 100) {
int64_t block_idx = ObRandom::rand(block_handles.count()/2, block_handles.count() - 1);
io_info.fd_.first_id_ = block_handles[block_idx].get_macro_id().first_id();
io_info.fd_.second_id_ = block_handles[block_idx].get_macro_id().second_id();
io_info.offset_ = ObRandom::rand(0, OB_DEFAULT_MACRO_BLOCK_SIZE - load_size);
io_info.size_ = load_size;
const int64_t begin_ts = ObTimeUtility::fast_current_time();
if (OB_FAIL(OB_IO_MANAGER.read(io_info, io_handle))) {
LOG_WARN("io benchmark read failed", K(ret), K(io_info));
} else {
++io_count;
rt_us += ObTimeUtility::fast_current_time() - begin_ts;
data_size += io_handle.get_data_size();
}
}
if (OB_SUCC(ret)) {
rt_us = rt_us >= 1 ? rt_us : 1;
disk_rnd_read_speed_ = data_size / rt_us;
init_ = true;
}
io_count = 0;
rt_us = 0;
data_size = 0;
//test seq io
while (OB_SUCC(ret) && io_count < 100 && io_count < block_handles.count()/2) {
int64_t block_idx = io_count;
io_info.fd_.first_id_ = block_handles[block_idx].get_macro_id().first_id();
io_info.fd_.second_id_ = block_handles[block_idx].get_macro_id().second_id();
io_info.offset_ = 0;
io_info.size_ = OB_DEFAULT_MACRO_BLOCK_SIZE;
const int64_t begin_ts = ObTimeUtility::fast_current_time();
if (OB_FAIL(OB_IO_MANAGER.read(io_info, io_handle))) {
LOG_WARN("io benchmark read failed", K(ret), K(io_info));
} else {
++io_count;
rt_us += ObTimeUtility::fast_current_time() - begin_ts;
data_size += io_handle.get_data_size();
}
}
if (OB_SUCC(ret)) {
rt_us = rt_us >= 1 ? rt_us : 1;
disk_seq_read_speed_ = data_size / rt_us;
allocator.free(read_buf);
}
return ret;
}
//TODO: collect system stat with workload
}
}

View File

@ -0,0 +1,223 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#ifndef _OB_OPT_SYSTEM_STAT_H_
#define _OB_OPT_SYSTEM_STAT_H_
#include <stdint.h>
#include <cstddef>
#include "lib/hash_func/murmur_hash.h"
#include "lib/utility/ob_print_utils.h"
#include "share/cache/ob_kvcache_struct.h"
namespace oceanbase {
namespace common {
/**
* Optimizer System Level Statistics
*/
class ObOptSystemStat : public common::ObIKVCacheValue
{
OB_UNIS_VERSION_V(1);
public:
struct Key : public common::ObIKVCacheKey
{
Key() : tenant_id_(0)
{
}
explicit Key(uint64_t tenant_id) :
tenant_id_(tenant_id)
{
}
void init(uint64_t tenant_id)
{
tenant_id_ = tenant_id;
}
uint64_t hash() const
{
return common::murmurhash(this, sizeof(Key), 0);
}
int hash(uint64_t &hash_val) const { hash_val = hash(); return OB_SUCCESS; }
bool operator==(const ObIKVCacheKey &other) const
{
const Key &other_key = reinterpret_cast<const Key&>(other);
return tenant_id_ == other_key.tenant_id_;
}
uint64_t get_tenant_id() const
{
return tenant_id_;
}
int64_t size() const
{
return sizeof(*this);
}
int deep_copy(char *buf, const int64_t buf_len, ObIKVCacheKey *&key) const
{
int ret = OB_SUCCESS;
Key *tmp = NULL;
if (NULL == buf || buf_len < size()) {
ret = OB_INVALID_ARGUMENT;
COMMON_LOG(WARN, "invalid argument.",
K(ret), KP(buf), K(buf_len), K(size()));
} else {
tmp = new (buf) Key();
*tmp = *this;
key = tmp;
}
return ret;
}
bool is_valid() const
{
return tenant_id_ != 0;
}
void reset()
{
tenant_id_ = 0;
}
TO_STRING_KV(K_(tenant_id));
uint64_t tenant_id_;
};
ObOptSystemStat()
: last_analyzed_(0),
cpu_speed_(0),
disk_seq_read_speed_(0),
disk_rnd_read_speed_(0),
network_speed_(0) {}
ObOptSystemStat(int64_t last_analyzed,
int64_t cpu_speed,
int64_t disk_seq_read_speed,
int64_t disk_rnd_read_speed,
int64_t network_speed) :
last_analyzed_(last_analyzed),
cpu_speed_(cpu_speed),
disk_seq_read_speed_(disk_seq_read_speed),
disk_rnd_read_speed_(disk_rnd_read_speed),
network_speed_(network_speed) {}
virtual ~ObOptSystemStat() {}
int64_t get_last_analyzed() const { return last_analyzed_; }
void set_last_analyzed(int64_t last_analyzed) { last_analyzed_ = last_analyzed; }
int64_t get_cpu_speed() const { return cpu_speed_; }
void set_cpu_speed(int64_t cpu_speed) { cpu_speed_ = cpu_speed; }
int64_t get_disk_seq_read_speed() const { return disk_seq_read_speed_; }
void set_disk_seq_read_speed(int64_t disk_seq_read_speed) { disk_seq_read_speed_ = disk_seq_read_speed; }
int64_t get_disk_rnd_read_speed() const { return disk_rnd_read_speed_; }
void set_disk_rnd_read_speed(int64_t disk_rnd_read_speed) { disk_rnd_read_speed_ = disk_rnd_read_speed; }
int64_t get_network_speed() const { return network_speed_; }
void set_network_speed(int64_t network_speed) { network_speed_ = network_speed; }
virtual int64_t size() const
{
return sizeof(*this);
}
virtual int deep_copy(char *buf, const int64_t buf_len, ObIKVCacheValue *&value) const
{
int ret = OB_SUCCESS;
ObOptSystemStat *tstat = nullptr;
if (nullptr == buf || buf_len < size()) {
ret = OB_INVALID_ARGUMENT;
COMMON_LOG(WARN, "invalid argument.", K(ret), KP(buf), K(buf_len), K(size()));
} else {
tstat = new (buf) ObOptSystemStat();
*tstat = *this;
value = tstat;
}
return ret;
}
virtual int deep_copy(char *buf, const int64_t buf_len, ObOptSystemStat *&stat) const
{
int ret = OB_SUCCESS;
ObOptSystemStat *tstat = nullptr;
if (nullptr == buf || buf_len < size()) {
ret = OB_INVALID_ARGUMENT;
COMMON_LOG(WARN, "invalid argument.", K(ret), KP(buf), K(buf_len), K(size()));
} else {
tstat = new (buf) ObOptSystemStat();
*tstat = *this;
stat = tstat;
}
return ret;
}
bool is_valid() const
{
return cpu_speed_ > 0 &&
disk_seq_read_speed_ > 0 &&
disk_rnd_read_speed_ > 0 &&
network_speed_ > 0;
}
void reset() {
last_analyzed_ = 0;
cpu_speed_ = 0;
disk_seq_read_speed_ = 0;
disk_rnd_read_speed_ = 0;
network_speed_ = 0;
}
TO_STRING_KV(K(last_analyzed_),
K(cpu_speed_),
K(disk_seq_read_speed_),
K(disk_rnd_read_speed_),
K(network_speed_));
private:
int64_t last_analyzed_;
int64_t cpu_speed_;
int64_t disk_seq_read_speed_;
int64_t disk_rnd_read_speed_;
int64_t network_speed_;
};
class OptSystemIoBenchmark {
public:
OptSystemIoBenchmark()
:disk_seq_read_speed_(0),
disk_rnd_read_speed_(0),
init_(false)
{}
~OptSystemIoBenchmark()
{}
inline bool is_init() const { return init_; }
inline int64_t get_disk_seq_read_speed() const { return disk_seq_read_speed_; }
inline int64_t get_disk_rnd_read_speed() const { return disk_rnd_read_speed_; }
void reset();
static OptSystemIoBenchmark& get_instance();
int run_benchmark(ObIAllocator &allocator);
private:
int64_t disk_seq_read_speed_;
int64_t disk_rnd_read_speed_;
bool init_;
DISALLOW_COPY_AND_ASSIGN(OptSystemIoBenchmark);
};
}
}
#endif /* _OB_OPT_SYSTEM_STAT_H_ */

View File

@ -0,0 +1,52 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#include "share/stat/ob_opt_system_stat_cache.h"
#include "lib/stat/ob_diagnose_info.h"
namespace oceanbase {
namespace common {
/**
* @return OB_SUCCESS if value corresponding to the key is successfully fetched
* OB_ENTRY_NOT_EXIST if values is not available from the cache
* other error codes if unexpected errors occurred
*/
int ObOptSystemStatCache::get_value(const ObOptSystemStat::Key &key, ObOptSystemStatHandle &handle)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get(key, handle.stat_, handle.handle_))) {
if (OB_ENTRY_NOT_EXIST != ret) {
COMMON_LOG(WARN, "fail to get value from cache", K(ret), K(key));
}
EVENT_INC(ObStatEventIds::OPT_SYSTEM_STAT_CACHE_MISS);
} else {
handle.cache_ = this;
EVENT_INC(ObStatEventIds::OPT_SYSTEM_STAT_CACHE_HIT);
}
return ret;
}
int ObOptSystemStatCache::put_value(const ObOptSystemStat::Key &key, const ObOptSystemStat &value)
{
return put(key, value, true /* overwrite */);
}
int ObOptSystemStatCache::put_and_fetch_value(const ObOptSystemStat::Key &key,
const ObOptSystemStat &value,
ObOptSystemStatHandle &handle)
{
return put_and_fetch(key, value, handle.stat_, handle.handle_, true /* overwrite */ );
}
}
}

View File

@ -0,0 +1,67 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#ifndef _OB_OPT_SYSTEM_STAT_CACHE_H_
#define _OB_OPT_SYSTEM_STAT_CACHE_H_
#include "share/cache/ob_kv_storecache.h"
#include "share/stat/ob_opt_system_stat.h"
namespace oceanbase {
namespace common {
struct ObOptSystemStatHandle;
class ObOptSystemStatCache : public common::ObKVCache<ObOptSystemStat::Key, ObOptSystemStat>
{
public:
int get_value(const ObOptSystemStat::Key &key, ObOptSystemStatHandle &handle);
int put_value(const ObOptSystemStat::Key &key, const ObOptSystemStat &value);
int put_and_fetch_value(const ObOptSystemStat::Key &key,
const ObOptSystemStat &value,
ObOptSystemStatHandle &handle);
};
struct ObOptSystemStatHandle
{
const ObOptSystemStat *stat_;
ObOptSystemStatCache *cache_;
ObKVCacheHandle handle_;
ObOptSystemStatHandle()
: stat_(nullptr), cache_(nullptr), handle_() {}
ObOptSystemStatHandle(const ObOptSystemStatHandle &other)
{
if (this != &other) {
*this = other;
}
}
~ObOptSystemStatHandle()
{
stat_ = nullptr;
cache_ = nullptr;
}
void reset()
{
stat_ = nullptr;
cache_ = nullptr;
handle_.reset();
}
TO_STRING_KV(K(stat_));
};
}
}
#endif /* _OB_OPT_SYSTEM_STAT_CACHE_H_ */

View File

@ -667,6 +667,24 @@ struct ObSetColumnStatParam
};
struct ObSetSystemStatParam
{
ObSetSystemStatParam()
:tenant_id_(OB_INVALID_ID),
name_(),
value_(0)
{ }
int64_t tenant_id_;
ObString name_;
int64_t value_;
TO_STRING_KV(K(tenant_id_),
K(name_),
K(value_)
);
};
struct ObPartitionStatInfo
{
ObPartitionStatInfo():

View File

@ -872,6 +872,7 @@ ob_set_subtarget(ob_sql optimizer
optimizer/ob_opt_est_cost.cpp
optimizer/ob_opt_est_cost_model.cpp
optimizer/ob_opt_est_cost_model_vector.cpp
optimizer/ob_opt_cost_model_parameter.cpp
optimizer/ob_opt_est_utils.cpp
optimizer/ob_opt_selectivity.cpp
optimizer/ob_optimizer.cpp

View File

@ -491,6 +491,27 @@ int ObOptimizerTraceImpl::append(const ObPhyPlanType& type)
return ret;
}
int ObOptimizerTraceImpl::append(const OptSystemStat& stat)
{
int ret = OB_SUCCESS;
if (OB_FAIL(append("cpu speed:", stat.get_cpu_speed(), "MHz"))) {
LOG_WARN("failed to append msg", K(ret));
} else if (OB_FAIL(new_line())) {
LOG_WARN("failed to append msg", K(ret));
} else if (OB_FAIL(append("disk seq read speed:", stat.get_disk_seq_read_speed(), "MB/s"))) {
LOG_WARN("failed to append msg", K(ret));
} else if (OB_FAIL(new_line())) {
LOG_WARN("failed to append msg", K(ret));
} else if (OB_FAIL(append("disk rnd read speed:", stat.get_disk_rnd_read_speed(), "MB/s"))) {
LOG_WARN("failed to append msg", K(ret));
} else if (OB_FAIL(new_line())) {
LOG_WARN("failed to append msg", K(ret));
} else if (OB_FAIL(append("network speed:", stat.get_network_speed(), "MB/s"))) {
LOG_WARN("failed to append msg", K(ret));
}
return ret;
}
int ObOptimizerTraceImpl::append(const ObLogPlan *log_plan)
{
int ret = OB_SUCCESS;

View File

@ -43,6 +43,7 @@ class OptTableMetas;
class TableItem;
class ObSQLSessionInfo;
struct CandidatePlan;
class OptSystemStat;
class ObOptimizerTraceImpl;
@ -253,6 +254,7 @@ public:
int append(const OpParallelRule& rule);
int append(const ObTableLocationType& type);
int append(const ObPhyPlanType& type);
int append(const OptSystemStat& stat);
/***********************************************/
////print plan info
/***********************************************/

View File

@ -3667,7 +3667,7 @@ int ObJoinOrder::calculate_range_expr_cost(ObIArray<CandiRangeExprs*> &sorted_pr
range_count,
range_sel,
cost,
get_plan()->get_optimizer_context().get_cost_model_type()))) {
get_plan()->get_optimizer_context()))) {
LOG_WARN("failed to estimate range scan cost", K(ret));
} else {
LOG_TRACE("query range cost:", K(range_column_count), K(range_count), K(range_sel), K(cost));
@ -5305,7 +5305,7 @@ int AccessPath::estimate_cost_for_parallel(const int64_t cur_parallel,
part_cnt_per_dop,
storage_est_px_cost,
storage_est_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to calculated cost for parallel", K(ret));
} else if (!adj_cost_is_valid) {
cost = storage_est_cost;
@ -5317,7 +5317,7 @@ int AccessPath::estimate_cost_for_parallel(const int64_t cur_parallel,
part_cnt_per_dop,
stats_est_px_cost,
stats_est_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to calculated cost for parallel", K(ret));
} else {
double rate = opt_stats_cost_percent * 1.0 / 100.0;
@ -5354,7 +5354,7 @@ int AccessPath::estimate_cost()
if (OB_FAIL(ObOptEstCost::cost_table(est_cost_info_,
parallel_,
storage_est_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to get index access info", K(ret));
} else if (!adj_cost_is_valid) {
cost_ = storage_est_cost;
@ -5363,7 +5363,7 @@ int AccessPath::estimate_cost()
} else if (OB_FAIL(ObOptEstCost::cost_table(est_cost_info_,
parallel_,
stats_est_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to get index access info", K(ret));
} else {
double rate = opt_stats_cost_percent * 1.0 / 100.0;
@ -5402,7 +5402,7 @@ int AccessPath::re_estimate_cost(EstimateCostInfo &param, double &card, double &
adj_cost_is_valid))) {
LOG_WARN("failed to check adj index cost valid", K(ret));
} else if (OB_FAIL(re_estimate_cost(param, est_cost_info_, sample_info_,
opt_ctx->get_cost_model_type(),
*opt_ctx,
storage_est_card,
storage_est_cost))) {
LOG_WARN("failed to re estimate cost", K(ret));
@ -5415,7 +5415,7 @@ int AccessPath::re_estimate_cost(EstimateCostInfo &param, double &card, double &
} else if (OB_FALSE_IT(est_cost_info_.phy_query_range_row_count_ = stats_phy_query_range_row_count)) {
} else if (OB_FALSE_IT(est_cost_info_.logical_query_range_row_count_ = stats_logical_query_range_row_count)) {
} else if (OB_FAIL(re_estimate_cost(param, est_cost_info_, sample_info_,
opt_ctx->get_cost_model_type(),
*opt_ctx,
stats_est_card,
stats_est_cost))) {
LOG_WARN("failed to re estimate cost", K(ret));
@ -5435,7 +5435,7 @@ int AccessPath::re_estimate_cost(EstimateCostInfo &param, double &card, double &
int AccessPath::re_estimate_cost(const EstimateCostInfo &param,
ObCostTableScanInfo &est_cost_info,
const SampleInfo &sample_info,
const ObOptEstCost::MODEL_TYPE model_type,
const ObOptimizerContext &opt_ctx,
double &card,
double &cost)
{
@ -5494,7 +5494,7 @@ int AccessPath::re_estimate_cost(const EstimateCostInfo &param,
if (OB_FAIL(ObOptEstCost::cost_table(est_cost_info,
param.need_parallel_,
cost,
model_type))) {
opt_ctx))) {
LOG_WARN("failed to get index access info", K(ret));
} else {
//restore query range row count
@ -5643,8 +5643,8 @@ int TempTablePath::estimate_cost()
} else {
ObOptimizerContext &opt_ctx = parent_->get_plan()->get_optimizer_context();
double per_dop_card = root_->get_card() / parallel_;
op_cost_ = ObOptEstCost::cost_read_materialized(per_dop_card, opt_ctx.get_cost_model_type()) +
ObOptEstCost::cost_quals(per_dop_card, filter_, opt_ctx.get_cost_model_type());
op_cost_ = ObOptEstCost::cost_read_materialized(per_dop_card, opt_ctx) +
ObOptEstCost::cost_quals(per_dop_card, filter_, opt_ctx);
cost_ = op_cost_;
}
return ret;
@ -5681,8 +5681,8 @@ int TempTablePath::re_estimate_cost(EstimateCostInfo &param, double &card, doubl
}
}
double per_dop_card = read_card / parallel;
cost = ObOptEstCost::cost_read_materialized(per_dop_card, opt_ctx.get_cost_model_type()) +
ObOptEstCost::cost_quals(per_dop_card, filter_, opt_ctx.get_cost_model_type());
cost = ObOptEstCost::cost_read_materialized(per_dop_card, opt_ctx) +
ObOptEstCost::cost_quals(per_dop_card, filter_, opt_ctx);
if (param.override_) {
cost_ = cost;
op_cost_ = cost;
@ -6874,23 +6874,23 @@ int JoinPath::cost_nest_loop_join(int64_t join_parallel,
server_cnt_);
if (OB_FAIL(ObOptEstCost::cost_nestloop(est_join_info, op_cost,
plan->get_predicate_selectivities(),
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to estimate nest loop join cost", K(est_join_info), K(ret));
} else if (!re_est_for_op && is_left_need_exchange() &&
OB_FAIL(ObOptEstCost::cost_exchange(left_exch_info, left_ex_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to cost exchange", K(ret));
} else if (!re_est_for_op && is_right_need_exchange() &&
OB_FAIL(ObOptEstCost::cost_exchange(right_exch_info, right_ex_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to cost exchange", K(ret));
} else {
cost = op_cost + left_cost + ObOptEstCost::cost_get_rows(left_rows, opt_ctx.get_cost_model_type())
cost = op_cost + left_cost + ObOptEstCost::cost_get_rows(left_rows, opt_ctx)
+ left_ex_cost + right_ex_cost;
if (need_mat_ && !re_est_for_op) {
cost += ObOptEstCost::cost_get_rows(right_rows, opt_ctx.get_cost_model_type()) + right_path_->get_cost();
cost += ObOptEstCost::cost_get_rows(right_rows, opt_ctx) + right_path_->get_cost();
cost += ObOptEstCost::cost_material(right_rows, right_join_order->get_output_row_size(),
opt_ctx.get_cost_model_type());
opt_ctx);
}
LOG_TRACE("succeed to compute nested loop join cost", K(cost), K(op_cost), K(re_est_for_op),
K(in_parallel), K(left_out_parallel), K(right_out_parallel),
@ -6959,7 +6959,7 @@ int JoinPath::cost_merge_join(int64_t join_parallel,
other_cond_sel_,
&plan->get_update_table_metas(),
&plan->get_selectivity_ctx());
if (OB_FAIL(ObOptEstCost::cost_mergejoin(est_join_info, op_cost, opt_ctx.get_cost_model_type()))) {
if (OB_FAIL(ObOptEstCost::cost_mergejoin(est_join_info, op_cost, opt_ctx))) {
LOG_WARN("failed to estimate merge join cost", K(est_join_info), K(ret));
} else if (!re_est_for_op &&
OB_FAIL(ObOptEstCost::cost_sort_and_exchange(&plan->get_update_table_metas(),
@ -6977,7 +6977,7 @@ int JoinPath::cost_merge_join(int64_t join_parallel,
left_need_sort_,
left_prefix_pos_,
left_child_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to compute cost for merge style op", K(ret));
} else if (!re_est_for_op &&
OB_FAIL(ObOptEstCost::cost_sort_and_exchange(&plan->get_update_table_metas(),
@ -6995,7 +6995,7 @@ int JoinPath::cost_merge_join(int64_t join_parallel,
right_need_sort_,
right_prefix_pos_,
right_child_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to compute cost for merge style op", K(ret));
} else {
cost = op_cost + left_child_cost + right_child_cost;
@ -7091,15 +7091,15 @@ int JoinPath::cost_hash_join(int64_t join_parallel,
false,
right_sort_keys_,
server_cnt_);
if (OB_FAIL(ObOptEstCost::cost_hashjoin(est_join_info, op_cost, opt_ctx.get_cost_model_type()))) {
if (OB_FAIL(ObOptEstCost::cost_hashjoin(est_join_info, op_cost, opt_ctx))) {
LOG_WARN("failed to estimate hash join cost", K(est_join_info), K(ret));
} else if (!re_est_for_op && is_left_need_exchange() &&
OB_FAIL(ObOptEstCost::cost_exchange(left_exch_info, left_ex_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to cost exchange", K(ret));
} else if (!re_est_for_op && is_right_need_exchange() &&
OB_FAIL(ObOptEstCost::cost_exchange(right_exch_info, right_ex_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to cost exchange", K(ret));
} else {
cost = op_cost + left_cost + right_cost + left_ex_cost + right_ex_cost;
@ -7237,7 +7237,7 @@ int SubQueryPath::estimate_cost()
double child_card = root_->get_card();
double child_cost = root_->get_cost();
op_cost_ = ObOptEstCost::cost_filter_rows(child_card / parallel, filter_,
opt_ctx.get_cost_model_type());
opt_ctx);
cost_ = child_cost + op_cost_;
}
return ret;
@ -7272,7 +7272,7 @@ int SubQueryPath::re_estimate_cost(EstimateCostInfo &param, double &card, double
LOG_WARN("failed to est cost", K(ret));
} else {
op_cost = ObOptEstCost::cost_filter_rows(child_card / parallel, filter_,
opt_ctx.get_cost_model_type());
opt_ctx);
cost = child_cost + op_cost;
if (param.override_) {
op_cost_ = op_cost;
@ -8244,6 +8244,7 @@ int ObJoinOrder::generate_join_paths(const ObJoinOrder &left_tree,
ObJoinType reverse_join_type = get_opposite_join_type(join_info.join_type_);
bool is_connect_by = (join_info.join_type_ == CONNECT_BY_JOIN);
typedef ObSEArray<ObSEArray<Path*, 16>, 4> PathArray;
reverse_path_info.is_reverse_path_ = true;
SMART_VARS_2((PathArray, left_paths),
(PathArray, right_paths)) {
if (OB_FAIL(append(equal_sets, left_tree.get_output_equal_sets())) ||
@ -8264,6 +8265,7 @@ int ObJoinOrder::generate_join_paths(const ObJoinOrder &left_tree,
join_info.on_conditions_ :
join_info.where_conditions_,
false,
false,
path_info))) {
LOG_WARN("failed to get valid path types", K(join_info.join_type_), K(ret));
} else if (!is_connect_by && !force_ordered
@ -8274,6 +8276,7 @@ int ObJoinOrder::generate_join_paths(const ObJoinOrder &left_tree,
join_info.on_conditions_ :
join_info.where_conditions_,
false,
true,
reverse_path_info))) {
LOG_WARN("failed to get valid path types", K(join_info.join_type_), K(ret));
} else if (OB_FAIL(inner_generate_join_paths(left_tree,
@ -8301,6 +8304,7 @@ int ObJoinOrder::generate_join_paths(const ObJoinOrder &left_tree,
join_info.on_conditions_ :
join_info.where_conditions_,
true,
false,
path_info))) {
LOG_WARN("failed to get valid path types", K(join_info.join_type_), K(ret));
} else if (!is_connect_by && OB_FAIL(get_valid_path_info(right_tree,
@ -8310,6 +8314,7 @@ int ObJoinOrder::generate_join_paths(const ObJoinOrder &left_tree,
join_info.on_conditions_ :
join_info.where_conditions_,
true,
true,
reverse_path_info))) {
LOG_WARN("failed to get valid path types", K(join_info.join_type_), K(ret));
} else if (OB_FAIL(inner_generate_join_paths(left_tree,
@ -8681,7 +8686,11 @@ int ObJoinOrder::generate_hash_paths(const EqualSets &equal_sets,
} else {
Path *left_path = NULL;
Path *right_path = NULL;
OPT_TRACE_TITLE("Consider HASH", ob_join_type_str(path_info.join_type_));
if (path_info.is_reverse_path_) {
OPT_TRACE_TITLE("Consider Reverse HASH", ob_join_type_str(path_info.join_type_));
} else {
OPT_TRACE_TITLE("Consider HASH", ob_join_type_str(path_info.join_type_));
}
for (int64_t i = 0; OB_SUCC(ret) && i < left_best_paths.count(); i++) {
if (OB_ISNULL(left_path = left_best_paths.at(i))) {
ret = OB_ERR_UNEXPECTED;
@ -8756,7 +8765,11 @@ int ObJoinOrder::generate_nl_paths(const EqualSets &equal_sets,
const ObIArray<ObRawExpr*> &join_conditions =
IS_OUTER_OR_CONNECT_BY_JOIN(path_info.join_type_) ? on_conditions : where_conditions;
bool need_inner_path = false;
OPT_TRACE_TITLE("Consider NL", ob_join_type_str(path_info.join_type_));
if (path_info.is_reverse_path_) {
OPT_TRACE_TITLE("Consider Reverse NL", ob_join_type_str(path_info.join_type_));
} else {
OPT_TRACE_TITLE("Consider NL", ob_join_type_str(path_info.join_type_));
}
if (OB_UNLIKELY(left_paths.empty()) || OB_UNLIKELY(right_paths.empty()) || OB_ISNULL(get_plan()) ||
OB_UNLIKELY(left_paths.at(0).empty()) || OB_ISNULL(left_tree = left_paths.at(0).at(0)->parent_) ||
OB_UNLIKELY(right_paths.at(0).empty()) || OB_ISNULL(right_tree = right_paths.at(0).at(0)->parent_)) {
@ -9518,7 +9531,11 @@ int ObJoinOrder::generate_mj_paths(const EqualSets &equal_sets,
LOG_WARN("get unexpected array count", K(left_paths.count()),
K(left_merge_keys.count()), K(ret));
} else {
OPT_TRACE_TITLE("Consider Merge", ob_join_type_str(path_info.join_type_));
if (path_info.is_reverse_path_) {
OPT_TRACE_TITLE("Consider Reverse Merge", ob_join_type_str(path_info.join_type_));
} else {
OPT_TRACE_TITLE("Consider Merge", ob_join_type_str(path_info.join_type_));
}
for (int64_t i = 0; OB_SUCC(ret) && i < left_paths.count(); i++) {
for (int64_t j = 0; OB_SUCC(ret) && j < right_paths.count(); j++) {
if (OB_FAIL(generate_mj_paths(equal_sets,
@ -9763,7 +9780,7 @@ int ObJoinOrder::find_minimal_cost_merge_path(const Path &left_path,
right_need_sort,
right_prefix_pos,
right_path_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to compute cost for merge-join style op", K(ret));
} else if (NULL == best_path || right_path_cost < best_cost) {
if (OB_FAIL(best_order_items.assign(right_order_items))) {
@ -11201,6 +11218,7 @@ int ObJoinOrder::get_valid_path_info(const ObJoinOrder &left_tree,
const ObJoinType join_type,
const ObIArray<ObRawExpr*> &join_conditions,
const bool ignore_hint,
const bool reverse_join_tree,
ValidPathInfo &path_info)
{
int ret = OB_SUCCESS;
@ -11211,9 +11229,12 @@ int ObJoinOrder::get_valid_path_info(const ObJoinOrder &left_tree,
LOG_WARN("get unexpected null", K(get_plan()), K(ret));
} else {
if (ignore_hint) {
OPT_TRACE("start generate join path without hint");
OPT_TRACE("start generate join method without hint");
} else {
OPT_TRACE("start generate join path with hint");
OPT_TRACE("start generate join method with hint");
}
if (reverse_join_tree) {
OPT_TRACE("start generate reverse join method");
}
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
const bool both_access = ACCESS == left_tree.get_type() && ACCESS == right_tree.get_type();
@ -14885,7 +14906,7 @@ int ValuesTablePath::estimate_cost()
LOG_WARN("get unexpected null", K(parent_), K(ret));
} else {
ObOptimizerContext &opt_ctx = parent_->get_plan()->get_optimizer_context();
cost_ = ObOptEstCost::cost_get_rows(get_path_output_rows(), opt_ctx.get_cost_model_type());
cost_ = ObOptEstCost::cost_get_rows(get_path_output_rows(), opt_ctx);
op_cost_ = cost_;
}
return ret;

View File

@ -160,7 +160,8 @@ namespace sql
force_no_mat_(false),
prune_mj_(true),
force_inner_nl_(false),
ignore_hint_(true) { }
ignore_hint_(true),
is_reverse_path_(false) { }
virtual ~ValidPathInfo() {};
void reset()
{
@ -173,6 +174,7 @@ namespace sql
prune_mj_ = true;
force_inner_nl_ = false;
ignore_hint_ = true;
is_reverse_path_ = false;
}
TO_STRING_KV(K_(join_type),
K_(local_methods),
@ -182,7 +184,8 @@ namespace sql
K_(force_no_mat),
K_(prune_mj),
K_(force_inner_nl),
K_(ignore_hint));
K_(ignore_hint),
K_(is_reverse_path));
ObJoinType join_type_;
int64_t local_methods_;
int64_t distributed_methods_;
@ -192,6 +195,7 @@ namespace sql
bool prune_mj_; // prune merge join path
bool force_inner_nl_;
bool ignore_hint_;
bool is_reverse_path_;
};
enum OptimizationMethod
@ -652,7 +656,7 @@ struct EstimateCostInfo {
static int re_estimate_cost(const EstimateCostInfo &param,
ObCostTableScanInfo &est_cost_info,
const SampleInfo &sample_info,
const ObOptEstCost::MODEL_TYPE model_type,
const ObOptimizerContext &opt_ctx,
double &card,
double &cost);
int check_adj_index_cost_valid(double &stats_phy_query_range_row_count,
@ -2250,6 +2254,7 @@ struct NullAwareAntiJoinInfo {
const ObJoinType join_type,
const ObIArray<ObRawExpr*> &join_conditions,
const bool ignore_hint,
const bool reverse_join_tree,
ValidPathInfo &path_info);
int get_valid_path_info_from_hint(const ObRelIds &table_set,
bool both_access,

View File

@ -146,7 +146,7 @@ int ObLogCount::inner_est_cost(double &child_card,
}
}
op_cost = ObOptEstCost::cost_filter_rows(child_card, get_filter_exprs(),
opt_ctx.get_cost_model_type());
opt_ctx);
}
return ret;
}

View File

@ -816,7 +816,7 @@ int ObLogDelUpd::est_cost()
} else {
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
card_ = child->get_card();
op_cost_ = ObOptEstCost::cost_get_rows(child->get_card(), opt_ctx.get_cost_model_type());
op_cost_ = ObOptEstCost::cost_get_rows(child->get_card(), opt_ctx);
cost_ = op_cost_ + child->get_cost();
}
return ret;

View File

@ -95,7 +95,7 @@ int ObLogDelete::inner_est_cost(double child_card, double &op_cost)
} else {
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
cost_info.constraint_count_ = delete_dml_info->ck_cst_exprs_.count();
if (OB_FAIL(ObOptEstCost::cost_delete(cost_info, op_cost, opt_ctx.get_cost_model_type()))) {
if (OB_FAIL(ObOptEstCost::cost_delete(cost_info, op_cost, opt_ctx))) {
LOG_WARN("failed to get delete cost", K(ret));
}
}

View File

@ -217,13 +217,13 @@ int ObLogDistinct::inner_est_cost(const int64_t parallel, double child_card, dou
per_dop_ndv,
child->get_width(),
distinct_exprs_,
opt_ctx.get_cost_model_type());
opt_ctx);
} else {
op_cost = ObOptEstCost::cost_hash_distinct(per_dop_card,
per_dop_ndv,
child->get_width(),
distinct_exprs_,
opt_ctx.get_cost_model_type());
opt_ctx);
}
}
return ret;

View File

@ -493,7 +493,7 @@ int ObLogExchange::inner_est_cost(int64_t parallel, double child_card, double &o
get_in_server_cnt());
if (OB_FAIL(ObOptEstCost::cost_exchange_out(est_cost_info,
op_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to cost exchange out", K(ret));
}
} else {
@ -507,7 +507,7 @@ int ObLogExchange::inner_est_cost(int64_t parallel, double child_card, double &o
sort_keys_);
if (OB_FAIL(ObOptEstCost::cost_exchange_in(est_cost_info,
op_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to cost exchange in", K(ret));
}
}

View File

@ -220,12 +220,12 @@ int ObLogExprValues::do_re_est_cost(EstimateCostInfo &param, double &card, doubl
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
card = get_stmt()->is_insert_stmt() ? static_cast<const ObInsertStmt*>(get_stmt())->get_insert_row_count() :
get_values_row_count();
op_cost = ObOptEstCost::cost_get_rows(get_card(), opt_ctx.get_cost_model_type());
op_cost = ObOptEstCost::cost_get_rows(get_card(), opt_ctx);
cost = op_cost;
} else {
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
card = 1.0;
op_cost = ObOptEstCost::cost_filter_rows(get_card(), filter_exprs_, opt_ctx.get_cost_model_type());
op_cost = ObOptEstCost::cost_filter_rows(get_card(), filter_exprs_, opt_ctx);
cost = op_cost;
}
return ret;

View File

@ -225,7 +225,7 @@ int ObLogForUpdate::est_cost()
} else {
// todo: refine for update cost
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
set_op_cost(ObOptEstCost::cost_get_rows(first_child->get_card(), opt_ctx.get_cost_model_type()));
set_op_cost(ObOptEstCost::cost_get_rows(first_child->get_card(), opt_ctx));
set_cost(first_child->get_cost() + op_cost_);
set_card(first_child->get_card());
}

View File

@ -344,21 +344,21 @@ int ObLogGroupBy::inner_est_cost(const int64_t parallel, double child_card, doub
if (SCALAR_AGGREGATE == algo_) {
op_cost = ObOptEstCost::cost_scalar_group(per_dop_card,
get_aggr_funcs().count(),
opt_ctx.get_cost_model_type());
opt_ctx);
} else if (MERGE_AGGREGATE == algo_) {
op_cost = ObOptEstCost::cost_merge_group(per_dop_card,
per_dop_ndv,
child->get_width(),
group_rollup_exprs,
get_aggr_funcs().count(),
opt_ctx.get_cost_model_type());
opt_ctx);
} else {
op_cost = ObOptEstCost::cost_hash_group(per_dop_card,
per_dop_ndv,
child->get_width(),
group_exprs_,
get_aggr_funcs().count(),
opt_ctx.get_cost_model_type());
opt_ctx);
}
child_ndv = per_dop_ndv * parallel;
}

View File

@ -309,7 +309,7 @@ int ObLogInsert::inner_est_cost(double child_card, double &op_cost)
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
if (OB_FAIL(ObOptEstCost::cost_insert(cost_info,
op_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to get insert cost", K(ret));
}
}

View File

@ -117,7 +117,7 @@ int ObLogLimit::do_re_est_cost(EstimateCostInfo &param, double &card, double &op
if (OB_FAIL(child->re_est_cost(param, child_card, child_cost))) {
LOG_WARN("failed to re-est cost", K(ret));
} else {
op_cost = ObOptEstCost::cost_get_rows(child_card, opt_ctx.get_cost_model_type());
op_cost = ObOptEstCost::cost_get_rows(child_card, opt_ctx);
cost = op_cost + child_cost;
child_card = 0 <= limit_percent
? std::max(child_card * limit_percent / 100 - offset_count, 0.0)

View File

@ -38,7 +38,7 @@ int ObLogMaterial::est_cost()
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
op_cost += ObOptEstCost::cost_material(child->get_card() / parallel,
child->get_width(),
opt_ctx.get_cost_model_type());
opt_ctx);
set_op_cost(op_cost);
set_cost(child->get_cost() + op_cost);
set_card(child->get_card());
@ -67,7 +67,7 @@ int ObLogMaterial::do_re_est_cost(EstimateCostInfo &param, double &card, double
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
op_cost = ObOptEstCost::cost_material(child_card / parallel,
child->get_width(),
opt_ctx.get_cost_model_type());
opt_ctx);
cost = child_cost + op_cost;
card = child_card;
}

View File

@ -113,7 +113,7 @@ int ObLogOptimizerStatsGathering::est_cost()
if (osg_type_ != OSG_TYPE::MERGE_OSG) {
//for normal_osg and merge_osg calc the calc_stats cost;
//TODO: use a more accurate model.
op_cost_ += ObOptEstCost::cost_get_rows(child->get_card() / parallel, opt_ctx.get_cost_model_type());
op_cost_ += ObOptEstCost::cost_get_rows(child->get_card() / parallel, opt_ctx);
}
set_cost(op_cost_ + child->get_cost());
set_card(child->get_card());

View File

@ -793,6 +793,8 @@ int ObLogPlan::generate_join_orders()
//如果有leading hint就在这里按leading hint指定的join order枚举,
//如果根据leading hint没有枚举到有效join order,就忽略hint重新枚举。
if (OB_SUCC(ret)) {
OPT_TRACE("SYSTEM STATS:");
OPT_TRACE(get_optimizer_context().get_system_stat());
OPT_TRACE_TITLE("BASIC TABLE STATISTICS");
OPT_TRACE_STATIS(stmt, get_basic_table_metas());
OPT_TRACE_TITLE("UPDATE TABLE STATISTICS");

View File

@ -35,7 +35,7 @@ int ObLogSelectInto::est_cost()
} else {
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
set_op_cost(ObOptEstCost::cost_get_rows(child->get_card() / parallel,
opt_ctx.get_cost_model_type()));
opt_ctx));
set_cost(op_cost_ + child->get_cost());
set_card(child->get_card());
}

View File

@ -48,7 +48,7 @@ int ObLogSequence::est_cost()
if (0 == get_num_of_child()) {
op_cost_ = ObOptEstCost::cost_sequence(0,
nextval_seq_ids_.count(),
opt_ctx.get_cost_model_type());
opt_ctx);
cost_ = op_cost_;
card_ = 0.0;
} else if (OB_ISNULL(child = get_child(first_child))) {
@ -57,7 +57,7 @@ int ObLogSequence::est_cost()
} else {
op_cost_ = ObOptEstCost::cost_sequence(child->get_card(),
nextval_seq_ids_.count(),
opt_ctx.get_cost_model_type());
opt_ctx);
cost_ = op_cost_ + child->get_cost();
card_ = child->get_card();
}
@ -100,7 +100,7 @@ int ObLogSequence::do_re_est_cost(EstimateCostInfo &param, double &card, double
} else {
op_cost = ObOptEstCost::cost_sequence(child_card,
nextval_seq_ids_.count(),
get_plan()->get_optimizer_context().get_cost_model_type());
get_plan()->get_optimizer_context());
cost = child_cost + op_cost;
card = child_card;
}

View File

@ -460,22 +460,24 @@ int ObLogSet::do_re_est_cost(EstimateCostInfo &param, double &card, double &op_c
double tmp_card = 0.0;
double child_cost = 0.0;
ObSEArray<ObBasicCostInfo, 4> cost_infos;
ObOptEstCost::MODEL_TYPE model_type = ObOptEstCost::MODEL_TYPE::NORMAL_MODEL;
const ObSelectStmt *stmt = dynamic_cast<const ObSelectStmt*>(get_stmt());
if (OB_ISNULL(stmt) || OB_ISNULL(get_plan())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (OB_FALSE_IT(model_type = get_plan()->get_optimizer_context().get_cost_model_type())) {
} else if (OB_FAIL(get_re_est_cost_infos(param, cost_infos, child_cost, tmp_card))) {
LOG_WARN("failed to get re est cost infos", K(ret));
} else if (is_recursive_union() || !is_set_distinct()) {
ObCostMergeSetInfo cost_info(cost_infos, get_set_op(), stmt->get_select_item_size());
if (OB_FAIL(ObOptEstCost::cost_union_all(cost_info, op_cost, model_type))) {
if (OB_FAIL(ObOptEstCost::cost_union_all(cost_info,
op_cost,
get_plan()->get_optimizer_context()))) {
LOG_WARN("estimate cost of SET operator failed", K(ret));
}
} else if (MERGE_SET == set_algo_) {
ObCostMergeSetInfo cost_info(cost_infos, get_set_op(), stmt->get_select_item_size());
if (OB_FAIL(ObOptEstCost::cost_merge_set(cost_info, op_cost, model_type))) {
if (OB_FAIL(ObOptEstCost::cost_merge_set(cost_info,
op_cost,
get_plan()->get_optimizer_context()))) {
LOG_WARN("estimate cost of SET operator failed", K(ret));
}
} else if (HASH_SET == set_algo_) {
@ -490,7 +492,9 @@ int ObLogSet::do_re_est_cost(EstimateCostInfo &param, double &card, double &op_c
cost_infos.at(1).rows_, cost_infos.at(1).width_,
get_set_op(), select_exprs,
NULL, NULL /* no need for hash set*/ );
if (OB_FAIL(ObOptEstCost::cost_hash_set(hash_cost_info, op_cost, model_type))) {
if (OB_FAIL(ObOptEstCost::cost_hash_set(hash_cost_info,
op_cost,
get_plan()->get_optimizer_context()))) {
LOG_WARN("Fail to calcuate hash set cost", K(ret));
}
}

View File

@ -400,7 +400,7 @@ int ObLogSort::inner_est_cost(const int64_t parallel, double child_card, double
&get_plan()->get_selectivity_ctx(),
double_topn_count,
part_cnt_);
if (OB_FAIL(ObOptEstCost::cost_sort(cost_info, op_cost, opt_ctx.get_cost_model_type()))) {
if (OB_FAIL(ObOptEstCost::cost_sort(cost_info, op_cost, opt_ctx))) {
LOG_WARN("failed to calc cost", K(ret), K(child->get_type()));
} else if (NULL != topn_expr_) {
double_topn_count = std::min(double_topn_count * parallel, child_card);

View File

@ -257,7 +257,7 @@ int ObLogSubPlanFilter::do_re_est_cost(EstimateCostInfo &param, double &card, do
cost_info.rows_ = ObJoinOrder::calc_single_parallel_rows(cost_info.rows_, param.need_parallel_);
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
ObSubplanFilterCostInfo info(cost_infos, get_onetime_idxs(), get_initplan_idxs());
if (OB_FAIL(ObOptEstCost::cost_subplan_filter(info, op_cost, opt_ctx.get_cost_model_type()))) {
if (OB_FAIL(ObOptEstCost::cost_subplan_filter(info, op_cost, opt_ctx))) {
LOG_WARN("failed to calculate the cost of subplan filter", K(ret));
} else {
cost = op_cost + cost_info.cost_;

View File

@ -134,7 +134,7 @@ int ObLogSubPlanScan::do_re_est_cost(EstimateCostInfo &param, double &card, doub
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
op_cost = ObOptEstCost::cost_filter_rows(child_card / parallel,
get_filter_exprs(),
opt_ctx.get_cost_model_type());
opt_ctx);
cost = child_cost + op_cost;
card = child_card * selectivity;
}

View File

@ -139,9 +139,12 @@ int ObLogTableScan::do_re_est_cost(EstimateCostInfo &param, double &card, double
}
param.need_row_count_ = std::min(param.need_row_count_, card);
param.need_row_count_ += offset_count_double;
if (OB_FAIL(AccessPath::re_estimate_cost(param, *est_cost_info_, sample_info_,
opt_ctx->get_cost_model_type(),
card, op_cost))) {
if (OB_FAIL(AccessPath::re_estimate_cost(param,
*est_cost_info_,
sample_info_,
*opt_ctx,
card,
op_cost))) {
LOG_WARN("failed to re estimate cost", K(ret));
} else {
cost = op_cost;

View File

@ -132,8 +132,8 @@ int ObLogTempTableAccess::do_re_est_cost(EstimateCostInfo &param, double &card,
}
double per_dop_card = read_card / parallel;
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
cost = ObOptEstCost::cost_read_materialized(per_dop_card, opt_ctx.get_cost_model_type()) +
ObOptEstCost::cost_quals(per_dop_card, get_filter_exprs(), opt_ctx.get_cost_model_type());
cost = ObOptEstCost::cost_read_materialized(per_dop_card, opt_ctx) +
ObOptEstCost::cost_quals(per_dop_card, get_filter_exprs(), opt_ctx);
op_cost = cost;
}
return ret;

View File

@ -109,7 +109,7 @@ int ObLogTempTableInsert::do_re_est_cost(EstimateCostInfo &param, double &card,
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
op_cost = ObOptEstCost::cost_material(card / param.need_parallel_,
child->get_width(),
opt_ctx.get_cost_model_type());
opt_ctx);
cost += op_cost;
}
return ret;

View File

@ -132,7 +132,7 @@ int ObLogTopk::est_cost()
topk_card = std::min(topk_card, child->get_card());
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
double op_cost = ObOptEstCost::cost_get_rows(topk_card / parallel,
opt_ctx.get_cost_model_type());
opt_ctx);
set_card(topk_card);
set_op_cost(op_cost);
set_cost(child->get_cost() + op_cost);

View File

@ -230,7 +230,7 @@ int ObLogUnpivot::est_cost()
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
op_cost_ = ObOptEstCost::cost_filter_rows(card_ /parallel,
get_filter_exprs(),
opt_ctx.get_cost_model_type());
opt_ctx);
cost_ = op_cost_ + child->get_cost();
}
return ret;

View File

@ -167,7 +167,7 @@ int ObLogUpdate::inner_est_cost(double child_card, double &op_cost)
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
cost_info.constraint_count_ = update_dml_info->ck_cst_exprs_.count();
if (OB_FAIL(ObOptEstCost::cost_update(cost_info, op_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("failed to get update cost", K(ret));
}
}

View File

@ -252,7 +252,7 @@ int ObLogWindowFunction::est_cost()
first_child->get_width(),
win_exprs_.count(),
op_cost_,
get_plan()->get_optimizer_context().get_cost_model_type()))) {
get_plan()->get_optimizer_context()))) {
LOG_WARN("calculate cost of window function failed", K(ret));
} else {
set_card(first_child->get_card());
@ -283,7 +283,7 @@ int ObLogWindowFunction::do_re_est_cost(EstimateCostInfo &param, double &card, d
child->get_width(),
win_exprs_.count(),
op_cost,
opt_ctx.get_cost_model_type()))) {
opt_ctx))) {
LOG_WARN("calculate cost of window function failed", K(ret));
} else {
cost = child_cost + op_cost;

View File

@ -1086,7 +1086,7 @@ int ObLogicalOperator::do_re_est_cost(EstimateCostInfo &param, double &card, dou
double child_card = child->get_card();
double child_cost = child->get_cost();
ObOptimizerContext &opt_ctx = get_plan()->get_optimizer_context();
op_cost = ObOptEstCost::cost_get_rows(child_card / parallel, opt_ctx.get_cost_model_type());
op_cost = ObOptEstCost::cost_get_rows(child_card / parallel, opt_ctx);
if (OB_FAIL(SMART_CALL(child->re_est_cost(param, child_card, child_cost)))) {
LOG_WARN("failed to re est cost", K(ret));
} else if (OB_FAIL(ObOptSelectivity::calculate_selectivity(get_plan()->get_basic_table_metas(),

View File

@ -0,0 +1,385 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#define USING_LOG_PREFIX SQL_OPT
#include "ob_opt_cost_model_parameter.h"
#include "src/sql/optimizer/ob_optimizer_context.h"
using namespace oceanbase;
using namespace sql;
double ObOptCostModelParameter::get_cpu_tuple_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return CPU_TUPLE_COST;
} else {
return CPU_TUPLE_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_table_scan_cpu_tuple_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return TABLE_SCAN_CPU_TUPLE_COST;
} else {
return TABLE_SCAN_CPU_TUPLE_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_micro_block_seq_cost(const OptSystemStat& stat) const
{
if (stat.get_disk_seq_read_speed() <= 0 || stat.get_cpu_speed() <= 0) {
return MICRO_BLOCK_SEQ_COST;
} else {
return MICRO_BLOCK_SEQ_COST * 16 * 1024.0 / stat.get_disk_seq_read_speed();
}
}
double ObOptCostModelParameter::get_micro_block_rnd_cost(const OptSystemStat& stat) const
{
if (stat.get_disk_rnd_read_speed() <= 0 || stat.get_cpu_speed() <= 0) {
return MICRO_BLOCK_RND_COST;
} else {
return MICRO_BLOCK_RND_COST * 16 * 1024.0 / stat.get_disk_rnd_read_speed();
}
}
double ObOptCostModelParameter::get_project_column_cost(const OptSystemStat& stat,
PROJECT_TYPE type,
bool is_rnd,
bool use_column_store) const
{
if (stat.get_cpu_speed() <= 0) {
return project_params_[use_column_store][is_rnd][type];
} else {
return project_params_[use_column_store][is_rnd][type] / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_fetch_row_rnd_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return FETCH_ROW_RND_COST;
} else {
return FETCH_ROW_RND_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_cmp_spatial_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return CMP_SPATIAL_COST;
} else {
return CMP_SPATIAL_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_materialize_per_byte_write_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return MATERIALIZE_PER_BYTE_WRITE_COST;
} else {
return MATERIALIZE_PER_BYTE_WRITE_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_read_materialized_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return READ_MATERIALIZED_PER_ROW_COST;
} else {
return READ_MATERIALIZED_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_per_aggr_func_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return PER_AGGR_FUNC_COST;
} else {
return PER_AGGR_FUNC_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_per_win_func_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return PER_WIN_FUNC_COST;
} else {
return PER_WIN_FUNC_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_cpu_operator_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return CPU_OPERATOR_COST;
} else {
return CPU_OPERATOR_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_join_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return JOIN_PER_ROW_COST;
} else {
return JOIN_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_build_hash_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return BUILD_HASH_PER_ROW_COST;
} else {
return BUILD_HASH_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_probe_hash_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return PROBE_HASH_PER_ROW_COST;
} else {
return PROBE_HASH_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_rescan_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return RESCAN_COST;
} else {
return RESCAN_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_network_ser_per_byte_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return NETWORK_SER_PER_BYTE_COST;
} else {
return NETWORK_SER_PER_BYTE_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_network_deser_per_byte_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return NETWORK_DESER_PER_BYTE_COST;
} else {
return NETWORK_DESER_PER_BYTE_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_network_trans_per_byte_cost(const OptSystemStat& stat) const
{
if (stat.get_network_speed() <= 0) {
return NETWORK_TRANS_PER_BYTE_COST;
} else {
return NETWORK_TRANS_PER_BYTE_COST / stat.get_network_speed();
}
}
double ObOptCostModelParameter::get_px_rescan_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return PX_RESCAN_PER_ROW_COST;
} else {
return PX_RESCAN_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_px_batch_rescan_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return PX_BATCH_RESCAN_PER_ROW_COST;
} else {
return PX_BATCH_RESCAN_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_nl_scan_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return NL_SCAN_COST;
} else {
return NL_SCAN_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_batch_nl_scan_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return BATCH_NL_SCAN_COST;
} else {
return BATCH_NL_SCAN_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_nl_get_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return NL_GET_COST;
} else {
return NL_GET_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_batch_nl_get_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return BATCH_NL_GET_COST;
} else {
return BATCH_NL_GET_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_table_loopup_per_row_rpc_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return TABLE_LOOPUP_PER_ROW_RPC_COST;
} else {
return TABLE_LOOPUP_PER_ROW_RPC_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_insert_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return INSERT_PER_ROW_COST;
} else {
return INSERT_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_insert_index_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return INSERT_INDEX_PER_ROW_COST;
} else {
return INSERT_INDEX_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_insert_check_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return INSERT_CHECK_PER_ROW_COST;
} else {
return INSERT_CHECK_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_update_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return UPDATE_PER_ROW_COST;
} else {
return UPDATE_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_update_index_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return UPDATE_INDEX_PER_ROW_COST;
} else {
return UPDATE_INDEX_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_update_check_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return UPDATE_CHECK_PER_ROW_COST;
} else {
return UPDATE_CHECK_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_delete_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return DELETE_PER_ROW_COST;
} else {
return DELETE_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_delete_index_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return DELETE_INDEX_PER_ROW_COST;
} else {
return DELETE_INDEX_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_delete_check_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return DELETE_CHECK_PER_ROW_COST;
} else {
return DELETE_CHECK_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_spatial_per_row_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return SPATIAL_PER_ROW_COST;
} else {
return SPATIAL_PER_ROW_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_range_cost(const OptSystemStat& stat) const
{
if (stat.get_cpu_speed() <= 0) {
return RANGE_COST;
} else {
return RANGE_COST / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_comparison_cost(const OptSystemStat& stat, int64_t type) const
{
double cost = 0;
if (type >=0 && type <= ObMaxTC) {
cost = comparison_params_[type];
} else {
cost = comparison_params_[0];
}
if (stat.get_cpu_speed() <= 0) {
return cost;
} else {
return cost / stat.get_cpu_speed();
}
}
double ObOptCostModelParameter::get_hash_cost(const OptSystemStat& stat, int64_t type) const
{
double cost = 0;
if (type >=0 && type <= ObMaxTC) {
cost = hash_params_[type];
} else {
cost = hash_params_[0];
}
if (stat.get_cpu_speed() <= 0) {
return cost;
} else {
return cost / stat.get_cpu_speed();
}
}

View File

@ -0,0 +1,248 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#ifndef OCEANBASE_SQL_OPTIMIZER_OB_OPT_EST_PARAMETER_
#define OCEANBASE_SQL_OPTIMIZER_OB_OPT_EST_PARAMETER_
#include "common/object/ob_obj_type.h"
#define DEFAULT_CPU_SPEED 2500
#define DEFAULT_DISK_SEQ_READ_SPEED 1024
#define DEFAULT_DISK_RND_READ_SPEED 512
#define DEFAULT_NETWORK_SPEED 156
#define DEFAULT_MACR_BLOCK_SIZE (16 * 1024)
namespace oceanbase
{
namespace sql
{
class OptSystemStat;
enum PROJECT_TYPE {
PROJECT_INT = 0,
PROJECT_NUMBER,
PROJECT_CHAR,
MAX_PROJECT_TYPE
};
class ObOptCostModelParameter {
public:
explicit ObOptCostModelParameter(
const double DEFAULT_CPU_TUPLE_COST,
const double DEFAULT_TABLE_SCAN_CPU_TUPLE_COST,
const double DEFAULT_MICRO_BLOCK_SEQ_COST,
const double DEFAULT_MICRO_BLOCK_RND_COST,
const double DEFAULT_FETCH_ROW_RND_COST,
const double DEFAULT_CMP_GEO_COST,
const double DEFAULT_MATERIALIZE_PER_BYTE_WRITE_COST,
const double DEFAULT_READ_MATERIALIZED_PER_ROW_COST,
const double DEFAULT_PER_AGGR_FUNC_COST,
const double DEFAULT_PER_WIN_FUNC_COST,
const double DEFAULT_CPU_OPERATOR_COST,
const double DEFAULT_JOIN_PER_ROW_COST,
const double DEFAULT_BUILD_HASH_PER_ROW_COST,
const double DEFAULT_PROBE_HASH_PER_ROW_COST,
const double DEFAULT_RESCAN_COST,
const double DEFAULT_NETWORK_SER_PER_BYTE_COST,
const double DEFAULT_NETWORK_DESER_PER_BYTE_COST,
const double DEFAULT_NETWORK_TRANS_PER_BYTE_COST,
const double DEFAULT_PX_RESCAN_PER_ROW_COST,
const double DEFAULT_PX_BATCH_RESCAN_PER_ROW_COST,
const double DEFAULT_NL_SCAN_COST,
const double DEFAULT_BATCH_NL_SCAN_COST,
const double DEFAULT_NL_GET_COST,
const double DEFAULT_BATCH_NL_GET_COST,
const double DEFAULT_TABLE_LOOPUP_PER_ROW_RPC_COST,
const double DEFAULT_INSERT_PER_ROW_COST,
const double DEFAULT_INSERT_INDEX_PER_ROW_COST,
const double DEFAULT_INSERT_CHECK_PER_ROW_COST,
const double DEFAULT_UPDATE_PER_ROW_COST,
const double DEFAULT_UPDATE_INDEX_PER_ROW_COST,
const double DEFAULT_UPDATE_CHECK_PER_ROW_COST,
const double DEFAULT_DELETE_PER_ROW_COST,
const double DEFAULT_DELETE_INDEX_PER_ROW_COST,
const double DEFAULT_DELETE_CHECK_PER_ROW_COST,
const double DEFAULT_SPATIAL_PER_ROW_COST,
const double DEFAULT_RANGE_COST,
const double (&comparison_params)[common::ObMaxTC + 1],
const double (&hash_params)[common::ObMaxTC + 1],
const double (&project_params)[2][2][MAX_PROJECT_TYPE]
)
: CPU_TUPLE_COST(DEFAULT_CPU_TUPLE_COST),
TABLE_SCAN_CPU_TUPLE_COST(DEFAULT_TABLE_SCAN_CPU_TUPLE_COST),
MICRO_BLOCK_SEQ_COST(DEFAULT_MICRO_BLOCK_SEQ_COST),
MICRO_BLOCK_RND_COST(DEFAULT_MICRO_BLOCK_RND_COST),
FETCH_ROW_RND_COST(DEFAULT_FETCH_ROW_RND_COST),
CMP_SPATIAL_COST(DEFAULT_CMP_GEO_COST),
MATERIALIZE_PER_BYTE_WRITE_COST(DEFAULT_MATERIALIZE_PER_BYTE_WRITE_COST),
READ_MATERIALIZED_PER_ROW_COST(DEFAULT_READ_MATERIALIZED_PER_ROW_COST),
PER_AGGR_FUNC_COST(DEFAULT_PER_AGGR_FUNC_COST),
PER_WIN_FUNC_COST(DEFAULT_PER_WIN_FUNC_COST),
CPU_OPERATOR_COST(DEFAULT_CPU_OPERATOR_COST),
JOIN_PER_ROW_COST(DEFAULT_JOIN_PER_ROW_COST),
BUILD_HASH_PER_ROW_COST(DEFAULT_BUILD_HASH_PER_ROW_COST),
PROBE_HASH_PER_ROW_COST(DEFAULT_PROBE_HASH_PER_ROW_COST),
RESCAN_COST(DEFAULT_RESCAN_COST),
NETWORK_SER_PER_BYTE_COST(DEFAULT_NETWORK_SER_PER_BYTE_COST),
NETWORK_DESER_PER_BYTE_COST(DEFAULT_NETWORK_DESER_PER_BYTE_COST),
NETWORK_TRANS_PER_BYTE_COST(DEFAULT_NETWORK_TRANS_PER_BYTE_COST),
PX_RESCAN_PER_ROW_COST(DEFAULT_PX_RESCAN_PER_ROW_COST),
PX_BATCH_RESCAN_PER_ROW_COST(DEFAULT_PX_BATCH_RESCAN_PER_ROW_COST),
NL_SCAN_COST(DEFAULT_NL_SCAN_COST),
BATCH_NL_SCAN_COST(DEFAULT_BATCH_NL_SCAN_COST),
NL_GET_COST(DEFAULT_NL_GET_COST),
BATCH_NL_GET_COST(DEFAULT_BATCH_NL_GET_COST),
TABLE_LOOPUP_PER_ROW_RPC_COST(DEFAULT_TABLE_LOOPUP_PER_ROW_RPC_COST),
INSERT_PER_ROW_COST(DEFAULT_INSERT_PER_ROW_COST),
INSERT_INDEX_PER_ROW_COST(DEFAULT_INSERT_INDEX_PER_ROW_COST),
INSERT_CHECK_PER_ROW_COST(DEFAULT_INSERT_CHECK_PER_ROW_COST),
UPDATE_PER_ROW_COST(DEFAULT_UPDATE_PER_ROW_COST),
UPDATE_INDEX_PER_ROW_COST(DEFAULT_UPDATE_INDEX_PER_ROW_COST),
UPDATE_CHECK_PER_ROW_COST(DEFAULT_UPDATE_CHECK_PER_ROW_COST),
DELETE_PER_ROW_COST(DEFAULT_DELETE_PER_ROW_COST),
DELETE_INDEX_PER_ROW_COST(DEFAULT_DELETE_INDEX_PER_ROW_COST),
DELETE_CHECK_PER_ROW_COST(DEFAULT_DELETE_CHECK_PER_ROW_COST),
SPATIAL_PER_ROW_COST(DEFAULT_SPATIAL_PER_ROW_COST),
RANGE_COST(DEFAULT_RANGE_COST),
comparison_params_(comparison_params),
hash_params_(hash_params),
project_params_(project_params)
{
}
double get_cpu_tuple_cost(const OptSystemStat& stat) const;
double get_table_scan_cpu_tuple_cost(const OptSystemStat& stat) const;
double get_micro_block_seq_cost(const OptSystemStat& stat) const;
double get_micro_block_rnd_cost(const OptSystemStat& stat) const;
double get_project_column_cost(const OptSystemStat& stat,
PROJECT_TYPE type,
bool is_rnd,
bool use_column_store) const;
double get_fetch_row_rnd_cost(const OptSystemStat& stat) const;
double get_cmp_spatial_cost(const OptSystemStat& stat) const;
double get_materialize_per_byte_write_cost(const OptSystemStat& stat) const;
double get_read_materialized_per_row_cost(const OptSystemStat& stat) const;
double get_per_aggr_func_cost(const OptSystemStat& stat) const;
double get_per_win_func_cost(const OptSystemStat& stat) const;
double get_cpu_operator_cost(const OptSystemStat& stat) const;
double get_join_per_row_cost(const OptSystemStat& stat) const;
double get_build_hash_per_row_cost(const OptSystemStat& stat) const;
double get_probe_hash_per_row_cost(const OptSystemStat& stat) const;
double get_rescan_cost(const OptSystemStat& stat) const;
double get_network_ser_per_byte_cost(const OptSystemStat& stat) const;
double get_network_deser_per_byte_cost(const OptSystemStat& stat) const;
double get_network_trans_per_byte_cost(const OptSystemStat& stat) const;
double get_px_rescan_per_row_cost(const OptSystemStat& stat) const;
double get_px_batch_rescan_per_row_cost(const OptSystemStat& stat) const;
double get_nl_scan_cost(const OptSystemStat& stat) const;
double get_batch_nl_scan_cost(const OptSystemStat& stat) const;
double get_nl_get_cost(const OptSystemStat& stat) const;
double get_batch_nl_get_cost(const OptSystemStat& stat) const;
double get_table_loopup_per_row_rpc_cost(const OptSystemStat& stat) const;
double get_insert_per_row_cost(const OptSystemStat& stat) const;
double get_insert_index_per_row_cost(const OptSystemStat& stat) const;
double get_insert_check_per_row_cost(const OptSystemStat& stat) const;
double get_update_per_row_cost(const OptSystemStat& stat) const;
double get_update_index_per_row_cost(const OptSystemStat& stat) const;
double get_update_check_per_row_cost(const OptSystemStat& stat) const;
double get_delete_per_row_cost(const OptSystemStat& stat) const;
double get_delete_index_per_row_cost(const OptSystemStat& stat) const;
double get_delete_check_per_row_cost(const OptSystemStat& stat) const;
double get_spatial_per_row_cost(const OptSystemStat& stat) const;
double get_range_cost(const OptSystemStat& stat) const;
double get_comparison_cost(const OptSystemStat& stat, int64_t type) const;
double get_hash_cost(const OptSystemStat& stat, int64_t type) const;
protected:
/** 读取一行的CPU开销,基本上只包括get_next_row()操作 */
double CPU_TUPLE_COST;
/** 存储层吐出一行的代价 **/
double TABLE_SCAN_CPU_TUPLE_COST;
/** 顺序读取一个微块并反序列化的开销 */
double MICRO_BLOCK_SEQ_COST;
/** 随机读取一个微块并反序列化的开销 */
double MICRO_BLOCK_RND_COST;
/** 随机读取中定位某一行所在位置的开销 */
double FETCH_ROW_RND_COST;
/** 比较一次空间数据的代价 */
double CMP_SPATIAL_COST;
/** 物化一个字节的代价 */
double MATERIALIZE_PER_BYTE_WRITE_COST;
/** 读取物化后的行的代价,即对物化后数据结构的get_next_row() */
double READ_MATERIALIZED_PER_ROW_COST;
/** 一次聚集函数计算的代价 */
double PER_AGGR_FUNC_COST;
/** 一次窗口函数计算的代价 */
double PER_WIN_FUNC_COST;
/** 一次操作的基本代价 */
double CPU_OPERATOR_COST;
/** 连接两表的一行的基本代价 */
double JOIN_PER_ROW_COST;
/** 构建hash table时每行的均摊代价 */
double BUILD_HASH_PER_ROW_COST;
/** 查询hash table时每行的均摊代价 */
double PROBE_HASH_PER_ROW_COST;
double RESCAN_COST;
/*network serialization cost for one byte*/
double NETWORK_SER_PER_BYTE_COST;
/*network de-serialization cost for one byte*/
double NETWORK_DESER_PER_BYTE_COST;
/** 网络传输1个字节的代价 */
double NETWORK_TRANS_PER_BYTE_COST;
/*additional px-rescan cost*/
double PX_RESCAN_PER_ROW_COST;
double PX_BATCH_RESCAN_PER_ROW_COST;
//条件下压nestloop join右表扫一次的代价
double NL_SCAN_COST;
//条件下压batch nestloop join右表扫一次的代价
double BATCH_NL_SCAN_COST;
//条件下压nestloop join右表GET一次的代价
double NL_GET_COST;
//条件下压batch nestloop join右表GET一次的代价
double BATCH_NL_GET_COST;
//table look up一行的rpc代价
double TABLE_LOOPUP_PER_ROW_RPC_COST;
//insert一行主表的代价
double INSERT_PER_ROW_COST;
//insert一行索引表的代价
double INSERT_INDEX_PER_ROW_COST;
//insert单个约束检查代价
double INSERT_CHECK_PER_ROW_COST;
//update一行主表的代价
double UPDATE_PER_ROW_COST;
//update一行索引表的代价
double UPDATE_INDEX_PER_ROW_COST;
//update单个约束检查代价
double UPDATE_CHECK_PER_ROW_COST;
//delete一行主表的代价
double DELETE_PER_ROW_COST;
//delete一行索引表的代价
double DELETE_INDEX_PER_ROW_COST;
//delete单个约束检查代价
double DELETE_CHECK_PER_ROW_COST;
//空间索引扫描的线性参数
double SPATIAL_PER_ROW_COST;
//存储层切换一次range的代价
double RANGE_COST;
const double (&comparison_params_)[common::ObMaxTC + 1];
const double (&hash_params_)[common::ObMaxTC + 1]; /*
* +-sequence access project
* +-row store----+
* | +-random access project
* project cost-+
* | +-sequence access project
* +-column store-+
* +-random access project
*/
const double (&project_params_)[2][2][MAX_PROJECT_TYPE];
};
}
}
#endif /*OCEANBASE_SQL_OPTIMIZER_OB_OPT_EST_PARAMETER_*/

View File

@ -25,6 +25,19 @@
#include "ob_opt_est_parameter_vector.h"
#include "share/stat/ob_opt_stat_manager.h"
#include "ob_opt_est_cost_model_vector.h"
#include "ob_opt_est_parameter_normal.h"
#include "ob_opt_est_parameter_vector.h"
#define GET_COST_MODEL() \
ObOptEstCostModel normal_model(cost_params_normal, \
opt_ctx.get_system_stat()); \
ObOptEstVectorCostModel vector_model(cost_params_vector, \
opt_ctx.get_system_stat()); \
ObOptEstCostModel *model = &normal_model; \
if (VECTOR_MODEL == opt_ctx.get_cost_model_type()) { \
model = &vector_model; \
} \
using namespace oceanbase::common;
using namespace oceanbase::share;
@ -35,48 +48,44 @@ using namespace oceanbase::jit::expr;
// using share::schema::ObSchemaGetterGuard;
const int64_t ObOptEstCost::MAX_STORAGE_RANGE_ESTIMATION_NUM = 10;
ObOptEstCostModel normal_model_(comparison_params_normal,
hash_params_normal,
project_params_normal,
cost_params_normal);
ObOptEstVectorCostModel vector_model_(comparison_params_vector,
hash_params_vector,
project_params_vector,
cost_params_vector);
int ObOptEstCost::cost_nestloop(const ObCostNLJoinInfo &est_cost_info,
double &cost,
ObIArray<ObExprSelPair> &all_predicate_sel,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_nestloop(est_cost_info,
cost,
all_predicate_sel))) {
LOG_WARN("failed to est cost for nestloop join", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_nestloop(est_cost_info,
cost,
all_predicate_sel))) {
LOG_WARN("failed to est cost for nestloop join", K(ret));
}
return ret;
}
int ObOptEstCost::cost_mergejoin(const ObCostMergeJoinInfo &est_cost_info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_mergejoin(est_cost_info, cost))) {
LOG_WARN("failed to est cost for merge join", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_mergejoin(est_cost_info,
cost))) {
LOG_WARN("failed to est cost for merge join", K(ret));
}
return ret;
}
int ObOptEstCost::cost_hashjoin(const ObCostHashJoinInfo &est_cost_info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_hashjoin(est_cost_info, cost))) {
LOG_WARN("failed to est cost for hash join", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_hashjoin(est_cost_info,
cost))) {
LOG_WARN("failed to est cost for hash join", K(ret));
}
return ret;
}
@ -96,69 +105,78 @@ int ObOptEstCost::cost_sort_and_exchange(OptTableMetas *table_metas,
const bool need_sort,
const int64_t prefix_pos,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_sort_and_exchange(table_metas,
sel_ctx,
dist_method,
is_distributed,
is_local_order,
input_card,
input_width,
input_cost,
out_parallel,
in_server_cnt,
in_parallel,
expected_ordering,
need_sort,
prefix_pos,
cost))) {
LOG_WARN("failed to est cost for sort and exchange", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_sort_and_exchange(table_metas,
sel_ctx,
dist_method,
is_distributed,
is_local_order,
input_card,
input_width,
input_cost,
out_parallel,
in_server_cnt,
in_parallel,
expected_ordering,
need_sort,
prefix_pos,
cost))) {
LOG_WARN("failed to est cost for sort and exchange", K(ret));
}
return ret;
}
int ObOptEstCost::cost_sort(const ObSortCostInfo &cost_info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_sort(cost_info, cost))) {
LOG_WARN("failed to est cost for sort", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_sort(cost_info,
cost))) {
LOG_WARN("failed to est cost for sort", K(ret));
}
return ret;
}
int ObOptEstCost::cost_exchange(const ObExchCostInfo &cost_info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_exchange(cost_info, cost))) {
LOG_WARN("failed to est cost for exchange", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_exchange(cost_info,
cost))) {
LOG_WARN("failed to est cost for exchange", K(ret));
}
return ret;
}
int ObOptEstCost::cost_exchange_in(const ObExchInCostInfo &cost_info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_exchange_in(cost_info, cost))) {
LOG_WARN("failed to est cost for exchange in", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_exchange_in(cost_info,
cost))) {
LOG_WARN("failed to est cost for exchange in", K(ret));
}
return ret;
}
int ObOptEstCost::cost_exchange_out(const ObExchOutCostInfo &cost_info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_exchange_out(cost_info, cost))) {
LOG_WARN("failed to est cost for exchange out", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_exchange_out(cost_info,
cost))) {
LOG_WARN("failed to est cost for exchange out", K(ret));
}
return ret;
}
@ -168,13 +186,14 @@ double ObOptEstCost::cost_merge_group(double rows,
double row_width,
const ObIArray<ObRawExpr *> &group_columns,
int64_t agg_col_count,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
return get_model(model_type).cost_merge_group(rows,
res_rows,
row_width,
group_columns,
agg_col_count);
GET_COST_MODEL();
return model->cost_merge_group(rows,
res_rows,
row_width,
group_columns,
agg_col_count);
}
double ObOptEstCost::cost_hash_group(double rows,
@ -182,140 +201,161 @@ double ObOptEstCost::cost_hash_group(double rows,
double row_width,
const ObIArray<ObRawExpr *> &group_columns,
int64_t agg_col_count,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
return get_model(model_type).cost_hash_group(rows,
res_rows,
row_width,
group_columns,
agg_col_count);
GET_COST_MODEL();
return model->cost_hash_group(rows,
res_rows,
row_width,
group_columns,
agg_col_count);
}
double ObOptEstCost::cost_scalar_group(double rows,
int64_t agg_col_count,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
return get_model(model_type).cost_scalar_group(rows, agg_col_count);
GET_COST_MODEL();
return model->cost_scalar_group(rows,
agg_col_count);
}
double ObOptEstCost::cost_merge_distinct(double rows,
double res_rows,
double row_width,
const ObIArray<ObRawExpr *> &distinct_columns,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
return get_model(model_type).cost_merge_distinct(rows,
res_rows,
row_width,
distinct_columns);
GET_COST_MODEL();
return model->cost_merge_distinct(rows,
res_rows,
row_width,
distinct_columns);
}
double ObOptEstCost::cost_hash_distinct(double rows,
double res_rows,
double row_width,
const ObIArray<ObRawExpr *> &distinct_columns,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
return get_model(model_type).cost_hash_distinct(rows,
res_rows,
row_width,
distinct_columns);
GET_COST_MODEL();
return model->cost_hash_distinct(rows,
res_rows,
row_width,
distinct_columns);
}
double ObOptEstCost::cost_sequence(double rows,
double uniq_sequence_cnt,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
return get_model(model_type).cost_sequence(rows, uniq_sequence_cnt);
GET_COST_MODEL();
return model->cost_sequence(rows,
uniq_sequence_cnt);
}
double ObOptEstCost::cost_get_rows(double rows, MODEL_TYPE model_type)
double ObOptEstCost::cost_get_rows(double rows, const ObOptimizerContext &opt_ctx)
{
return get_model(model_type).cost_get_rows(rows);
GET_COST_MODEL();
return model->cost_get_rows(rows);
}
double ObOptEstCost::cost_read_materialized(double rows, MODEL_TYPE model_type)
double ObOptEstCost::cost_read_materialized(double rows, const ObOptimizerContext &opt_ctx)
{
return get_model(model_type).cost_read_materialized(rows);
GET_COST_MODEL();
return model->cost_read_materialized(rows);
}
double ObOptEstCost::cost_material(const double rows,
const double average_row_size,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
return get_model(model_type).cost_material(rows, average_row_size);
GET_COST_MODEL();
return model->cost_material(rows,
average_row_size);
}
double ObOptEstCost::cost_filter_rows(double rows,
ObIArray<ObRawExpr*> &filters,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
return get_model(model_type).cost_filter_rows(rows, filters);
GET_COST_MODEL();
return model->cost_filter_rows(rows,
filters);
}
int ObOptEstCost::cost_subplan_filter(const ObSubplanFilterCostInfo &info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_subplan_filter(info, cost))) {
LOG_WARN("failed to est cost for subplan filter", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_subplan_filter(info, cost))) {
LOG_WARN("failed to est cost for subplan filter", K(ret));
}
return ret;
}
int ObOptEstCost::cost_union_all(const ObCostMergeSetInfo &info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_union_all(info, cost))) {
LOG_WARN("failed to est cost for union all", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_union_all(info,
cost))) {
LOG_WARN("failed to est cost for union all", K(ret));
}
return ret;
}
int ObOptEstCost::cost_merge_set(const ObCostMergeSetInfo &info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_merge_set(info, cost))) {
LOG_WARN("failed to est cost for merge set", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_merge_set(info,
cost))) {
LOG_WARN("failed to est cost for merge set", K(ret));
}
return ret;
}
int ObOptEstCost::cost_hash_set(const ObCostHashSetInfo &info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_hash_set(info, cost))) {
LOG_WARN("failed to est cost for hash set", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_hash_set(info,
cost))) {
LOG_WARN("failed to est cost for hash set", K(ret));
}
return ret;
}
double ObOptEstCost::cost_quals(double rows,
const ObIArray<ObRawExpr *> &quals,
MODEL_TYPE model_type,
const ObOptimizerContext &opt_ctx,
bool need_scale)
{
return get_model(model_type).cost_quals(rows, quals, need_scale);
GET_COST_MODEL();
return model->cost_quals(rows, quals, need_scale);
}
int ObOptEstCost::cost_table(const ObCostTableScanInfo &est_cost_info,
int64_t parallel,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
double index_back_cost = 0;
if (OB_FAIL(get_model(model_type).cost_table(est_cost_info,
parallel,
cost))) {
LOG_WARN("failed to est cost for table scan", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_table(est_cost_info,
parallel,
cost))) {
LOG_WARN("failed to est cost for table scan", K(ret));
}
return ret;
}
@ -325,22 +365,24 @@ int ObOptEstCost::cost_table_for_parallel(const ObCostTableScanInfo &est_cost_in
const double part_cnt_per_dop,
double &px_cost,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_table_for_parallel(est_cost_info,
GET_COST_MODEL();
if (OB_FAIL(model->cost_table_for_parallel(est_cost_info,
parallel,
part_cnt_per_dop,
px_cost,
cost))) {
LOG_WARN("failed to est cost for table scan parallel", K(model_type), K(ret));
LOG_WARN("failed to est cost for table scan parallel", K(ret));
}
return ret;
}
double ObOptEstCost::cost_late_materialization_table_get(int64_t column_cnt, MODEL_TYPE model_type)
double ObOptEstCost::cost_late_materialization_table_get(int64_t column_cnt, const ObOptimizerContext &opt_ctx)
{
return get_model(model_type).cost_late_materialization_table_get(column_cnt);
GET_COST_MODEL();
return model->cost_late_materialization_table_get(column_cnt);
}
void ObOptEstCost::cost_late_materialization_table_join(double left_card,
@ -349,76 +391,82 @@ void ObOptEstCost::cost_late_materialization_table_join(double left_card,
double right_cost,
double &op_cost,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
get_model(model_type).cost_late_materialization_table_join(left_card,
left_cost,
right_card,
right_cost,
op_cost,
cost);
GET_COST_MODEL();
model->cost_late_materialization_table_join(left_card,
left_cost,
right_card,
right_cost,
op_cost,
cost);
}
void ObOptEstCost::cost_late_materialization(double left_card,
double left_cost,
int64_t column_count,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
get_model(model_type).cost_late_materialization(left_card,
left_cost,
column_count,
cost);
GET_COST_MODEL();
model->cost_late_materialization(left_card,
left_cost,
column_count,
cost);
}
int ObOptEstCost::cost_window_function(double rows,
double width,
double win_func_cnt,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_window_function(rows,
width,
win_func_cnt,
cost))) {
LOG_WARN("failed to est cost for window function", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_window_function(rows,
width,
win_func_cnt,
cost))) {
LOG_WARN("failed to est cost for window function", K(ret));
}
return ret;
}
int ObOptEstCost::cost_insert(ObDelUpCostInfo& cost_info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_insert(cost_info,
cost))) {
LOG_WARN("failed to est cost for insert", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_insert(cost_info,
cost))) {
LOG_WARN("failed to est cost for insert", K(ret));
}
return ret;
}
int ObOptEstCost::cost_update(ObDelUpCostInfo& cost_info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_update(cost_info,
cost))) {
LOG_WARN("failed to est cost for update", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_update(cost_info,
cost))) {
LOG_WARN("failed to est cost for update", K(ret));
}
return ret;
}
int ObOptEstCost::cost_delete(ObDelUpCostInfo& cost_info,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).cost_delete(cost_info,
cost))) {
LOG_WARN("failed to est cost for delete", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->cost_delete(cost_info,
cost))) {
LOG_WARN("failed to est cost for delete", K(ret));
}
return ret;
}
@ -429,16 +477,17 @@ int ObOptEstCost::calc_range_cost(const ObTableMetaInfo& table_meta_info,
int64_t range_count,
double range_sel,
double &cost,
MODEL_TYPE model_type)
const ObOptimizerContext &opt_ctx)
{
int ret = OB_SUCCESS;
if (OB_FAIL(get_model(model_type).calc_range_cost(table_meta_info,
filters,
index_column_count,
range_count,
range_sel,
cost))) {
LOG_WARN("failed to est cost for range scan", K(model_type), K(ret));
GET_COST_MODEL();
if (OB_FAIL(model->calc_range_cost(table_meta_info,
filters,
index_column_count,
range_count,
range_sel,
cost))) {
LOG_WARN("failed to est cost for range scan", K(ret));
}
return ret;
}
@ -707,11 +756,3 @@ int ObOptEstCost::stat_estimate_single_range_rc(const ObCostTableScanInfo &est_c
return ret;
}
ObOptEstCostModel &ObOptEstCost::get_model(MODEL_TYPE model_type)
{
if (VECTOR_MODEL == model_type) {
return vector_model_;
} else {
return normal_model_;
}
}

View File

@ -25,6 +25,7 @@ struct ObExprSelPair;
struct JoinFilterInfo;
class OptTableMetas;
class OptSelectivityCtx;
class ObOptimizerContext;
class ObOptEstCost
{
@ -38,15 +39,15 @@ public:
static int cost_nestloop(const ObCostNLJoinInfo &est_cost_info,
double &cost,
common::ObIArray<ObExprSelPair> &all_predicate_sel,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static int cost_mergejoin(const ObCostMergeJoinInfo &est_cost_info,
double &cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static int cost_hashjoin(const ObCostHashJoinInfo &est_cost_info,
double &cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static int cost_sort_and_exchange(OptTableMetas *table_metas,
OptSelectivityCtx *sel_ctx,
@ -63,75 +64,91 @@ public:
const bool need_sort,
const int64_t prefix_pos,
double &cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static int cost_sort(const ObSortCostInfo &cost_info,
double &cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static int cost_exchange(const ObExchCostInfo &cost_info,
double &ex_cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static int cost_exchange_in(const ObExchInCostInfo &cost_info,
double &cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static int cost_exchange_out(const ObExchOutCostInfo &cost_info,
double &cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static double cost_merge_group(double rows,
double res_rows,
double width,
const ObIArray<ObRawExpr *> &group_columns,
int64_t agg_col_count,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static double cost_hash_group(double rows,
double res_rows,
double width,
const ObIArray<ObRawExpr *> &group_columns,
int64_t agg_col_count,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static double cost_scalar_group(double rows,
int64_t agg_col_count,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static double cost_merge_distinct(double rows,
double res_rows,
double width,
const ObIArray<ObRawExpr *> &distinct_columns,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static double cost_hash_distinct(double rows,
double res_rows,
double width,
const ObIArray<ObRawExpr *> &disinct_columns,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static double cost_get_rows(double rows, MODEL_TYPE model_type);
static double cost_get_rows(double rows,
const ObOptimizerContext &opt_ctx);
static double cost_sequence(double rows, double uniq_sequence_cnt, MODEL_TYPE model_type);
static double cost_sequence(double rows,
double uniq_sequence_cnt,
const ObOptimizerContext &opt_ctx);
static double cost_material(const double rows, const double average_row_size, MODEL_TYPE model_type);
static double cost_material(const double rows,
const double average_row_size,
const ObOptimizerContext &opt_ctx);
static double cost_read_materialized(const double rows, MODEL_TYPE model_type);
static double cost_read_materialized(const double rows,
const ObOptimizerContext &opt_ctx);
static double cost_filter_rows(double rows, ObIArray<ObRawExpr*> &filters, MODEL_TYPE model_type);
static double cost_filter_rows(double rows,
ObIArray<ObRawExpr*> &filters,
const ObOptimizerContext &opt_ctx);
static int cost_subplan_filter(const ObSubplanFilterCostInfo &info, double &cost, MODEL_TYPE model_type);
static int cost_subplan_filter(const ObSubplanFilterCostInfo &info,
double &cost,
const ObOptimizerContext &opt_ctx);
static int cost_union_all(const ObCostMergeSetInfo &info, double &cost, MODEL_TYPE model_type);
static int cost_union_all(const ObCostMergeSetInfo &info,
double &cost,
const ObOptimizerContext &opt_ctx);
static int cost_merge_set(const ObCostMergeSetInfo &info, double &cost, MODEL_TYPE model_type);
static int cost_merge_set(const ObCostMergeSetInfo &info,
double &cost,
const ObOptimizerContext &opt_ctx);
static int cost_hash_set(const ObCostHashSetInfo &info, double &cost, MODEL_TYPE model_type);
static int cost_hash_set(const ObCostHashSetInfo &info,
double &cost,
const ObOptimizerContext &opt_ctx);
static double cost_quals(double rows,
const ObIArray<ObRawExpr *> &quals,
MODEL_TYPE model_type,
const ObOptimizerContext &opt_ctx,
bool need_scale = true);
/*
* entry point for estimating table access cost
@ -139,16 +156,17 @@ public:
static int cost_table(const ObCostTableScanInfo &est_cost_info,
int64_t parallel,
double &cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static int cost_table_for_parallel(const ObCostTableScanInfo &est_cost_info,
const int64_t parallel,
const double part_cnt_per_dop,
double &px_cost,
double &cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static double cost_late_materialization_table_get(int64_t column_cnt, MODEL_TYPE model_type);
static double cost_late_materialization_table_get(int64_t column_cnt,
const ObOptimizerContext &opt_ctx);
static void cost_late_materialization_table_join(double left_card,
double left_cost,
@ -156,25 +174,31 @@ public:
double right_cost,
double &op_cost,
double &cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static void cost_late_materialization(double left_card,
double left_cost,
int64_t column_count,
double &cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static int cost_window_function(double rows,
double width,
double win_func_cnt,
double &cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static int cost_insert(ObDelUpCostInfo& cost_info, double &cost, MODEL_TYPE model_type);
static int cost_insert(ObDelUpCostInfo& cost_info,
double &cost,
const ObOptimizerContext &opt_ctx);
static int cost_update(ObDelUpCostInfo& cost_info, double &cost, MODEL_TYPE model_type);
static int cost_update(ObDelUpCostInfo& cost_info,
double &cost,
const ObOptimizerContext &opt_ctx);
static int cost_delete(ObDelUpCostInfo& cost_info, double &cost, MODEL_TYPE model_type);
static int cost_delete(ObDelUpCostInfo& cost_info,
double &cost,
const ObOptimizerContext &opt_ctx);
static int calc_range_cost(const ObTableMetaInfo& table_meta_info,
const ObIArray<ObRawExpr *> &filters,
@ -182,7 +206,7 @@ public:
int64_t range_count,
double range_sel,
double &cost,
MODEL_TYPE model_type);
const ObOptimizerContext &opt_ctx);
static int estimate_width_for_table(const OptTableMetas &table_metas,
const OptSelectivityCtx &ctx,
@ -218,9 +242,6 @@ public:
static double get_estimate_width_from_type(const ObExprResType &type);
private:
static ObOptEstCostModel &get_model(MODEL_TYPE model_type);
// static ObOptEstCostModel normal_model_;
// static ObOptEstCostModel vector_model_;
DISALLOW_COPY_AND_ASSIGN(ObOptEstCost);
};

View File

@ -19,6 +19,7 @@
#include "sql/optimizer/ob_join_order.h"
#include "sql/optimizer/ob_optimizer.h"
#include "sql/optimizer/ob_opt_selectivity.h"
#include "ob_opt_cost_model_parameter.h"
#include <math.h>
using namespace oceanbase::common;
using namespace oceanbase::share;
@ -207,15 +208,15 @@ int ObOptEstCostModel::cost_nestloop(const ObCostNLJoinInfo &est_cost_info,
double rescan_cost = 0.0;
if (est_cost_info.right_has_px_rescan_) {
if (est_cost_info.parallel_ > 1) {
rescan_cost = cost_params_.PX_RESCAN_PER_ROW_COST;
rescan_cost = cost_params_.get_px_rescan_per_row_cost(sys_stat_);
} else {
rescan_cost = cost_params_.PX_BATCH_RESCAN_PER_ROW_COST;
rescan_cost = cost_params_.get_px_batch_rescan_per_row_cost(sys_stat_);
}
} else {
rescan_cost = cost_params_.RESCAN_COST;
rescan_cost = cost_params_.get_rescan_cost(sys_stat_);
}
once_rescan_cost = est_cost_info.right_cost_ + rescan_cost
+ right_rows * cost_params_.CPU_TUPLE_COST;
+ right_rows * cost_params_.get_cpu_tuple_cost(sys_stat_);
}
// total rescan cost
if (LEFT_SEMI_JOIN == est_cost_info.join_type_
@ -231,7 +232,7 @@ int ObOptEstCostModel::cost_nestloop(const ObCostNLJoinInfo &est_cost_info,
cost += qual_cost;
double join_cost = cost_params_.JOIN_PER_ROW_COST * out_tuples;
double join_cost = cost_params_.get_join_per_row_cost(sys_stat_) * out_tuples;
cost += join_cost;
LOG_TRACE("OPT: [COST NESTLOOP JOIN]",
@ -286,12 +287,12 @@ int ObOptEstCostModel::cost_mergejoin(const ObCostMergeJoinInfo &est_cost_info,
}
out_tuples = cond_tuples * filter_sel;
// get_next_row()获取左表和右表所有行的代价
cost += cost_params_.CPU_TUPLE_COST * (left_rows + right_rows);
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * (left_rows + right_rows);
// 谓词代价
cost += cost_quals(cond_tuples, est_cost_info.equal_join_conditions_) +
cost_quals(cond_tuples, est_cost_info.other_join_conditions_);
// JOIN连接的代价
cost += cost_params_.JOIN_PER_ROW_COST * out_tuples;
cost += cost_params_.get_join_per_row_cost(sys_stat_) * out_tuples;
cost += cost_material(left_rows, left_width);
cost += cost_read_materialized(left_rows);
LOG_TRACE("OPT: [COST MERGE JOIN]",
@ -362,18 +363,18 @@ int ObOptEstCostModel::cost_hashjoin(const ObCostHashJoinInfo &est_cost_info,
}
cost += join_filter_cost;
// build hash cost for left table
build_hash_cost += cost_params_.CPU_TUPLE_COST * left_rows;
build_hash_cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * left_rows;
build_hash_cost += cost_material(left_rows, est_cost_info.left_width_);
build_hash_cost += cost_hash(left_rows, est_cost_info.equal_join_conditions_);
build_hash_cost += cost_params_.BUILD_HASH_PER_ROW_COST * left_rows;
build_hash_cost += cost_params_.get_build_hash_per_row_cost(sys_stat_) * left_rows;
// probe cost for right table
cost += build_hash_cost;
cost += cost_params_.CPU_TUPLE_COST * right_rows;
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * right_rows;
cost += cost_hash(right_rows, est_cost_info.equal_join_conditions_);
cost += cost_params_.PROBE_HASH_PER_ROW_COST * right_rows;
cost += cost_params_.get_probe_hash_per_row_cost(sys_stat_) * right_rows;
cost += cost_quals(cond_tuples, est_cost_info.equal_join_conditions_)
+ cost_quals(cond_tuples, est_cost_info.other_join_conditions_);
cost += cost_params_.JOIN_PER_ROW_COST * out_tuples;
cost += cost_params_.get_join_per_row_cost(sys_stat_) * out_tuples;
LOG_TRACE("OPT: [COST HASH JOIN]",
K(left_rows), K(right_rows),
K(cond_sel), K(filter_sel),
@ -487,7 +488,7 @@ int ObOptEstCostModel::cost_sort(const ObSortCostInfo &cost_info,
LOG_WARN("failed to cost local order sort", K(ret));
} else {
// get_next_row获取下层算子行的代价
cost += cost_params_.CPU_TUPLE_COST * cost_info.rows_;
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * cost_info.rows_;
}
} else if (cost_info.prefix_pos_ > 0) {
// prefix sort
@ -495,7 +496,7 @@ int ObOptEstCostModel::cost_sort(const ObSortCostInfo &cost_info,
LOG_WARN("failed to calc prefix cost", K(ret));
} else {
// get_next_row获取下层算子行的代价
cost += cost_params_.CPU_TUPLE_COST * cost_info.rows_;
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * cost_info.rows_;
}
} else if (cost_info.topn_ >= 0) {
//top-n sort
@ -503,7 +504,7 @@ int ObOptEstCostModel::cost_sort(const ObSortCostInfo &cost_info,
LOG_WARN("failed to calc topn sort cost", K(ret));
} else {
// get_next_row获取下层算子行的代价
cost += cost_params_.CPU_TUPLE_COST * cost_info.rows_;
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * cost_info.rows_;
}
} else if (cost_info.part_cnt_ > 0) {
// part sort
@ -511,7 +512,7 @@ int ObOptEstCostModel::cost_sort(const ObSortCostInfo &cost_info,
LOG_WARN("failed to calc part cost", K(ret));
} else {
// get_next_row获取下层算子行的代价
cost += cost_params_.CPU_TUPLE_COST * cost_info.rows_;
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * cost_info.rows_;
}
} else {
// normal sort
@ -519,7 +520,7 @@ int ObOptEstCostModel::cost_sort(const ObSortCostInfo &cost_info,
LOG_WARN("failed to calc cost", K(ret));
} else {
// get_next_row获取下层算子行的代价
cost += cost_params_.CPU_TUPLE_COST * cost_info.rows_;
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * cost_info.rows_;
}
}
LOG_TRACE("succeed to compute sort cost", K(cost_info), K(cost));
@ -633,7 +634,7 @@ int ObOptEstCostModel::cost_part_sort(const ObSortCostInfo &cost_info,
} else {
real_sort_cost = rows * LOG2(rows / distinct_parts) * comp_cost;
material_cost = cost_material(rows, width) + cost_read_materialized(rows);
calc_hash_cost = cost_hash(rows, part_exprs) + rows * cost_params_.BUILD_HASH_PER_ROW_COST / 2.0;
calc_hash_cost = cost_hash(rows, part_exprs) + rows * cost_params_.get_build_hash_per_row_cost(sys_stat_) / 2.0;
cost = real_sort_cost + material_cost + calc_hash_cost;
LOG_TRACE("OPT: [COST HASH SORT]", K(cost), K(real_sort_cost), K(calc_hash_cost),
K(material_cost), K(rows), K(width), K(cost_info.part_cnt_));
@ -935,8 +936,8 @@ int ObOptEstCostModel::cost_exchange_in(const ObExchInCostInfo &cost_info,
per_dop_rows = cost_info.rows_ / cost_info.parallel_;
}
if (OB_SUCC(ret)) {
cost = cost_params_.CPU_TUPLE_COST * per_dop_rows;
cost += cost_params_.NETWORK_DESER_PER_BYTE_COST * per_dop_rows * cost_info.width_;
cost = cost_params_.get_cpu_tuple_cost(sys_stat_) * per_dop_rows;
cost += cost_params_.get_network_deser_per_byte_cost(sys_stat_) * per_dop_rows * cost_info.width_;
LOG_TRACE("OPT: [COST EXCHANGE IN]", K(cost_info.rows_), K(cost_info.width_),
K(cost_info.dist_method_), K(cost_info.parallel_), K(cost));
if (ObPQDistributeMethod::BROADCAST == cost_info.dist_method_) {
@ -985,9 +986,9 @@ int ObOptEstCostModel::cost_exchange_out(const ObExchOutCostInfo &cost_info,
}
if (OB_SUCC(ret)) {
// add repartition cost, hash-hash cost ?
cost = cost_params_.CPU_TUPLE_COST * per_dop_ser_rows;
cost += cost_params_.NETWORK_SER_PER_BYTE_COST * per_dop_ser_rows * cost_info.width_;
cost += cost_params_.NETWORK_TRANS_PER_BYTE_COST * per_dop_trans_rows * cost_info.width_;
cost = cost_params_.get_cpu_tuple_cost(sys_stat_) * per_dop_ser_rows;
cost += cost_params_.get_network_ser_per_byte_cost(sys_stat_) * per_dop_ser_rows * cost_info.width_;
cost += cost_params_.get_network_trans_per_byte_cost(sys_stat_) * per_dop_trans_rows * cost_info.width_;
LOG_TRACE("OPT: [COST EXCHANGE OUT]", K(cost_info.rows_), K(cost_info.width_),
K(cost_info.dist_method_), K(cost_info.parallel_), K(cost));
}
@ -1013,11 +1014,11 @@ double ObOptEstCostModel::cost_merge_group(double rows,
int64_t agg_col_count)
{
double cost = 0.0;
cost += cost_params_.CPU_TUPLE_COST * rows;
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * rows;
//material cost
cost += cost_material(res_rows, row_width);
cost += cost_quals(rows, group_columns);
cost += cost_params_.PER_AGGR_FUNC_COST * static_cast<double>(agg_col_count) * rows;
cost += cost_params_.get_per_aggr_func_cost(sys_stat_) * static_cast<double>(agg_col_count) * rows;
LOG_TRACE("OPT: [COST MERGE GROUP BY]", K(cost), K(agg_col_count),
K(rows), K(res_rows));
return cost;
@ -1043,12 +1044,12 @@ double ObOptEstCostModel::cost_hash_group(double rows,
int64_t agg_col_count)
{
double cost = 0;
cost += cost_params_.CPU_TUPLE_COST * rows;
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * rows;
cost += cost_material(res_rows, row_width);
cost += cost_params_.BUILD_HASH_PER_ROW_COST * res_rows;
cost += cost_params_.PROBE_HASH_PER_ROW_COST * rows;
cost += cost_params_.get_build_hash_per_row_cost(sys_stat_) * res_rows;
cost += cost_params_.get_probe_hash_per_row_cost(sys_stat_) * rows;
cost += cost_hash(rows, group_columns);
cost += cost_params_.PER_AGGR_FUNC_COST * static_cast<double>(agg_col_count) * rows;
cost += cost_params_.get_per_aggr_func_cost(sys_stat_) * static_cast<double>(agg_col_count) * rows;
LOG_TRACE("OPT: [HASH GROUP BY]", K(cost), K(agg_col_count), K(rows), K(res_rows));
return cost;
}
@ -1063,8 +1064,8 @@ double ObOptEstCostModel::cost_hash_group(double rows,
double ObOptEstCostModel::cost_scalar_group(double rows, int64_t agg_col_count)
{
double cost = 0.0;
cost += cost_params_.CPU_TUPLE_COST * rows;
cost += cost_params_.PER_AGGR_FUNC_COST * static_cast<double>(agg_col_count) * rows;
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * rows;
cost += cost_params_.get_per_aggr_func_cost(sys_stat_) * static_cast<double>(agg_col_count) * rows;
LOG_TRACE("OPT: [SCALAR GROUP BY]", K(cost), K(agg_col_count), K(rows));
return cost;
}
@ -1083,7 +1084,7 @@ double ObOptEstCostModel::cost_merge_distinct(double rows,
const ObIArray<ObRawExpr *> &distinct_columns)
{
double cost = 0.0;
cost += cost_params_.CPU_TUPLE_COST * rows;
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * rows;
cost += cost_quals(rows, distinct_columns);
LOG_TRACE("OPT: [COST MERGE DISTINCT]", K(cost), K(rows), K(res_rows));
return cost;
@ -1106,13 +1107,13 @@ double ObOptEstCostModel::cost_hash_distinct(double rows,
{
double cost = 0.0;
// get_next_row()的代价
cost += cost_params_.CPU_TUPLE_COST * rows;
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * rows;
//material cost
cost += cost_material(res_rows, width);
// 构建hash table的代价
cost += cost_params_.BUILD_HASH_PER_ROW_COST * res_rows;
cost += cost_params_.get_build_hash_per_row_cost(sys_stat_) * res_rows;
// probe的代价
cost += cost_params_.PROBE_HASH_PER_ROW_COST * rows;
cost += cost_params_.get_probe_hash_per_row_cost(sys_stat_) * rows;
// 计算hash值代价
cost += cost_hash(rows, distinct_columns);
@ -1125,7 +1126,8 @@ double ObOptEstCostModel::cost_hash_distinct(double rows,
*/
double ObOptEstCostModel::cost_sequence(double rows, double uniq_sequence_cnt)
{
return cost_params_.CPU_TUPLE_COST * rows + cost_params_.CPU_OPERATOR_COST * uniq_sequence_cnt;
return cost_params_.get_cpu_tuple_cost(sys_stat_) * rows +
cost_params_.get_cpu_operator_cost(sys_stat_) * uniq_sequence_cnt;
}
/**
* @brief Limit算子代价的函数
@ -1134,7 +1136,7 @@ double ObOptEstCostModel::cost_sequence(double rows, double uniq_sequence_cnt)
*/
double ObOptEstCostModel::cost_get_rows(double rows)
{
return rows * cost_params_.CPU_TUPLE_COST;
return rows * cost_params_.get_cpu_tuple_cost(sys_stat_);
}
/**
@ -1142,7 +1144,7 @@ double ObOptEstCostModel::cost_get_rows(double rows)
*/
double ObOptEstCostModel::cost_read_materialized(double rows)
{
return rows * cost_params_.READ_MATERIALIZED_PER_ROW_COST;
return rows * cost_params_.get_read_materialized_per_row_cost(sys_stat_);
}
/**
@ -1154,7 +1156,7 @@ double ObOptEstCostModel::cost_read_materialized(double rows)
*/
double ObOptEstCostModel::cost_material(const double rows, const double average_row_size)
{
double cost = cost_params_.MATERIALIZE_PER_BYTE_WRITE_COST * average_row_size * rows;
double cost = cost_params_.get_materialize_per_byte_write_cost(sys_stat_) * average_row_size * rows;
LOG_TRACE("OPT: [COST MATERIAL]", K(cost), K(rows), K(average_row_size));
return cost;
}
@ -1163,11 +1165,9 @@ double ObOptEstCostModel::cost_material(const double rows, const double average_
double ObOptEstCostModel::cost_late_materialization_table_get(int64_t column_cnt)
{
double op_cost = 0.0;
bool is_get = true;
bool use_column_store = false;
double io_cost = cost_params_.MICRO_BLOCK_SEQ_COST;
double cpu_cost = (cost_params_.CPU_TUPLE_COST
+ project_params_[use_column_store][is_get][PROJECT_INT] * column_cnt);
double io_cost = cost_params_.get_micro_block_seq_cost(sys_stat_);
double cpu_cost = (cost_params_.get_cpu_tuple_cost(sys_stat_)
+ cost_params_.get_project_column_cost(sys_stat_, PROJECT_INT, true, false) * column_cnt);
op_cost = io_cost + cpu_cost;
return op_cost;
}
@ -1183,10 +1183,10 @@ void ObOptEstCostModel::cost_late_materialization_table_join(double left_card,
cost = 0.0;
// 再次扫描右表全表的代价。如果不使用物化,就是读取一次右表和本层get_next_row的代价;
// 如果物化,则为读取物化后的行的代价。
double once_rescan_cost = right_cost + right_card * cost_params_.CPU_TUPLE_COST;
op_cost += left_card * once_rescan_cost + left_card * cost_params_.JOIN_PER_ROW_COST;
double once_rescan_cost = right_cost + right_card * cost_params_.get_cpu_tuple_cost(sys_stat_);
op_cost += left_card * once_rescan_cost + left_card * cost_params_.get_join_per_row_cost(sys_stat_);
// 读取左表和本层get_next_row的代价
cost += left_cost + ObOptEstCostModel::cost_params_.CPU_TUPLE_COST * left_card;
cost += left_cost + cost_params_.get_cpu_tuple_cost(sys_stat_) * left_card;
cost += op_cost;
}
@ -1414,7 +1414,7 @@ int ObOptEstCostModel::cost_index_scan(const ObCostTableScanInfo &est_cost_info,
//add spatial index scan cost
if (OB_FAIL(ret)) {
} else if (est_cost_info.index_meta_info_.is_geo_index_) {
double spatial_cost = row_count * cost_params_.SPATIAL_PER_ROW_COST;
double spatial_cost = row_count * cost_params_.get_spatial_per_row_cost(sys_stat_);
cost += spatial_cost;
LOG_TRACE("OPT::[COST SPATIAL INDEX SCAN]", K(spatial_cost), K(ret));
}
@ -1472,8 +1472,8 @@ int ObOptEstCostModel::cost_global_index_back_with_rp(double row_count,
double column_count = est_cost_info.access_column_items_.count();
double transform_size = (table_meta_info->average_row_size_ * row_count * column_count)
/static_cast<double>(table_meta_info->table_column_count_);
cost = transform_size * cost_params_.NETWORK_TRANS_PER_BYTE_COST +
row_count * cost_params_.TABLE_LOOPUP_PER_ROW_RPC_COST;
cost = transform_size * cost_params_.get_network_trans_per_byte_cost(sys_stat_) +
row_count * cost_params_.get_table_loopup_per_row_rpc_cost(sys_stat_);
LOG_TRACE("OPT::[COST GLOBAL INDEX BACK WITH RPC]", K(cost), K(table_meta_info->average_row_size_),
K(row_count), K(table_meta_info->table_column_count_));
}
@ -1539,7 +1539,7 @@ int ObOptEstCostModel::cost_range_get(const ObCostTableScanInfo &est_cost_info,
cpu_cost))) {
LOG_WARN("failed to calc table scan cpu cost", K(ret));
} else {
double fetch_row_cost = cost_params_.FETCH_ROW_RND_COST * row_count;
double fetch_row_cost = cost_params_.get_fetch_row_rnd_cost(sys_stat_) * row_count;
cost = cpu_cost + io_cost + fetch_row_cost + memtable_cost + memtable_merge_cost;
LOG_TRACE("OPT:[COST RANGE GET]", K(is_scan_index), K(row_count), K(cost),
K(io_cost), K(cpu_cost), K(fetch_row_cost), K(memtable_cost), K(memtable_merge_cost));
@ -1577,18 +1577,18 @@ int ObOptEstCostModel::range_get_io_cost(const ObCostTableScanInfo &est_cost_inf
num_micro_blocks_read = num_micro_blocks;
}
// IO代价,包括读取整个微块及反序列化的代价和每行定位微块的代价
double first_block_cost = cost_params_.MICRO_BLOCK_RND_COST;
double first_block_cost = cost_params_.get_micro_block_rnd_cost(sys_stat_);
if (est_cost_info.is_inner_path_) {
if (est_cost_info.can_use_batch_nlj_) {
first_block_cost = cost_params_.BATCH_NL_GET_COST;
first_block_cost = cost_params_.get_batch_nl_get_cost(sys_stat_);
} else {
first_block_cost = cost_params_.NL_GET_COST;
first_block_cost = cost_params_.get_nl_get_cost(sys_stat_);
}
}
if (num_micro_blocks_read < 1) {
cost = 0;
} else {
cost = first_block_cost + cost_params_.MICRO_BLOCK_RND_COST * (num_micro_blocks_read-1);
cost = first_block_cost + cost_params_.get_micro_block_rnd_cost(sys_stat_) * (num_micro_blocks_read-1);
}
LOG_TRACE("OPT:[COST RANGE GET IO]", K(is_scan_index), K(row_count), K(cost), K(num_micro_blocks),
K(num_micro_blocks_read), K(first_block_cost));
@ -1627,18 +1627,18 @@ int ObOptEstCostModel::range_scan_io_cost(const ObCostTableScanInfo &est_cost_in
}
// IO代价,主要包括读取微块、反序列化的代价的代价
double first_block_cost = cost_params_.MICRO_BLOCK_RND_COST;
double first_block_cost = cost_params_.get_micro_block_rnd_cost(sys_stat_);
if (!est_cost_info.pushdown_prefix_filters_.empty()) {
if (est_cost_info.can_use_batch_nlj_) {
first_block_cost = cost_params_.BATCH_NL_SCAN_COST;
first_block_cost = cost_params_.get_batch_nl_scan_cost(sys_stat_);
} else {
first_block_cost = cost_params_.NL_SCAN_COST;
first_block_cost = cost_params_.get_nl_scan_cost(sys_stat_);
}
}
if (num_micro_blocks_read < 1) {
cost = first_block_cost;
} else {
cost = first_block_cost + cost_params_.MICRO_BLOCK_SEQ_COST * (num_micro_blocks_read-1);
cost = first_block_cost + cost_params_.get_micro_block_seq_cost(sys_stat_) * (num_micro_blocks_read-1);
}
LOG_TRACE("OPT:[COST RANGE SCAN IO]", K(is_scan_index), K(row_count), K(cost), K(num_micro_blocks),
K(num_micro_blocks_read), K(first_block_cost));
@ -1701,8 +1701,8 @@ int ObOptEstCostModel::range_scan_cpu_cost(const ObCostTableScanInfo &est_cost_i
}
// CPU代价,包括get_next_row调用的代价和谓词代价
double range_cost = 0;
range_cost = est_cost_info.ranges_.count() * cost_params_.RANGE_COST;
cost = row_count * cost_params_.CPU_TUPLE_COST;
range_cost = est_cost_info.ranges_.count() * cost_params_.get_range_cost(sys_stat_);
cost = row_count * cost_params_.get_cpu_tuple_cost(sys_stat_);
cost += range_cost + qual_cost + project_cost;
LOG_TRACE("OPT: [RANGE SCAN CPU COST]", K(is_scan_index), K(is_get),
@ -1731,7 +1731,7 @@ int ObOptEstCostModel::get_sort_cmp_cost(const common::ObIArray<sql::ObExprResTy
// if first col is identical, then we needn't compare the second col and so on.
//But now we cannot get hand on NDV easily, just use
// cmp_cost_col0 + cmp_cost_col1 / DEF_NDV + cmp_cost_col2 / DEF_NDV^2 ...
double cost_for_col = comparison_params_[tc];
double cost_for_col = cost_params_.get_comparison_cost(sys_stat_, tc);;
if (OB_UNLIKELY(cost_for_col < 0)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("not supported type class", K(tc), K(ret));
@ -1751,9 +1751,9 @@ int ObOptEstCostModel::get_sort_cmp_cost(const common::ObIArray<sql::ObExprResTy
int ObOptEstCostModel::cost_window_function(double rows, double width, double win_func_cnt, double &cost)
{
int ret = OB_SUCCESS;
cost += rows * cost_params_.CPU_TUPLE_COST;
cost += rows * cost_params_.get_cpu_tuple_cost(sys_stat_);
cost += ObOptEstCostModel::cost_material(rows, width) + ObOptEstCostModel::cost_read_materialized(rows);
cost += rows * cost_params_.PER_WIN_FUNC_COST * win_func_cnt;
cost += rows * cost_params_.get_per_win_func_cost(sys_stat_) * win_func_cnt;
return ret;
}
@ -1766,7 +1766,7 @@ int ObOptEstCostModel::cost_window_function(double rows, double width, double wi
*/
double ObOptEstCostModel::cost_filter_rows(double rows, ObIArray<ObRawExpr*> &filters)
{
return rows * cost_params_.CPU_TUPLE_COST + cost_quals(rows, filters);
return rows * cost_params_.get_cpu_tuple_cost(sys_stat_) + cost_quals(rows, filters);
}
/**
@ -1784,7 +1784,7 @@ int ObOptEstCostModel::cost_subplan_filter(const ObSubplanFilterCostInfo &info,
cost = 0.0;
double onetime_cost = 0.0;
if (info.children_.count() > 0) {
cost += info.children_.at(0).rows_ * cost_params_.CPU_TUPLE_COST;
cost += info.children_.at(0).rows_ * cost_params_.get_cpu_tuple_cost(sys_stat_);
}
for (int64_t i = 1; OB_SUCC(ret) && i < info.children_.count(); ++i) {
const ObBasicCostInfo &child = info.children_.at(i);
@ -1796,14 +1796,14 @@ int ObOptEstCostModel::cost_subplan_filter(const ObSubplanFilterCostInfo &info,
} else if (info.initplan_idxs_.has_member(i)) { // init plan cost
// 这个子节点是一个initplan
// 对右表进行物化,之后只需读取物化后的行
onetime_cost += child.cost_ + child.rows_ * cost_params_.CPU_TUPLE_COST
onetime_cost += child.cost_ + child.rows_ * cost_params_.get_cpu_tuple_cost(sys_stat_)
+ cost_material(child.rows_, child.width_);
cost += info.children_.at(0).rows_ * cost_read_materialized(child.rows_);
} else { // other cost
// 一般情况,每一次都要扫描右表
cost += info.children_.at(0).rows_ * (child.cost_ + child.rows_ * cost_params_.CPU_TUPLE_COST);
cost += info.children_.at(0).rows_ * (child.cost_ + child.rows_ * cost_params_.get_cpu_tuple_cost(sys_stat_));
if (child.exchange_allocated_) {
cost += cost_params_.PX_RESCAN_PER_ROW_COST * info.children_.at(0).rows_;
cost += cost_params_.get_px_rescan_per_row_cost(sys_stat_) * info.children_.at(0).rows_;
}
}
} // for info_childs end
@ -1822,7 +1822,7 @@ int ObOptEstCostModel::cost_union_all(const ObCostMergeSetInfo &info, double &co
for (int64_t i = 0; i < info.children_.count(); ++i) {
total_rows += info.children_.at(i).rows_;
}
cost = total_rows * cost_params_.CPU_TUPLE_COST;
cost = total_rows * cost_params_.get_cpu_tuple_cost(sys_stat_);
return ret;
}
@ -1843,7 +1843,7 @@ int ObOptEstCostModel::cost_merge_set(const ObCostMergeSetInfo &info, double &co
}
cost = 0.0;
//get next row cost
cost += sum_rows * cost_params_.CPU_TUPLE_COST;
cost += sum_rows * cost_params_.get_cpu_tuple_cost(sys_stat_);
cost += cost_material(sum_rows, width);
//operator cost:cmp_cost + cpu_cost
LOG_TRACE("OPT: [COST MERGE SET]", K(cost), K(sum_rows), K(width));
@ -1874,14 +1874,14 @@ int ObOptEstCostModel::cost_hash_set(const ObCostHashSetInfo &info, double &cost
cost = 0.0;
//get_next_row() 代价
cost += cost_params_.CPU_TUPLE_COST * (info.left_rows_ + info.right_rows_);
cost += cost_params_.get_cpu_tuple_cost(sys_stat_) * (info.left_rows_ + info.right_rows_);
//material cost
cost += cost_material(info.left_rows_, info.left_width_) +
cost_material(info.right_rows_, info.right_width_);
//build hash table cost
cost += cost_params_.BUILD_HASH_PER_ROW_COST * build_rows;
cost += cost_params_.get_build_hash_per_row_cost(sys_stat_) * build_rows;
//probe hash table cost
cost += cost_params_.PROBE_HASH_PER_ROW_COST * probe_rows;
cost += cost_params_.get_probe_hash_per_row_cost(sys_stat_) * probe_rows;
//计算 hash 的代价
cost += cost_hash(info.left_rows_ + info.right_rows_, info.hash_columns_);
@ -1908,11 +1908,7 @@ double ObOptEstCostModel::cost_hash(double rows, const ObIArray<ObRawExpr *> &ha
LOG_WARN_RET(OB_ERR_UNEXPECTED, "qual should not be NULL, but we don't set error return code here, just skip it");
} else {
ObObjTypeClass calc_type = expr->get_result_type().get_calc_type_class();
if (OB_UNLIKELY(hash_params_[calc_type] < 0)) {
LOG_WARN_RET(OB_NOT_SUPPORTED, "hash type not supported, skipped", K(calc_type));
} else {
cost_per_row += hash_params_[calc_type];
}
cost_per_row += cost_params_.get_hash_cost(sys_stat_,calc_type);
}
}
return rows * cost_per_row;
@ -1963,18 +1959,30 @@ int ObOptEstCostModel::cost_project(double rows,
const ObExprResType &type = expr->get_result_type();
if (type.is_integer_type()) {
// int
project_one_row_cost += project_params_[use_column_store][is_get][PROJECT_INT];
project_one_row_cost += cost_params_.get_project_column_cost(sys_stat_,
PROJECT_INT,
is_get,
use_column_store);
} else if (type.get_accuracy().get_length() > 0) {
// ObStringTC
int64_t string_width = type.get_accuracy().get_length();
string_width = std::min(string_width, ObOptEstCostModel::DEFAULT_MAX_STRING_WIDTH);
project_one_row_cost += project_params_[use_column_store][is_get][PROJECT_CHAR] * string_width;
project_one_row_cost += cost_params_.get_project_column_cost(sys_stat_,
PROJECT_CHAR,
is_get,
use_column_store) * string_width;
} else if (type.get_accuracy().get_precision() > 0 || type.is_oracle_integer()) {
// number, time
project_one_row_cost += project_params_[use_column_store][is_get][PROJECT_NUMBER];
project_one_row_cost += cost_params_.get_project_column_cost(sys_stat_,
PROJECT_NUMBER,
is_get,
use_column_store);
} else {
// default for DEFAULT PK
project_one_row_cost += project_params_[use_column_store][is_get][PROJECT_INT];
project_one_row_cost += cost_params_.get_project_column_cost(sys_stat_,
PROJECT_INT,
is_get,
use_column_store);
}
}
}
@ -2039,19 +2047,15 @@ double ObOptEstCostModel::cost_quals(double rows, const ObIArray<ObRawExpr *> &q
if (OB_ISNULL(qual)) {
LOG_WARN_RET(OB_ERR_UNEXPECTED, "qual should not be NULL, but we don't set error return code here, just skip it");
} else if (qual->is_spatial_expr()) {
cost_per_row += cost_params_.CMP_SPATIAL_COST * factor;
cost_per_row += cost_params_.get_cmp_spatial_cost(sys_stat_) * factor;
if (need_scale) {
factor /= 10.0;
}
} else {
ObObjTypeClass calc_type = qual->get_result_type().get_calc_type_class();
if (OB_UNLIKELY(comparison_params_[calc_type] < 0)) {
LOG_WARN_RET(OB_NOT_SUPPORTED, "comparison type not supported, skipped", K(calc_type));
} else {
cost_per_row += comparison_params_[calc_type] * factor;
if (need_scale) {
factor /= 10.0;
}
cost_per_row += cost_params_.get_comparison_cost(sys_stat_, calc_type) * factor;
if (need_scale) {
factor /= 10.0;
}
}
}
@ -2061,30 +2065,30 @@ double ObOptEstCostModel::cost_quals(double rows, const ObIArray<ObRawExpr *> &q
int ObOptEstCostModel::cost_insert(ObDelUpCostInfo& cost_info, double &cost)
{
int ret = OB_SUCCESS;
cost = cost_params_.CPU_TUPLE_COST * cost_info.affect_rows_ +
cost_params_.INSERT_PER_ROW_COST * cost_info.affect_rows_ +
cost_params_.INSERT_INDEX_PER_ROW_COST * cost_info.index_count_ +
cost_params_.INSERT_CHECK_PER_ROW_COST * cost_info.constraint_count_;
cost = cost_params_.get_cpu_tuple_cost(sys_stat_) * cost_info.affect_rows_ +
cost_params_.get_insert_per_row_cost(sys_stat_) * cost_info.affect_rows_ +
cost_params_.get_insert_index_per_row_cost(sys_stat_) * cost_info.index_count_ +
cost_params_.get_insert_check_per_row_cost(sys_stat_) * cost_info.constraint_count_;
return ret;
}
int ObOptEstCostModel::cost_update(ObDelUpCostInfo& cost_info, double &cost)
{
int ret = OB_SUCCESS;
cost = cost_params_.CPU_TUPLE_COST * cost_info.affect_rows_ +
cost_params_.UPDATE_PER_ROW_COST * cost_info.affect_rows_ +
cost_params_.UPDATE_INDEX_PER_ROW_COST * cost_info.index_count_ +
cost_params_.UPDATE_CHECK_PER_ROW_COST * cost_info.constraint_count_;
cost = cost_params_.get_cpu_tuple_cost(sys_stat_) * cost_info.affect_rows_ +
cost_params_.get_update_per_row_cost(sys_stat_) * cost_info.affect_rows_ +
cost_params_.get_update_index_per_row_cost(sys_stat_) * cost_info.index_count_ +
cost_params_.get_update_check_per_row_cost(sys_stat_) * cost_info.constraint_count_;
return ret;
}
int ObOptEstCostModel::cost_delete(ObDelUpCostInfo& cost_info, double &cost)
{
int ret = OB_SUCCESS;
cost = cost_params_.CPU_TUPLE_COST * cost_info.affect_rows_ +
cost_params_.DELETE_PER_ROW_COST * cost_info.affect_rows_ +
cost_params_.DELETE_INDEX_PER_ROW_COST * cost_info.index_count_ +
cost_params_.DELETE_CHECK_PER_ROW_COST * cost_info.constraint_count_;
cost = cost_params_.get_cpu_tuple_cost(sys_stat_) * cost_info.affect_rows_ +
cost_params_.get_delete_per_row_cost(sys_stat_) * cost_info.affect_rows_ +
cost_params_.get_delete_index_per_row_cost(sys_stat_) * cost_info.index_count_ +
cost_params_.get_delete_check_per_row_cost(sys_stat_) * cost_info.constraint_count_;
return ret;
}
@ -2109,11 +2113,11 @@ int ObOptEstCostModel::calc_range_cost(const ObTableMetaInfo& table_meta_info,
* row_count
/ static_cast<double> (table_meta_info.table_row_count_));
}
double io_cost = cost_params_.MICRO_BLOCK_SEQ_COST * num_micro_blocks_read;
double io_cost = cost_params_.get_micro_block_seq_cost(sys_stat_) * num_micro_blocks_read;
double qual_cost = cost_quals(row_count, filters);
double cpu_cost = row_count * cost_params_.CPU_TUPLE_COST
+ range_count * cost_params_.RANGE_COST + qual_cost;
cpu_cost += row_count * cost_params_.TABLE_SCAN_CPU_TUPLE_COST;
double cpu_cost = row_count * cost_params_.get_cpu_tuple_cost(sys_stat_)
+ range_count * cost_params_.get_range_cost(sys_stat_) + qual_cost;
cpu_cost += row_count * cost_params_.get_table_scan_cpu_tuple_cost(sys_stat_);
cost = io_cost + cpu_cost;
return ret;
}

View File

@ -30,6 +30,8 @@ struct ObExprSelPair;
struct JoinFilterInfo;
class OptTableMetas;
class OptSelectivityCtx;
class ObOptCostModelParameter;
class OptSystemStat;
enum RowCountEstMethod
{
@ -633,171 +635,11 @@ public:
const static int64_t DEFAULT_LOCAL_ORDER_DEGREE;
const static int64_t DEFAULT_MAX_STRING_WIDTH;
const static int64_t DEFAULT_FIXED_OBJ_WIDTH;
enum PROJECT_TYPE {
PROJECT_INT = 0,
PROJECT_NUMBER,
PROJECT_CHAR,
MAX_PROJECT_TYPE
};
struct ObCostParams
{
explicit ObCostParams(
const double DEFAULT_CPU_TUPLE_COST,
const double DEFAULT_TABLE_SCAN_CPU_TUPLE_COST,
const double DEFAULT_MICRO_BLOCK_SEQ_COST,
const double DEFAULT_MICRO_BLOCK_RND_COST,
const double DEFAULT_FETCH_ROW_RND_COST,
const double DEFAULT_CMP_GEO_COST,
const double DEFAULT_MATERIALIZE_PER_BYTE_WRITE_COST,
const double DEFAULT_READ_MATERIALIZED_PER_ROW_COST,
const double DEFAULT_PER_AGGR_FUNC_COST,
const double DEFAULT_PER_WIN_FUNC_COST,
const double DEFAULT_CPU_OPERATOR_COST,
const double DEFAULT_JOIN_PER_ROW_COST,
const double DEFAULT_BUILD_HASH_PER_ROW_COST,
const double DEFAULT_PROBE_HASH_PER_ROW_COST,
const double DEFAULT_RESCAN_COST,
const double DEFAULT_NETWORK_SER_PER_BYTE_COST,
const double DEFAULT_NETWORK_DESER_PER_BYTE_COST,
const double DEFAULT_NETWORK_TRANS_PER_BYTE_COST,
const double DEFAULT_PX_RESCAN_PER_ROW_COST,
const double DEFAULT_PX_BATCH_RESCAN_PER_ROW_COST,
const double DEFAULT_NL_SCAN_COST,
const double DEFAULT_BATCH_NL_SCAN_COST,
const double DEFAULT_NL_GET_COST,
const double DEFAULT_BATCH_NL_GET_COST,
const double DEFAULT_TABLE_LOOPUP_PER_ROW_RPC_COST,
const double DEFAULT_INSERT_PER_ROW_COST,
const double DEFAULT_INSERT_INDEX_PER_ROW_COST,
const double DEFAULT_INSERT_CHECK_PER_ROW_COST,
const double DEFAULT_UPDATE_PER_ROW_COST,
const double DEFAULT_UPDATE_INDEX_PER_ROW_COST,
const double DEFAULT_UPDATE_CHECK_PER_ROW_COST,
const double DEFAULT_DELETE_PER_ROW_COST,
const double DEFAULT_DELETE_INDEX_PER_ROW_COST,
const double DEFAULT_DELETE_CHECK_PER_ROW_COST,
const double DEFAULT_SPATIAL_PER_ROW_COST,
const double DEFAULT_RANGE_COST
)
: CPU_TUPLE_COST(DEFAULT_CPU_TUPLE_COST),
TABLE_SCAN_CPU_TUPLE_COST(DEFAULT_TABLE_SCAN_CPU_TUPLE_COST),
MICRO_BLOCK_SEQ_COST(DEFAULT_MICRO_BLOCK_SEQ_COST),
MICRO_BLOCK_RND_COST(DEFAULT_MICRO_BLOCK_RND_COST),
FETCH_ROW_RND_COST(DEFAULT_FETCH_ROW_RND_COST),
CMP_SPATIAL_COST(DEFAULT_CMP_GEO_COST),
MATERIALIZE_PER_BYTE_WRITE_COST(DEFAULT_MATERIALIZE_PER_BYTE_WRITE_COST),
READ_MATERIALIZED_PER_ROW_COST(DEFAULT_READ_MATERIALIZED_PER_ROW_COST),
PER_AGGR_FUNC_COST(DEFAULT_PER_AGGR_FUNC_COST),
PER_WIN_FUNC_COST(DEFAULT_PER_WIN_FUNC_COST),
CPU_OPERATOR_COST(DEFAULT_CPU_OPERATOR_COST),
JOIN_PER_ROW_COST(DEFAULT_JOIN_PER_ROW_COST),
BUILD_HASH_PER_ROW_COST(DEFAULT_BUILD_HASH_PER_ROW_COST),
PROBE_HASH_PER_ROW_COST(DEFAULT_PROBE_HASH_PER_ROW_COST),
RESCAN_COST(DEFAULT_RESCAN_COST),
NETWORK_SER_PER_BYTE_COST(DEFAULT_NETWORK_SER_PER_BYTE_COST),
NETWORK_DESER_PER_BYTE_COST(DEFAULT_NETWORK_DESER_PER_BYTE_COST),
NETWORK_TRANS_PER_BYTE_COST(DEFAULT_NETWORK_TRANS_PER_BYTE_COST),
PX_RESCAN_PER_ROW_COST(DEFAULT_PX_RESCAN_PER_ROW_COST),
PX_BATCH_RESCAN_PER_ROW_COST(DEFAULT_PX_BATCH_RESCAN_PER_ROW_COST),
NL_SCAN_COST(DEFAULT_NL_SCAN_COST),
BATCH_NL_SCAN_COST(DEFAULT_BATCH_NL_SCAN_COST),
NL_GET_COST(DEFAULT_NL_GET_COST),
BATCH_NL_GET_COST(DEFAULT_BATCH_NL_GET_COST),
TABLE_LOOPUP_PER_ROW_RPC_COST(DEFAULT_TABLE_LOOPUP_PER_ROW_RPC_COST),
INSERT_PER_ROW_COST(DEFAULT_INSERT_PER_ROW_COST),
INSERT_INDEX_PER_ROW_COST(DEFAULT_INSERT_INDEX_PER_ROW_COST),
INSERT_CHECK_PER_ROW_COST(DEFAULT_INSERT_CHECK_PER_ROW_COST),
UPDATE_PER_ROW_COST(DEFAULT_UPDATE_PER_ROW_COST),
UPDATE_INDEX_PER_ROW_COST(DEFAULT_UPDATE_INDEX_PER_ROW_COST),
UPDATE_CHECK_PER_ROW_COST(DEFAULT_UPDATE_CHECK_PER_ROW_COST),
DELETE_PER_ROW_COST(DEFAULT_DELETE_PER_ROW_COST),
DELETE_INDEX_PER_ROW_COST(DEFAULT_DELETE_INDEX_PER_ROW_COST),
DELETE_CHECK_PER_ROW_COST(DEFAULT_DELETE_CHECK_PER_ROW_COST),
SPATIAL_PER_ROW_COST(DEFAULT_SPATIAL_PER_ROW_COST),
RANGE_COST(DEFAULT_RANGE_COST)
{}
/** 读取一行的CPU开销,基本上只包括get_next_row()操作 */
double CPU_TUPLE_COST;
/** 存储层吐出一行的代价 **/
double TABLE_SCAN_CPU_TUPLE_COST;
/** 顺序读取一个微块并反序列化的开销 */
double MICRO_BLOCK_SEQ_COST;
/** 随机读取一个微块并反序列化的开销 */
double MICRO_BLOCK_RND_COST;
/** 随机读取中定位某一行所在位置的开销 */
double FETCH_ROW_RND_COST;
/** 比较一次空间数据的代价 */
double CMP_SPATIAL_COST;
/** 物化一个字节的代价 */
double MATERIALIZE_PER_BYTE_WRITE_COST;
/** 读取物化后的行的代价,即对物化后数据结构的get_next_row() */
double READ_MATERIALIZED_PER_ROW_COST;
/** 一次聚集函数计算的代价 */
double PER_AGGR_FUNC_COST;
/** 一次窗口函数计算的代价 */
double PER_WIN_FUNC_COST;
/** 一次操作的基本代价 */
double CPU_OPERATOR_COST;
/** 连接两表的一行的基本代价 */
double JOIN_PER_ROW_COST;
/** 构建hash table时每行的均摊代价 */
double BUILD_HASH_PER_ROW_COST;
/** 查询hash table时每行的均摊代价 */
double PROBE_HASH_PER_ROW_COST;
double RESCAN_COST;
/*network serialization cost for one byte*/
double NETWORK_SER_PER_BYTE_COST;
/*network de-serialization cost for one byte*/
double NETWORK_DESER_PER_BYTE_COST;
/** 网络传输1个字节的代价 */
double NETWORK_TRANS_PER_BYTE_COST;
/*additional px-rescan cost*/
double PX_RESCAN_PER_ROW_COST;
double PX_BATCH_RESCAN_PER_ROW_COST;
//条件下压nestloop join右表扫一次的代价
double NL_SCAN_COST;
//条件下压batch nestloop join右表扫一次的代价
double BATCH_NL_SCAN_COST;
//条件下压nestloop join右表GET一次的代价
double NL_GET_COST;
//条件下压batch nestloop join右表GET一次的代价
double BATCH_NL_GET_COST;
//table look up一行的rpc代价
double TABLE_LOOPUP_PER_ROW_RPC_COST;
//insert一行主表的代价
double INSERT_PER_ROW_COST;
//insert一行索引表的代价
double INSERT_INDEX_PER_ROW_COST;
//insert单个约束检查代价
double INSERT_CHECK_PER_ROW_COST;
//update一行主表的代价
double UPDATE_PER_ROW_COST;
//update一行索引表的代价
double UPDATE_INDEX_PER_ROW_COST;
//update单个约束检查代价
double UPDATE_CHECK_PER_ROW_COST;
//delete一行主表的代价
double DELETE_PER_ROW_COST;
//delete一行索引表的代价
double DELETE_INDEX_PER_ROW_COST;
//delete单个约束检查代价
double DELETE_CHECK_PER_ROW_COST;
//空间索引扫描的线性参数
double SPATIAL_PER_ROW_COST;
//存储层切换一次range的代价
double RANGE_COST;
};
ObOptEstCostModel(
const double (&comparison_params)[common::ObMaxTC + 1],
const double (&hash_params)[common::ObMaxTC + 1],
const double (&project_params)[2][2][MAX_PROJECT_TYPE],
const ObCostParams &cost_params)
:comparison_params_(comparison_params),
hash_params_(hash_params),
project_params_(project_params),
cost_params_(cost_params)
ObOptEstCostModel(const ObOptCostModelParameter &cost_params,
const OptSystemStat &stat)
:cost_params_(cost_params),
sys_stat_(stat)
{}
virtual ~ObOptEstCostModel()=default;
@ -1040,20 +882,10 @@ protected:
double row_count,
bool is_get,
double &cost);
protected:
const double (&comparison_params_)[common::ObMaxTC + 1];
const double (&hash_params_)[common::ObMaxTC + 1];
/*
* +-sequence access project
* +-row store----+
* | +-random access project
* project cost-+
* | +-sequence access project
* +-column store-+
* +-random access project
*/
const double (&project_params_)[2][2][MAX_PROJECT_TYPE];
const ObCostParams &cost_params_;
const ObOptCostModelParameter &cost_params_;
const OptSystemStat &sys_stat_;
DISALLOW_COPY_AND_ASSIGN(ObOptEstCostModel);
};

View File

@ -13,6 +13,7 @@
#define USING_LOG_PREFIX SQL_OPT
#include "sql/optimizer/ob_opt_est_cost_model_vector.h"
#include "ob_opt_cost_model_parameter.h"
using namespace oceanbase;
using namespace sql;

View File

@ -22,15 +22,9 @@ namespace sql
class ObOptEstVectorCostModel : public ObOptEstCostModel {
public:
ObOptEstVectorCostModel(
const double (&comparison_params)[common::ObMaxTC + 1],
const double (&hash_params)[common::ObMaxTC + 1],
const double (&project_params)[2][2][ObOptEstCostModel::MAX_PROJECT_TYPE],
const ObCostParams &cost_params)
:ObOptEstCostModel(comparison_params,
hash_params,
project_params,
cost_params)
ObOptEstVectorCostModel(const ObOptCostModelParameter &cost_params,
const OptSystemStat &stat)
:ObOptEstCostModel(cost_params, stat)
{}
virtual ~ObOptEstVectorCostModel()=default;
protected:

View File

@ -12,78 +12,78 @@
#ifndef OCEANBASE_SQL_OPTIMIZER_OB_OPT_EST_PARAMETER_NORMAL_
#define OCEANBASE_SQL_OPTIMIZER_OB_OPT_EST_PARAMETER_NORMAL_
#include "ob_opt_est_cost_model.h"
#include "ob_opt_cost_model_parameter.h"
namespace oceanbase
{
namespace sql
{
const static double NORMAL_CPU_TUPLE_COST = 0.02977945030613315927249275026;
const static double NORMAL_TABLE_SCAN_CPU_TUPLE_COST = 0.3717749711890249146505031527;
const static double NORMAL_MICRO_BLOCK_SEQ_COST = 4.12032943880540981;
const static double NORMAL_MICRO_BLOCK_RND_COST = 5.45276187553;
const static double NORMAL_FETCH_ROW_RND_COST = 2.2477466668;
const static double NORMAL_MATERIALIZE_PER_BYTE_WRITE_COST = 0.0003799844906944444444444444444;
const static double NORMAL_READ_MATERIALIZED_PER_ROW_COST = 0.08075845740444444444444444444;
const static double NORMAL_PER_AGGR_FUNC_COST = 0.03295337962222222222222222222;
const static double NORMAL_PER_WIN_FUNC_COST = 0.4276335555833333333333333333;
const static double NORMAL_CPU_OPERATOR_COST = 0.03295337962222222222222222222;
const static double NORMAL_JOIN_PER_ROW_COST = 0.2924230170039462058068723292;
const static double NORMAL_BUILD_HASH_PER_ROW_COST = 0.2518499446975396825396825399;
const static double NORMAL_PROBE_HASH_PER_ROW_COST = 0.2320765365033553814947149724;
const static double NORMAL_RESCAN_COST = 0.7380813333;
const static double NORMAL_NETWORK_SER_PER_BYTE_COST = 0.0094539370039375;
const static double NORMAL_NETWORK_DESER_PER_BYTE_COST = 0.0094539370039375;
const static double NORMAL_NETWORK_TRANS_PER_BYTE_COST = 0.011832508338;
const static double NORMAL_PX_RESCAN_PER_ROW_COST = 398.267410467;
const static double NORMAL_PX_BATCH_RESCAN_PER_ROW_COST = 49.5841472833;
const static double NORMAL_NL_SCAN_COST = 19.2;
const static double NORMAL_BATCH_NL_SCAN_COST = 16.11;
const static double NORMAL_NL_GET_COST = 8.24;
const static double NORMAL_BATCH_NL_GET_COST = 6.76;
const static double NORMAL_TABLE_LOOPUP_PER_ROW_RPC_COST = 20.9591092914652749211572741;
const static double NORMAL_INSERT_PER_ROW_COST = 6.330037500000001;
const static double NORMAL_INSERT_INDEX_PER_ROW_COST = 6.583673124999999;
const static double NORMAL_INSERT_CHECK_PER_ROW_COST = 96.2424;
const static double NORMAL_UPDATE_PER_ROW_COST = 7.562755000000001;
const static double NORMAL_UPDATE_INDEX_PER_ROW_COST = 23.969286875;
const static double NORMAL_UPDATE_CHECK_PER_ROW_COST = 92.15352;
const static double NORMAL_DELETE_PER_ROW_COST = 5.0310162499999995;
const static double NORMAL_DELETE_INDEX_PER_ROW_COST = 6.549611874999999;
const static double NORMAL_DELETE_CHECK_PER_ROW_COST = 59.4583275;
const static double NORMAL_SPATIAL_PER_ROW_COST = 3.2434868757557513;
const static double NORMAL_RANGE_COST = 2.1;
const static double NORMAL_CPU_TUPLE_COST = 0.02977945030613315927249275026 * DEFAULT_CPU_SPEED;
const static double NORMAL_TABLE_SCAN_CPU_TUPLE_COST = 0.3717749711890249146505031527 * DEFAULT_CPU_SPEED;
const static double NORMAL_MICRO_BLOCK_SEQ_COST = 4.12032943880540981 * DEFAULT_DISK_SEQ_READ_SPEED / DEFAULT_MACR_BLOCK_SIZE;
const static double NORMAL_MICRO_BLOCK_RND_COST = 5.45276187553 * DEFAULT_DISK_RND_READ_SPEED / DEFAULT_MACR_BLOCK_SIZE;
const static double NORMAL_FETCH_ROW_RND_COST = 2.2477466668 * DEFAULT_CPU_SPEED;
const static double NORMAL_MATERIALIZE_PER_BYTE_WRITE_COST = 0.0003799844906944444444444444444 * DEFAULT_CPU_SPEED;
const static double NORMAL_READ_MATERIALIZED_PER_ROW_COST = 0.08075845740444444444444444444 * DEFAULT_CPU_SPEED;
const static double NORMAL_PER_AGGR_FUNC_COST = 0.03295337962222222222222222222 * DEFAULT_CPU_SPEED;
const static double NORMAL_PER_WIN_FUNC_COST = 0.4276335555833333333333333333 * DEFAULT_CPU_SPEED;
const static double NORMAL_CPU_OPERATOR_COST = 0.03295337962222222222222222222 * DEFAULT_CPU_SPEED;
const static double NORMAL_JOIN_PER_ROW_COST = 0.2924230170039462058068723292 * DEFAULT_CPU_SPEED;
const static double NORMAL_BUILD_HASH_PER_ROW_COST = 0.2518499446975396825396825399 * DEFAULT_CPU_SPEED;
const static double NORMAL_PROBE_HASH_PER_ROW_COST = 0.2320765365033553814947149724 * DEFAULT_CPU_SPEED;
const static double NORMAL_RESCAN_COST = 0.7380813333 * DEFAULT_CPU_SPEED;
const static double NORMAL_NETWORK_SER_PER_BYTE_COST = 0.0094539370039375 * DEFAULT_CPU_SPEED;
const static double NORMAL_NETWORK_DESER_PER_BYTE_COST = 0.0094539370039375 * DEFAULT_CPU_SPEED;
const static double NORMAL_NETWORK_TRANS_PER_BYTE_COST = 0.011832508338 * DEFAULT_NETWORK_SPEED;
const static double NORMAL_PX_RESCAN_PER_ROW_COST = 398.267410467 * DEFAULT_CPU_SPEED;
const static double NORMAL_PX_BATCH_RESCAN_PER_ROW_COST = 49.5841472833 * DEFAULT_CPU_SPEED;
const static double NORMAL_NL_SCAN_COST = 19.2 * DEFAULT_CPU_SPEED;
const static double NORMAL_BATCH_NL_SCAN_COST = 16.11 * DEFAULT_CPU_SPEED;
const static double NORMAL_NL_GET_COST = 8.24 * DEFAULT_CPU_SPEED;
const static double NORMAL_BATCH_NL_GET_COST = 6.76 * DEFAULT_CPU_SPEED;
const static double NORMAL_TABLE_LOOPUP_PER_ROW_RPC_COST = 20.9591092914652749211572741 * DEFAULT_CPU_SPEED;
const static double NORMAL_INSERT_PER_ROW_COST = 6.330037500000001 * DEFAULT_CPU_SPEED;
const static double NORMAL_INSERT_INDEX_PER_ROW_COST = 6.583673124999999 * DEFAULT_CPU_SPEED;
const static double NORMAL_INSERT_CHECK_PER_ROW_COST = 96.2424 * DEFAULT_CPU_SPEED;
const static double NORMAL_UPDATE_PER_ROW_COST = 7.562755000000001 * DEFAULT_CPU_SPEED;
const static double NORMAL_UPDATE_INDEX_PER_ROW_COST = 23.969286875 * DEFAULT_CPU_SPEED;
const static double NORMAL_UPDATE_CHECK_PER_ROW_COST = 92.15352 * DEFAULT_CPU_SPEED;
const static double NORMAL_DELETE_PER_ROW_COST = 5.0310162499999995 * DEFAULT_CPU_SPEED;
const static double NORMAL_DELETE_INDEX_PER_ROW_COST = 6.549611874999999 * DEFAULT_CPU_SPEED;
const static double NORMAL_DELETE_CHECK_PER_ROW_COST = 59.4583275 * DEFAULT_CPU_SPEED;
const static double NORMAL_SPATIAL_PER_ROW_COST = 3.2434868757557513 * DEFAULT_CPU_SPEED;
const static double NORMAL_RANGE_COST = 2.1 * DEFAULT_CPU_SPEED;
//project cost params
//row store
const static double NORMAL_ROW_STORE_PROJECT_COLUMN_SEQ_INT_COST = 0.04392826667;
const static double NORMAL_ROW_STORE_PROJECT_COLUMN_SEQ_NUMBER_COST = 0.04187649999657894736842105263;
const static double NORMAL_ROW_STORE_PROJECT_COLUMN_SEQ_CHAR_COST = 0.001149576877742598684210526316;
const static double NORMAL_ROW_STORE_PROJECT_COLUMN_SEQ_INT_COST = 0.04392826667 * DEFAULT_CPU_SPEED;
const static double NORMAL_ROW_STORE_PROJECT_COLUMN_SEQ_NUMBER_COST = 0.04187649999657894736842105263 * DEFAULT_CPU_SPEED;
const static double NORMAL_ROW_STORE_PROJECT_COLUMN_SEQ_CHAR_COST = 0.001149576877742598684210526316 * DEFAULT_CPU_SPEED;
const static double NORMAL_ROW_STORE_PROJECT_COLUMN_RND_INT_COST = 0.04392826667;
const static double NORMAL_ROW_STORE_PROJECT_COLUMN_RND_NUMBER_COST = 0.04187649999657894736842105263;
const static double NORMAL_ROW_STORE_PROJECT_COLUMN_RND_CHAR_COST = 0.001149576877742598684210526316;
const static double NORMAL_ROW_STORE_PROJECT_COLUMN_RND_INT_COST = 0.04392826667 * DEFAULT_CPU_SPEED;
const static double NORMAL_ROW_STORE_PROJECT_COLUMN_RND_NUMBER_COST = 0.04187649999657894736842105263 * DEFAULT_CPU_SPEED;
const static double NORMAL_ROW_STORE_PROJECT_COLUMN_RND_CHAR_COST = 0.001149576877742598684210526316 * DEFAULT_CPU_SPEED;
//column store
const static double NORMAL_COLUMN_STORE_PROJECT_COLUMN_SEQ_INT_COST = 0.08879689693065789473684210526;
const static double NORMAL_COLUMN_STORE_PROJECT_COLUMN_SEQ_NUMBER_COST = 0.07463286534828947368421052632;
const static double NORMAL_COLUMN_STORE_PROJECT_COLUMN_SEQ_CHAR_COST = 0.002145698273026315789473684210;
const static double NORMAL_COLUMN_STORE_PROJECT_COLUMN_SEQ_INT_COST = 0.08879689693065789473684210526 * DEFAULT_CPU_SPEED;
const static double NORMAL_COLUMN_STORE_PROJECT_COLUMN_SEQ_NUMBER_COST = 0.07463286534828947368421052632 * DEFAULT_CPU_SPEED;
const static double NORMAL_COLUMN_STORE_PROJECT_COLUMN_SEQ_CHAR_COST = 0.002145698273026315789473684210 * DEFAULT_CPU_SPEED;
const static double NORMAL_COLUMN_STORE_PROJECT_COLUMN_RND_INT_COST = 0.08879689693065789473684210526;
const static double NORMAL_COLUMN_STORE_PROJECT_COLUMN_RND_NUMBER_COST = 0.07463286534828947368421052632;
const static double NORMAL_COLUMN_STORE_PROJECT_COLUMN_RND_CHAR_COST = 0.002145698273026315789473684210;
const static double NORMAL_COLUMN_STORE_PROJECT_COLUMN_RND_INT_COST = 0.08879689693065789473684210526 * DEFAULT_CPU_SPEED;
const static double NORMAL_COLUMN_STORE_PROJECT_COLUMN_RND_NUMBER_COST = 0.07463286534828947368421052632 * DEFAULT_CPU_SPEED;
const static double NORMAL_COLUMN_STORE_PROJECT_COLUMN_RND_CHAR_COST = 0.002145698273026315789473684210 * DEFAULT_CPU_SPEED;
//compare cost params
const static double NORMAL_CMP_INT_COST = 0.0100087103407539;
const static double NORMAL_CMP_NUMBER_COST = 0.0227412012152380952380952381;
const static double NORMAL_CMP_CHAR_COST = 0.09707028746051587301587301588;
const static double NORMAL_CMP_SPATIAL_COST = 19.311884382850465;
const static double NORMAL_CMP_INT_COST = 0.0100087103407539 * DEFAULT_CPU_SPEED;
const static double NORMAL_CMP_NUMBER_COST = 0.0227412012152380952380952381 * DEFAULT_CPU_SPEED;
const static double NORMAL_CMP_CHAR_COST = 0.09707028746051587301587301588 * DEFAULT_CPU_SPEED;
const static double NORMAL_CMP_SPATIAL_COST = 19.311884382850465 * DEFAULT_CPU_SPEED;
const static double NORMAL_INVALID_CMP_COST = -1;
//hash cost params
const static double NORMAL_HASH_INT_COST = 0.02272897981269841269841269841;
const static double NORMAL_HASH_NUMBER_COST = 0.02702563229230158730158730158;
const static double NORMAL_HASH_CHAR_COST = 0.2306996323278174603174603175;
const static double NORMAL_HASH_INT_COST = 0.02272897981269841269841269841 * DEFAULT_CPU_SPEED;
const static double NORMAL_HASH_NUMBER_COST = 0.02702563229230158730158730158 * DEFAULT_CPU_SPEED;
const static double NORMAL_HASH_CHAR_COST = 0.2306996323278174603174603175 * DEFAULT_CPU_SPEED;
const static double NORMAL_INVALID_HASH_COST = -1;
const static double comparison_params_normal[ObMaxTC+1] = {
@ -145,7 +145,7 @@ const static double hash_params_normal[ObMaxTC+1] = {
NORMAL_HASH_NUMBER_COST, // ObDecimalIntTC
};
const static double project_params_normal[2][2][ObOptEstCostModel::MAX_PROJECT_TYPE] = {
const static double project_params_normal[2][2][MAX_PROJECT_TYPE] = {
{
{// row store sequence access
NORMAL_ROW_STORE_PROJECT_COLUMN_SEQ_INT_COST, // int
@ -172,7 +172,7 @@ const static double project_params_normal[2][2][ObOptEstCostModel::MAX_PROJECT_T
}
};
const static ObOptEstCostModel::ObCostParams cost_params_normal(
const static ObOptCostModelParameter cost_params_normal(
NORMAL_CPU_TUPLE_COST,
NORMAL_TABLE_SCAN_CPU_TUPLE_COST,
NORMAL_MICRO_BLOCK_SEQ_COST,
@ -208,7 +208,10 @@ const static ObOptEstCostModel::ObCostParams cost_params_normal(
NORMAL_DELETE_INDEX_PER_ROW_COST,
NORMAL_DELETE_CHECK_PER_ROW_COST,
NORMAL_SPATIAL_PER_ROW_COST,
NORMAL_RANGE_COST
NORMAL_RANGE_COST,
comparison_params_normal,
hash_params_normal,
project_params_normal
);
}

View File

@ -12,77 +12,78 @@
#ifndef OCEANBASE_SQL_OPTIMIZER_OB_OPT_EST_PARAMETER_VECTOR_
#define OCEANBASE_SQL_OPTIMIZER_OB_OPT_EST_PARAMETER_VECTOR_
#include "ob_opt_est_cost_model.h"
#include "ob_opt_cost_model_parameter.h"
namespace oceanbase
{
namespace sql
{
const static double VECTOR_CPU_TUPLE_COST = 0.00264692180695;
const static double VECTOR_TABLE_SCAN_CPU_TUPLE_COST = 0.00816675438377;
const static double VECTOR_MICRO_BLOCK_SEQ_COST = 1.19603792057955;
const static double VECTOR_MICRO_BLOCK_RND_COST = 1.6742435644151;
const static double VECTOR_FETCH_ROW_RND_COST = 2.294445334;
const static double VECTOR_MATERIALIZE_PER_BYTE_WRITE_COST = 0.0019941666625;
const static double VECTOR_READ_MATERIALIZED_PER_ROW_COST = 0.00279052036722;
const static double VECTOR_PER_AGGR_FUNC_COST = 0.01547711103333;
const static double VECTOR_PER_WIN_FUNC_COST = 0.6489393333;
const static double VECTOR_CPU_OPERATOR_COST = 0.00441003086296;
const static double VECTOR_JOIN_PER_ROW_COST = 0.02229222638004;
const static double VECTOR_BUILD_HASH_PER_ROW_COST = 0.12472949246032;
const static double VECTOR_PROBE_HASH_PER_ROW_COST = 0.07363102503623;
const static double VECTOR_RESCAN_COST = 0.76306366670000;
const static double VECTOR_NETWORK_SER_PER_BYTE_COST = 0.0094539370039375;
const static double VECTOR_NETWORK_DESER_PER_BYTE_COST = 0.0094539370039375;
const static double VECTOR_NETWORK_TRANS_PER_BYTE_COST = 0.011832508338;
const static double VECTOR_PX_RESCAN_PER_ROW_COST = 398.267410467;
const static double VECTOR_PX_BATCH_RESCAN_PER_ROW_COST = 49.5841472833;
const static double VECTOR_NL_SCAN_COST = 17.92;
const static double VECTOR_BATCH_NL_SCAN_COST = 15.32;
const static double VECTOR_NL_GET_COST = 6.4;
const static double VECTOR_BATCH_NL_GET_COST = 6.4;
const static double VECTOR_TABLE_LOOPUP_PER_ROW_RPC_COST = 20.9591092914652749211572741;
const static double VECTOR_INSERT_PER_ROW_COST = 6.330037500000001;
const static double VECTOR_INSERT_INDEX_PER_ROW_COST = 6.583673124999999;
const static double VECTOR_INSERT_CHECK_PER_ROW_COST = 96.2424;
const static double VECTOR_UPDATE_PER_ROW_COST = 7.562755000000001;
const static double VECTOR_UPDATE_INDEX_PER_ROW_COST = 23.969286875;
const static double VECTOR_UPDATE_CHECK_PER_ROW_COST = 92.15352;
const static double VECTOR_DELETE_PER_ROW_COST = 5.0310162499999995;
const static double VECTOR_DELETE_INDEX_PER_ROW_COST = 6.549611874999999;
const static double VECTOR_DELETE_CHECK_PER_ROW_COST = 59.4583275;
const static double VECTOR_SPATIAL_PER_ROW_COST = 3.2434868757557513; // todo: fix later
const static double VECTOR_RANGE_COST = 2.1;
const static double VECTOR_CPU_TUPLE_COST = 0.00264692180695 * DEFAULT_CPU_SPEED;
const static double VECTOR_TABLE_SCAN_CPU_TUPLE_COST = 0.00816675438377 * DEFAULT_CPU_SPEED;
const static double VECTOR_MICRO_BLOCK_SEQ_COST = 1.19603792057955 * DEFAULT_DISK_SEQ_READ_SPEED / DEFAULT_MACR_BLOCK_SIZE;
const static double VECTOR_MICRO_BLOCK_RND_COST = 1.6742435644151 * DEFAULT_DISK_RND_READ_SPEED / DEFAULT_MACR_BLOCK_SIZE;
const static double VECTOR_FETCH_ROW_RND_COST = 2.294445334 * DEFAULT_CPU_SPEED;
const static double VECTOR_MATERIALIZE_PER_BYTE_WRITE_COST = 0.0019941666625 * DEFAULT_CPU_SPEED;
const static double VECTOR_READ_MATERIALIZED_PER_ROW_COST = 0.00279052036722 * DEFAULT_CPU_SPEED;
const static double VECTOR_PER_AGGR_FUNC_COST = 0.01547711103333 * DEFAULT_CPU_SPEED;
const static double VECTOR_PER_WIN_FUNC_COST = 0.6489393333 * DEFAULT_CPU_SPEED;
const static double VECTOR_CPU_OPERATOR_COST = 0.00441003086296 * DEFAULT_CPU_SPEED;
const static double VECTOR_JOIN_PER_ROW_COST = 0.02229222638004 * DEFAULT_CPU_SPEED;
const static double VECTOR_BUILD_HASH_PER_ROW_COST = 0.12472949246032 * DEFAULT_CPU_SPEED;
const static double VECTOR_PROBE_HASH_PER_ROW_COST = 0.07363102503623 * DEFAULT_CPU_SPEED;
const static double VECTOR_RESCAN_COST = 0.76306366670000 * DEFAULT_CPU_SPEED;
const static double VECTOR_NETWORK_SER_PER_BYTE_COST = 0.0094539370039375 * DEFAULT_CPU_SPEED;
const static double VECTOR_NETWORK_DESER_PER_BYTE_COST = 0.0094539370039375 * DEFAULT_CPU_SPEED;
const static double VECTOR_NETWORK_TRANS_PER_BYTE_COST = 0.011832508338 * DEFAULT_NETWORK_SPEED;
const static double VECTOR_PX_RESCAN_PER_ROW_COST = 398.267410467 * DEFAULT_CPU_SPEED;
const static double VECTOR_PX_BATCH_RESCAN_PER_ROW_COST = 49.5841472833 * DEFAULT_CPU_SPEED;
const static double VECTOR_NL_SCAN_COST = 17.92 * DEFAULT_CPU_SPEED;
const static double VECTOR_BATCH_NL_SCAN_COST = 15.32 * DEFAULT_CPU_SPEED;
const static double VECTOR_NL_GET_COST = 6.4 * DEFAULT_CPU_SPEED;
const static double VECTOR_BATCH_NL_GET_COST = 6.4 * DEFAULT_CPU_SPEED;
const static double VECTOR_TABLE_LOOPUP_PER_ROW_RPC_COST = 20.9591092914652749211572741 * DEFAULT_CPU_SPEED;
const static double VECTOR_INSERT_PER_ROW_COST = 6.330037500000001 * DEFAULT_CPU_SPEED;
const static double VECTOR_INSERT_INDEX_PER_ROW_COST = 6.583673124999999 * DEFAULT_CPU_SPEED;
const static double VECTOR_INSERT_CHECK_PER_ROW_COST = 96.2424 * DEFAULT_CPU_SPEED;
const static double VECTOR_UPDATE_PER_ROW_COST = 7.562755000000001 * DEFAULT_CPU_SPEED;
const static double VECTOR_UPDATE_INDEX_PER_ROW_COST = 23.969286875 * DEFAULT_CPU_SPEED;
const static double VECTOR_UPDATE_CHECK_PER_ROW_COST = 92.15352 * DEFAULT_CPU_SPEED;
const static double VECTOR_DELETE_PER_ROW_COST = 5.0310162499999995 * DEFAULT_CPU_SPEED;
const static double VECTOR_DELETE_INDEX_PER_ROW_COST = 6.549611874999999 * DEFAULT_CPU_SPEED;
const static double VECTOR_DELETE_CHECK_PER_ROW_COST = 59.4583275 * DEFAULT_CPU_SPEED;
const static double VECTOR_SPATIAL_PER_ROW_COST = 3.2434868757557513 * DEFAULT_CPU_SPEED; // todo: fix later
const static double VECTOR_RANGE_COST = 2.1 * DEFAULT_CPU_SPEED;
//project cost params
//row store
const static double VECTOR_ROW_STORE_PROJECT_COLUMN_SEQ_INT_COST = 0.02314121667000;
const static double VECTOR_ROW_STORE_PROJECT_COLUMN_SEQ_NUMBER_COST = 0.01602888420961;
const static double VECTOR_ROW_STORE_PROJECT_COLUMN_SEQ_CHAR_COST = 0.00028227202574;
const static double VECTOR_ROW_STORE_PROJECT_COLUMN_SEQ_INT_COST = 0.02314121667000 * DEFAULT_CPU_SPEED;
const static double VECTOR_ROW_STORE_PROJECT_COLUMN_SEQ_NUMBER_COST = 0.01602888420961 * DEFAULT_CPU_SPEED;
const static double VECTOR_ROW_STORE_PROJECT_COLUMN_SEQ_CHAR_COST = 0.00028227202574 * DEFAULT_CPU_SPEED;
const static double VECTOR_ROW_STORE_PROJECT_COLUMN_RND_INT_COST = 0.08067736535000;
const static double VECTOR_ROW_STORE_PROJECT_COLUMN_RND_NUMBER_COST = 0.08806720526487;
const static double VECTOR_ROW_STORE_PROJECT_COLUMN_RND_CHAR_COST = 0.0025971659266159;
const static double VECTOR_ROW_STORE_PROJECT_COLUMN_RND_INT_COST = 0.08067736535000 * DEFAULT_CPU_SPEED;
const static double VECTOR_ROW_STORE_PROJECT_COLUMN_RND_NUMBER_COST = 0.08806720526487 * DEFAULT_CPU_SPEED;
const static double VECTOR_ROW_STORE_PROJECT_COLUMN_RND_CHAR_COST = 0.0025971659266159 * DEFAULT_CPU_SPEED;
//column store
const static double VECTOR_COLUMN_STORE_PROJECT_COLUMN_SEQ_INT_COST = 0.002314121667000;
const static double VECTOR_COLUMN_STORE_PROJECT_COLUMN_SEQ_NUMBER_COST = 0.0041602888420961;
const static double VECTOR_COLUMN_STORE_PROJECT_COLUMN_SEQ_CHAR_COST = 0.000128227202574;
const static double VECTOR_COLUMN_STORE_PROJECT_COLUMN_SEQ_INT_COST = 0.002314121667000 * DEFAULT_CPU_SPEED;
const static double VECTOR_COLUMN_STORE_PROJECT_COLUMN_SEQ_NUMBER_COST = 0.0041602888420961 * DEFAULT_CPU_SPEED;
const static double VECTOR_COLUMN_STORE_PROJECT_COLUMN_SEQ_CHAR_COST = 0.000128227202574 * DEFAULT_CPU_SPEED;
const static double VECTOR_COLUMN_STORE_PROJECT_COLUMN_RND_INT_COST = 0.08067736535000;
const static double VECTOR_COLUMN_STORE_PROJECT_COLUMN_RND_NUMBER_COST = 0.08806720526487;
const static double VECTOR_COLUMN_STORE_PROJECT_COLUMN_RND_CHAR_COST = 0.0025971659266159;
const static double VECTOR_COLUMN_STORE_PROJECT_COLUMN_RND_INT_COST = 0.08067736535000 * DEFAULT_CPU_SPEED;
const static double VECTOR_COLUMN_STORE_PROJECT_COLUMN_RND_NUMBER_COST = 0.08806720526487 * DEFAULT_CPU_SPEED;
const static double VECTOR_COLUMN_STORE_PROJECT_COLUMN_RND_CHAR_COST = 0.0025971659266159 * DEFAULT_CPU_SPEED;
//compare cost params
const static double VECTOR_CMP_INT_COST = 0.0084782994043;
const static double VECTOR_CMP_NUMBER_COST = 0.0144099836801;
const static double VECTOR_CMP_CHAR_COST = 0.03754351606603;
const static double VECTOR_CMP_SPATIAL_COST = 19.311884382850465; // gis vector is not supported
const static double VECTOR_CMP_INT_COST = 0.0084782994043 * DEFAULT_CPU_SPEED;
const static double VECTOR_CMP_NUMBER_COST = 0.0144099836801 * DEFAULT_CPU_SPEED;
const static double VECTOR_CMP_CHAR_COST = 0.03754351606603 * DEFAULT_CPU_SPEED;
const static double VECTOR_CMP_SPATIAL_COST = 19.311884382850465 * DEFAULT_CPU_SPEED; // gis vector is not supported
const static double VECTOR_INVALID_CMP_COST = -1;
//hash cost params
const static double VECTOR_HASH_INT_COST = 0.00742821518373;
const static double VECTOR_HASH_NUMBER_COST = 0.01494804432806;
const static double VECTOR_HASH_CHAR_COST = 0.18684685876579;
const static double VECTOR_HASH_INT_COST = 0.00742821518373 * DEFAULT_CPU_SPEED;
const static double VECTOR_HASH_NUMBER_COST = 0.01494804432806 * DEFAULT_CPU_SPEED;
const static double VECTOR_HASH_CHAR_COST = 0.18684685876579 * DEFAULT_CPU_SPEED;
const static double VECTOR_INVALID_HASH_COST = -1;
const static double comparison_params_vector[ObMaxTC+1] = {
@ -143,7 +144,7 @@ const static double hash_params_vector[ObMaxTC+1] = {
VECTOR_HASH_NUMBER_COST, // ObDecimalIntTC
};
const static double project_params_vector[2][2][ObOptEstCostModel::MAX_PROJECT_TYPE] = {
const static double project_params_vector[2][2][MAX_PROJECT_TYPE] = {
{
{// row store sequence access
VECTOR_ROW_STORE_PROJECT_COLUMN_SEQ_INT_COST, // int
@ -170,7 +171,7 @@ const static double project_params_vector[2][2][ObOptEstCostModel::MAX_PROJECT_T
}
};
const static ObOptEstCostModel::ObCostParams cost_params_vector(
const static ObOptCostModelParameter cost_params_vector(
VECTOR_CPU_TUPLE_COST,
VECTOR_TABLE_SCAN_CPU_TUPLE_COST,
VECTOR_MICRO_BLOCK_SEQ_COST,
@ -206,7 +207,10 @@ const static ObOptEstCostModel::ObCostParams cost_params_vector(
VECTOR_DELETE_INDEX_PER_ROW_COST,
VECTOR_DELETE_CHECK_PER_ROW_COST,
VECTOR_SPATIAL_PER_ROW_COST,
VECTOR_RANGE_COST
VECTOR_RANGE_COST,
comparison_params_vector,
hash_params_vector,
project_params_vector
);
}

View File

@ -26,6 +26,10 @@
#include "sql/dblink/ob_dblink_utils.h"
#include "sql/resolver/dml/ob_merge_stmt.h"
#include "sql/optimizer/ob_log_temp_table_insert.h"
#include "share/stat/ob_opt_system_stat.h"
#include "sql/optimizer/ob_opt_cost_model_parameter.h"
#include "src/share/stat/ob_opt_stat_manager.h"
using namespace oceanbase;
using namespace sql;
using namespace oceanbase::common;
@ -557,6 +561,8 @@ int ObOptimizer::extract_opt_ctx_basic_flags(const ObDMLStmt &stmt, ObSQLSession
LOG_WARN("fail to get force_serial_set_order", K(ret));
} else if (OB_FAIL(check_force_default_stat())) {
LOG_WARN("failed to check force default stat", K(ret));
} else if (OB_FAIL(init_system_stat())) {
LOG_WARN("failed to init system stat", K(ret));
} else if (OB_FAIL(calc_link_stmt_count(stmt, link_stmt_count))) {
LOG_WARN("calc link stmt count failed", K(ret));
} else if (OB_FAIL(ObDblinkUtils::has_reverse_link_or_any_dblink(&stmt, has_dblink, true))) {
@ -1030,6 +1036,49 @@ int ObOptimizer::check_force_default_stat()
return ret;
}
int ObOptimizer::init_system_stat()
{
int ret = OB_SUCCESS;
bool is_valid = false;
OptSystemStat &meta = ctx_.get_system_stat();
ObOptStatManager *opt_stat_manager = ctx_.get_opt_stat_manager();
ObSQLSessionInfo* session = ctx_.get_session_info();
if (OB_ISNULL(opt_stat_manager) || OB_ISNULL(session)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null param", K(ret));
} else if (OB_FAIL(opt_stat_manager->check_system_stat_validity(ctx_.get_exec_ctx(),
session->get_effective_tenant_id(),
is_valid))) {
LOG_WARN("failed to check system stat is valid", K(ret));
} else if (!ctx_.use_default_stat() && is_valid) {
ObOptSystemStat stat;
if (OB_FAIL(opt_stat_manager->get_system_stat(session->get_effective_tenant_id(), stat))) {
LOG_WARN("failed to get system stat", K(ret));
} else {
meta.set_cpu_speed(stat.get_cpu_speed());
meta.set_disk_seq_read_speed(stat.get_disk_seq_read_speed());
meta.set_disk_rnd_read_speed(stat.get_disk_rnd_read_speed());
meta.set_network_speed(stat.get_network_speed());
}
}
if (OB_SUCC(ret)) {
//refine default stat
if (meta.get_cpu_speed() <= 0) {
meta.set_cpu_speed(DEFAULT_CPU_SPEED);
}
if (meta.get_disk_seq_read_speed() <= 0) {
meta.set_disk_seq_read_speed(DEFAULT_DISK_SEQ_READ_SPEED);
}
if (meta.get_disk_rnd_read_speed() <= 0) {
meta.set_disk_rnd_read_speed(DEFAULT_DISK_RND_READ_SPEED);
}
if (meta.get_network_speed() <= 0) {
meta.set_network_speed(DEFAULT_NETWORK_SPEED);
}
}
return ret;
}
int ObOptimizer::check_merge_stmt_is_update_index_rowkey(const ObSQLSessionInfo &session,
const ObDMLStmt &stmt,
const ObIArray<uint64_t> &index_ids,

View File

@ -221,6 +221,7 @@ namespace sql
int64_t flag);
int check_whether_contain_nested_sql(const ObDMLStmt &stmt);
int check_force_default_stat();
int init_system_stat();
int calc_link_stmt_count(const ObDMLStmt &stmt, int64_t &count);
private:

View File

@ -116,6 +116,45 @@ struct AutoDOPParams {
int64_t parallel_min_scan_time_threshold_; // auto dop threshold for table scan cost
};
struct OptSystemStat {
OptSystemStat()
:last_analyzed_(0),
cpu_speed_(0),
disk_seq_read_speed_(0),
disk_rnd_read_speed_(0),
network_speed_(0)
{
}
inline int64_t get_last_analyzed() const { return last_analyzed_; }
void set_last_analyzed(int64_t last_analyzed) { last_analyzed_ = last_analyzed; }
inline int64_t get_cpu_speed() const { return cpu_speed_; }
void set_cpu_speed(int64_t cpu_speed) { cpu_speed_ = cpu_speed; }
inline int64_t get_disk_seq_read_speed() const { return disk_seq_read_speed_; }
void set_disk_seq_read_speed(int64_t disk_seq_read_speed) { disk_seq_read_speed_ = disk_seq_read_speed; }
inline int64_t get_disk_rnd_read_speed() const { return disk_rnd_read_speed_; }
void set_disk_rnd_read_speed(int64_t disk_rnd_read_speed) { disk_rnd_read_speed_ = disk_rnd_read_speed; }
inline int64_t get_network_speed() const { return network_speed_; }
void set_network_speed(int64_t network_speed) { network_speed_ = network_speed; }
TO_STRING_KV(K(last_analyzed_),
K(cpu_speed_),
K(disk_seq_read_speed_),
K(disk_rnd_read_speed_),
K(network_speed_));
private:
int64_t last_analyzed_;
int64_t cpu_speed_;
int64_t disk_seq_read_speed_;
int64_t disk_rnd_read_speed_;
int64_t network_speed_;
};
class ObOptimizerContext
{
@ -192,7 +231,8 @@ ObOptimizerContext(ObSQLSessionInfo *session_info,
has_multiple_link_stmt_(false),
hash_join_enabled_(true),
optimizer_sortmerge_join_enabled_(true),
nested_loop_join_enabled_(true)
nested_loop_join_enabled_(true),
system_stat_()
{ }
inline common::ObOptStatManager *get_opt_stat_manager() { return opt_stat_manager_; }
inline void set_opt_stat_manager(common::ObOptStatManager *sm) { opt_stat_manager_ = sm; }
@ -558,6 +598,9 @@ ObOptimizerContext(ObSQLSessionInfo *session_info,
inline void set_merge_join_enabled(bool enabled) { optimizer_sortmerge_join_enabled_ = enabled; }
inline bool is_nested_join_enabled() const { return nested_loop_join_enabled_; }
inline void set_nested_join_enabled(bool enabled) { nested_loop_join_enabled_ = enabled; }
inline OptSystemStat& get_system_stat() { return system_stat_; }
inline const OptSystemStat& get_system_stat() const { return system_stat_; }
private:
ObSQLSessionInfo *session_info_;
ObExecContext *exec_ctx_;
@ -640,6 +683,7 @@ private:
bool hash_join_enabled_;
bool optimizer_sortmerge_join_enabled_;
bool nested_loop_join_enabled_;
OptSystemStat system_stat_;
};
}
}

View File

@ -2534,7 +2534,7 @@ int ObSelectLogPlan::allocate_set_distinct_as_top(ObLogicalOperator *&top)
top->get_card(),
top->get_width(),
distinct_exprs,
get_optimizer_context().get_cost_model_type());
get_optimizer_context());
distinct->set_cost(top->get_cost() + distinct_cost);
distinct->set_op_cost(distinct_cost);
top = distinct_op;
@ -3461,7 +3461,7 @@ int ObSelectLogPlan::get_minimal_cost_set_plan(const int64_t in_parallel,
right_need_sort,
right_prefix_pos,
right_path_cost,
get_optimizer_context().get_cost_model_type()))) {
get_optimizer_context()))) {
LOG_WARN("failed to compute cost for merge join style op", K(ret));
} else if (NULL == best_plan || right_path_cost < best_cost) {
if (OB_FAIL(best_order_items.assign(right_order_items))) {
@ -7077,7 +7077,7 @@ int ObSelectLogPlan::generate_late_materialization_table_get(ObLogTableScan *ind
// set card and cost
table_scan->set_card(1.0);
table_scan->set_op_cost(ObOptEstCost::cost_late_materialization_table_get(stmt->get_column_size(),
get_optimizer_context().get_cost_model_type()));
get_optimizer_context()));
table_scan->set_cost(table_scan->get_op_cost());
est_cost_info->output_row_count_ = 1.0;
est_cost_info->phy_query_range_row_count_ = 1.0;
@ -7183,7 +7183,7 @@ int ObSelectLogPlan::allocate_late_materialization_join_as_top(ObLogicalOperator
right_child->get_cost(),
join->get_op_cost(),
join->get_cost(),
get_optimizer_context().get_cost_model_type());
get_optimizer_context());
if (OB_FAIL(join->set_op_ordering(left_child->get_op_ordering()))) {
LOG_WARN("failed to set op ordering", K(ret));
} else {
@ -7254,7 +7254,7 @@ int ObSelectLogPlan::if_plan_need_late_materialization(ObLogicalOperator *top,
if (OB_FAIL(ObOptEstCost::cost_table(*table_scan->get_est_cost_info(),
table_scan->get_parallel(),
op_cost,
get_optimizer_context().get_cost_model_type()))) {
get_optimizer_context()))) {
LOG_WARN("failed to get index access info", K(ret));
} else if (OB_FAIL(child_sort->est_cost())) {
LOG_WARN("failed to compute property", K(ret));
@ -7265,7 +7265,7 @@ int ObSelectLogPlan::if_plan_need_late_materialization(ObLogicalOperator *top,
top->get_cost(),
stmt->get_column_size(),
late_mater_cost,
get_optimizer_context().get_cost_model_type());
get_optimizer_context());
table_scan->set_cost(op_cost);
table_scan->set_op_cost(op_cost);
index_scan = table_scan;

View File

@ -240,6 +240,7 @@ select * from information_schema.tables where table_schema in ('oceanbase', 'mys
| def | oceanbase | DBA_OB_ARCHIVELOG_SUMMARY | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | DBA_OB_ARCHIVE_DEST | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | DBA_OB_AUTO_INCREMENT | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | DBA_OB_AUX_STATISTICS | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | DBA_OB_BACKUP_DELETE_JOBS | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | DBA_OB_BACKUP_DELETE_JOB_HISTORY | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | DBA_OB_BACKUP_DELETE_POLICY | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
@ -461,6 +462,7 @@ select * from information_schema.tables where table_schema in ('oceanbase', 'mys
| def | oceanbase | __ALL_VIRTUAL_INFORMATION_COLUMNS | SYSTEM TABLE | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | __all_acquired_snapshot | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | __all_auto_increment | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | __all_aux_stat | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | __all_balance_job | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | __all_balance_job_history | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | __all_balance_task | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
@ -839,6 +841,7 @@ select * from information_schema.statistics where table_schema in ('oceanbase',
| def | oceanbase | __all_acquired_snapshot | 1 | oceanbase | idx_snapshot_tablet | 1 | tablet_id | A | NULL | NULL | NULL | YES | BTREE | | | YES | NULL |
| def | oceanbase | __all_auto_increment | 0 | oceanbase | PRIMARY | 1 | sequence_key | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_auto_increment | 0 | oceanbase | PRIMARY | 2 | column_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_aux_stat | 0 | oceanbase | PRIMARY | 1 | tenant_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_balance_job | 0 | oceanbase | PRIMARY | 1 | job_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_balance_job_history | 0 | oceanbase | PRIMARY | 1 | job_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_balance_task | 0 | oceanbase | PRIMARY | 1 | task_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
@ -1523,6 +1526,7 @@ select * from information_schema.tables where table_schema in ('oceanbase', 'mys
| def | oceanbase | DBA_OB_ARCHIVELOG_SUMMARY | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | DBA_OB_ARCHIVE_DEST | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | DBA_OB_AUTO_INCREMENT | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | DBA_OB_AUX_STATISTICS | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | DBA_OB_BACKUP_DELETE_JOBS | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | DBA_OB_BACKUP_DELETE_JOB_HISTORY | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | DBA_OB_BACKUP_DELETE_POLICY | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
@ -1743,6 +1747,7 @@ select * from information_schema.tables where table_schema in ('oceanbase', 'mys
| def | oceanbase | V$SYSTEM_EVENT | SYSTEM VIEW | MEMORY | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | __all_acquired_snapshot | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | __all_auto_increment | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | __all_aux_stat | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | __all_balance_job | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | __all_balance_job_history | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
| def | oceanbase | __all_balance_task | SYSTEM TABLE | InnoDB | NULL | DYNAMIC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | utf8mb4_general_ci | NULL | NULL | |
@ -2148,6 +2153,7 @@ select * from information_schema.statistics where table_schema in ('oceanbase',
| def | oceanbase | __all_arbitration_service | 0 | oceanbase | PRIMARY | 1 | arbitration_service_key | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_auto_increment | 0 | oceanbase | PRIMARY | 1 | sequence_key | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_auto_increment | 0 | oceanbase | PRIMARY | 2 | column_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_aux_stat | 0 | oceanbase | PRIMARY | 1 | tenant_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_backup_delete_job | 0 | oceanbase | PRIMARY | 1 | tenant_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_backup_delete_job | 0 | oceanbase | PRIMARY | 2 | job_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_backup_delete_job_history | 0 | oceanbase | PRIMARY | 1 | tenant_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
@ -3069,6 +3075,7 @@ select * from information_schema.statistics where table_schema in ('oceanbase',
| def | oceanbase | __all_acquired_snapshot | 1 | oceanbase | idx_snapshot_tablet | 1 | tablet_id | A | NULL | NULL | NULL | YES | BTREE | | | YES | NULL |
| def | oceanbase | __all_auto_increment | 0 | oceanbase | PRIMARY | 1 | sequence_key | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_auto_increment | 0 | oceanbase | PRIMARY | 2 | column_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_aux_stat | 0 | oceanbase | PRIMARY | 1 | tenant_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_balance_job | 0 | oceanbase | PRIMARY | 1 | job_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_balance_job_history | 0 | oceanbase | PRIMARY | 1 | job_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| def | oceanbase | __all_balance_task | 0 | oceanbase | PRIMARY | 1 | task_id | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |

View File

@ -5558,3 +5558,13 @@ COMMENT longtext YES
select /*+QUERY_TIMEOUT(60000000)*/ count(*) as cnt from (select * from oceanbase.DBA_OB_IMPORT_TABLE_TASK_HISTORY limit 1);
cnt
1
desc oceanbase.DBA_OB_AUX_STATISTICS;
Field Type Null Key Default Extra
LAST_ANALYZED timestamp(6) NO NULL
CPU_SPEED(MHZ) bigint(20) YES
DISK_SEQ_READ_SPEED(MB/S) bigint(20) YES
DISK_RND_READ_SPEED(MB/S) bigint(20) YES
NETWORK_SPEED(MB/S) bigint(20) YES NULL
select /*+QUERY_TIMEOUT(60000000)*/ count(*) as cnt from (select * from oceanbase.DBA_OB_AUX_STATISTICS limit 1);
cnt
1

View File

@ -7988,3 +7988,24 @@ LARGE_QUEUED bigint(20) NO
select /*+QUERY_TIMEOUT(60000000)*/ count(*) as cnt from (select * from oceanbase.V$OB_TENANT_RUNTIME_INFO limit 1);
cnt
1
desc oceanbase.DBA_OB_AUX_STATISTICS;
Field Type Null Key Default Extra
LAST_ANALYZED timestamp(6) NO NULL
CPU_SPEED(MHZ) bigint(20) YES
DISK_SEQ_READ_SPEED(MB/S) bigint(20) YES
DISK_RND_READ_SPEED(MB/S) bigint(20) YES
NETWORK_SPEED(MB/S) bigint(20) YES NULL
select /*+QUERY_TIMEOUT(60000000)*/ count(*) as cnt from (select * from oceanbase.DBA_OB_AUX_STATISTICS limit 1);
cnt
1
desc oceanbase.CDB_OB_AUX_STATISTICS;
Field Type Null Key Default Extra
TENANT_ID bigint(20) NO NULL
LAST_ANALYZED timestamp(6) NO NULL
CPU_SPEED(MHZ) bigint(20) YES
DISK_SEQ_READ_SPEED(MB/S) bigint(20) YES
DISK_RND_READ_SPEED(MB/S) bigint(20) YES
NETWORK_SPEED(MB/S) bigint(20) YES NULL
select /*+QUERY_TIMEOUT(60000000)*/ count(*) as cnt from (select * from oceanbase.CDB_OB_AUX_STATISTICS limit 1);
cnt
1

View File

@ -8644,3 +8644,16 @@ comment longtext YES
select /*+QUERY_TIMEOUT(60000000)*/ IF(count(*) >= 0, 1, 0) from oceanbase.__all_virtual_import_table_task_history;
IF(count(*) >= 0, 1, 0)
1
desc oceanbase.__all_virtual_aux_stat;
Field Type Null Key Default Extra
tenant_id bigint(20) NO PRI NULL
gmt_create timestamp(6) NO NULL
gmt_modified timestamp(6) NO NULL
last_analyzed timestamp(6) NO NULL
cpu_speed bigint(20) YES 2500
disk_seq_read_speed bigint(20) YES 2000
disk_rnd_read_speed bigint(20) YES 150
network_speed bigint(20) YES NULL
select /*+QUERY_TIMEOUT(60000000)*/ IF(count(*) >= 0, 1, 0) from oceanbase.__all_virtual_aux_stat;
IF(count(*) >= 0, 1, 0)
1

View File

@ -264,6 +264,7 @@ select 0xffffffffff & table_id, table_name, table_type, database_id, part_num fr
478 __all_import_table_job_history 0 201001 1
479 __all_import_table_task 0 201001 1
480 __all_import_table_task_history 0 201001 1
494 __all_aux_stat 0 201001 1
10001 __tenant_virtual_all_table 2 201001 1
10002 __tenant_virtual_table_column 2 201001 1
10003 __tenant_virtual_table_index 2 201001 1
@ -667,6 +668,7 @@ select 0xffffffffff & table_id, table_name, table_type, database_id, part_num fr
12425 __all_virtual_import_table_job_history 2 201001 1
12426 __all_virtual_import_table_task 2 201001 1
12427 __all_virtual_import_table_task_history 2 201001 1
12447 __all_virtual_aux_stat 2 201001 1
20001 GV$OB_PLAN_CACHE_STAT 1 201001 1
20002 GV$OB_PLAN_CACHE_PLAN_STAT 1 201001 1
20003 SCHEMATA 1 201002 1
@ -1034,6 +1036,8 @@ select 0xffffffffff & table_id, table_name, table_type, database_id, part_num fr
21474 DBA_OB_IMPORT_TABLE_TASK_HISTORY 1 201001 1
21477 GV$OB_TENANT_RUNTIME_INFO 1 201001 1
21478 V$OB_TENANT_RUNTIME_INFO 1 201001 1
21497 DBA_OB_AUX_STATISTICS 1 201001 1
21498 CDB_OB_AUX_STATISTICS 1 201001 1
check sys table count and table_id range success
check count and table_id range for virtual table success
select * from information_schema.CHARACTER_SETS limit 1;