[FEAT MERGE] implement dynamic sampling

This commit is contained in:
wangt1xiuyi
2023-04-27 12:15:28 +00:00
committed by ob-robot
parent 56f85c9c76
commit f745b47cbc
86 changed files with 6754 additions and 2282 deletions

View File

@ -167,6 +167,17 @@ void ObGlobalHint::merge_parallel_hint(int64_t parallel)
}
}
void ObGlobalHint::merge_dynamic_sampling_hint(int64_t dynamic_sampling)
{
if (dynamic_sampling != UNSET_DYNAMIC_SAMPLING) {
if (UNSET_DYNAMIC_SAMPLING == dynamic_sampling_ || dynamic_sampling == dynamic_sampling_) {
dynamic_sampling_ = dynamic_sampling;
} else {//conflict will cause reset origin state compatible Oracle.
dynamic_sampling_ = UNSET_DYNAMIC_SAMPLING;
}
}
}
void ObGlobalHint::merge_parallel_dml_hint(ObPDMLOption pdml_option)
{
if (ObPDMLOption::DISABLE != pdml_option_ && ObPDMLOption::ENABLE != pdml_option_) {
@ -305,6 +316,7 @@ void ObGlobalHint::reset()
enable_append_ = false;
osg_hint_.flags_ = 0;
has_dbms_stats_hint_ = false;
dynamic_sampling_ = ObGlobalHint::UNSET_DYNAMIC_SAMPLING;
}
int ObGlobalHint::merge_global_hint(const ObGlobalHint &other)
@ -331,6 +343,7 @@ int ObGlobalHint::merge_global_hint(const ObGlobalHint &other)
enable_append_ |= other.enable_append_;
osg_hint_.flags_ |= other.osg_hint_.flags_;
has_dbms_stats_hint_ |= other.has_dbms_stats_hint_;
merge_dynamic_sampling_hint(other.dynamic_sampling_);
if (OB_FAIL(merge_monitor_hints(other.monitoring_ids_))) {
LOG_WARN("failed to merge monitor hints", K(ret));
} else if (OB_FAIL(merge_dop_hint(other.dops_))) {
@ -491,6 +504,9 @@ int ObGlobalHint::print_global_hint(PlanText &plan_text, const bool ignore_paral
if (OB_SUCC(ret) && has_append()) { // APPEND
PRINT_GLOBAL_HINT_STR("APPEND");
}
if (OB_SUCC(ret) && UNSET_DYNAMIC_SAMPLING != dynamic_sampling_) { //DYNAMIC SAMPLING
PRINT_GLOBAL_HINT_NUM("DYNAMIC_SAMPLING", dynamic_sampling_);
}
if (OB_SUCC(ret) && OB_FAIL(opt_params_.print_opt_param_hint(plan_text))) {
LOG_WARN("failed to print opt param hint", K(ret));
}
@ -683,6 +699,16 @@ bool ObOptParamHint::is_param_val_valid(const OptParamType param_type, const ObO
|| 0 == val.get_varchar().case_compare("false"));
break;
}
case USE_DEFAULT_OPT_STAT: {
is_valid = val.is_varchar() && (0 == val.get_varchar().case_compare("true")
|| 0 == val.get_varchar().case_compare("false"));
break;
}
case USE_FORCE_BLOCK_SAMPLE: {
is_valid = val.is_varchar() && (0 == val.get_varchar().case_compare("true")
|| 0 == val.get_varchar().case_compare("false"));
break;
}
default:
LOG_TRACE("invalid opt param val", K(param_type), K(val));
break;
@ -834,6 +860,7 @@ ObItemType ObHint::get_hint_type(ObItemType type)
case T_NO_DISTINCT_PUSHDOWN: return T_DISTINCT_PUSHDOWN;
case T_NO_USE_HASH_SET: return T_USE_HASH_SET;
case T_NO_USE_DISTRIBUTED_DML: return T_USE_DISTRIBUTED_DML;
case T_DYNAMIC_SAMPLING: return T_DYNAMIC_SAMPLING;
default: return type;
}
@ -975,6 +1002,7 @@ int ObHint::deep_copy_hint_contain_table(ObIAllocator *allocator, ObHint *&hint)
case HINT_GROUPBY_PLACEMENT: DEEP_COPY_NORMAL_HINT(ObGroupByPlacementHint); break;
case HINT_JOIN_FILTER: DEEP_COPY_NORMAL_HINT(ObJoinFilterHint); break;
case HINT_WIN_MAGIC: DEEP_COPY_NORMAL_HINT(ObWinMagicHint); break;
case HINT_TABLE_DYNAMIC_SAMPLING: DEEP_COPY_NORMAL_HINT(ObTableDynamicSamplingHint); break;
default: {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected hint type to deep copy", K(ret), K(hint_class_));
@ -2542,5 +2570,36 @@ int ObAggHint::print_hint_desc(PlanText &plan_text) const
return ret;
}
int ObTableDynamicSamplingHint::assign(const ObTableDynamicSamplingHint &other)
{
int ret = OB_SUCCESS;
if (OB_FAIL(table_.assign(other.table_))) {
LOG_WARN("fail to assign table", K(ret));
} else if (OB_FAIL(ObOptHint::assign(other))) {
LOG_WARN("fail to assign hint", K(ret));
} else {
dynamic_sampling_ = other.dynamic_sampling_;
sample_block_cnt_ = other.sample_block_cnt_;
}
return ret;
}
int ObTableDynamicSamplingHint::print_hint_desc(PlanText &plan_text) const
{
int ret = OB_SUCCESS;
char *buf = plan_text.buf_;
int64_t &buf_len = plan_text.buf_len_;
int64_t &pos = plan_text.pos_;
if (OB_FAIL(table_.print_table_in_hint(plan_text))) {
LOG_WARN("fail to print table in hint", K(ret));
} else if (OB_FAIL(BUF_PRINTF(" %ld", dynamic_sampling_))) {
LOG_WARN("fail to print dynamic sampling", K(ret));
} else if (sample_block_cnt_ > 0 &&
OB_FAIL(BUF_PRINTF(" %ld", sample_block_cnt_))) {
LOG_WARN("fail to print dynamic sampling sample percent", K(ret));
}
return ret;
}
}//end of namespace sql
}//end of namespace oceanbase