mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-33281 Optimizer hints cleanup:
- add a comment that opt_hints_global->check_unresolved() is never called - improve comments - rename everything with "resolved_children" to "fully_resolved_children" - Opt_hints_table::adjust_key_hints() now returns value - less "reach-back-to-parent" logic - rename Hint "adjustment" and "resolution" (yes, both terms were used) to "fixing". "Resolution" is already used for parse-tree objects
This commit is contained in:
committed by
Oleg Smirnov
parent
2c8f6058c1
commit
d2918e10fc
@@ -21,8 +21,7 @@
|
||||
#include "opt_hints.h"
|
||||
|
||||
/**
|
||||
Information about hints. Sould be
|
||||
synchronized with opt_hints_enum enum.
|
||||
Information about hints. Must be in sync with opt_hints_enum.
|
||||
|
||||
Note: Hint name depends on hint state. 'NO_' prefix is added
|
||||
if appropriate hint state bit(see Opt_hints_map::hints) is not
|
||||
@@ -176,7 +175,12 @@ static Opt_hints_qb *get_qb_hints(Parse_context *pc)
|
||||
{
|
||||
global_hints->register_child(qb);
|
||||
pc->select->opt_hints_qb= qb;
|
||||
qb->set_resolved();
|
||||
/*
|
||||
Mark the query block as resolved as we know which SELECT_LEX it is
|
||||
attached to.
|
||||
Note that children (indexes, tables) are probably not resolved, yet.
|
||||
*/
|
||||
qb->set_fixed();
|
||||
}
|
||||
return qb;
|
||||
}
|
||||
@@ -272,7 +276,7 @@ void Opt_hints::print(THD *thd, String *str)
|
||||
{
|
||||
for (uint i= 0; i < MAX_HINT_ENUM; i++)
|
||||
{
|
||||
if (is_specified(static_cast<opt_hints_enum>(i)) && is_resolved())
|
||||
if (is_specified(static_cast<opt_hints_enum>(i)) && is_fixed())
|
||||
{
|
||||
append_hint_type(str, static_cast<opt_hints_enum>(i));
|
||||
str->append(STRING_WITH_LEN("("));
|
||||
@@ -308,7 +312,7 @@ void Opt_hints::append_hint_type(String *str, opt_hints_enum type)
|
||||
}
|
||||
|
||||
|
||||
void Opt_hints::print_warn_unresolved(THD *thd)
|
||||
void Opt_hints::print_unfixed_warnings(THD *thd)
|
||||
{
|
||||
String hint_name_str, hint_type_str;
|
||||
append_name(thd, &hint_name_str);
|
||||
@@ -320,24 +324,29 @@ void Opt_hints::print_warn_unresolved(THD *thd)
|
||||
hint_type_str.length(0);
|
||||
append_hint_type(&hint_type_str, static_cast<opt_hints_enum>(i));
|
||||
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
|
||||
get_warn_unresolved_code(),
|
||||
ER_THD(thd, get_warn_unresolved_code()),
|
||||
get_unfixed_warning_code(),
|
||||
ER_THD(thd, get_unfixed_warning_code()),
|
||||
hint_name_str.c_ptr_safe(),
|
||||
hint_type_str.c_ptr_safe());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@brief
|
||||
Recursively walk the descendant hints and emit warnings for any
|
||||
unresolved hints
|
||||
*/
|
||||
|
||||
void Opt_hints::check_unresolved(THD *thd)
|
||||
void Opt_hints::check_unfixed(THD *thd)
|
||||
{
|
||||
if (!is_resolved())
|
||||
print_warn_unresolved(thd);
|
||||
if (!is_fixed())
|
||||
print_unfixed_warnings(thd);
|
||||
|
||||
if (!is_all_resolved())
|
||||
if (!are_children_fully_fixed())
|
||||
{
|
||||
for (uint i= 0; i < child_array.size(); i++)
|
||||
child_array[i]->check_unresolved(thd);
|
||||
child_array[i]->check_unfixed(thd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,8 +363,8 @@ Opt_hints_qb::Opt_hints_qb(Opt_hints *opt_hints_arg,
|
||||
}
|
||||
|
||||
|
||||
Opt_hints_table *Opt_hints_qb::adjust_hints_for_table(TABLE *table,
|
||||
const Lex_ident_table &alias)
|
||||
Opt_hints_table *Opt_hints_qb::fix_hints_for_table(TABLE *table,
|
||||
const Lex_ident_table &alias)
|
||||
{
|
||||
Opt_hints_table *tab= static_cast<Opt_hints_table *>(find_by_name(alias));
|
||||
|
||||
@@ -364,7 +373,9 @@ Opt_hints_table *Opt_hints_qb::adjust_hints_for_table(TABLE *table,
|
||||
if (!tab) // Tables not found
|
||||
return NULL;
|
||||
|
||||
tab->adjust_key_hints(table);
|
||||
if (!tab->fix_hint(table))
|
||||
incr_fully_fixed_children();
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
@@ -411,16 +422,18 @@ uint Opt_hints_qb::sj_enabled_strategies(uint opt_switches) const
|
||||
/*
|
||||
@brief
|
||||
For each index IDX, put its hints into keyinfo_array[IDX]
|
||||
|
||||
*/
|
||||
void Opt_hints_table::adjust_key_hints(TABLE *table)
|
||||
|
||||
bool Opt_hints_table::fix_hint(TABLE *table)
|
||||
{
|
||||
set_resolved();
|
||||
/*
|
||||
Ok, there's a table we attach to. Mark this hint as fixed and proceed to
|
||||
fixing the child objects.
|
||||
*/
|
||||
set_fixed();
|
||||
|
||||
if (child_array_ptr()->size() == 0) // No key level hints
|
||||
{
|
||||
get_parent()->incr_resolved_children();
|
||||
return;
|
||||
}
|
||||
return false; // Ok, fully fixed
|
||||
|
||||
/* Make sure that adjustment is called only once. */
|
||||
DBUG_ASSERT(keyinfo_array.size() == 0);
|
||||
@@ -434,20 +447,18 @@ void Opt_hints_table::adjust_key_hints(TABLE *table)
|
||||
{
|
||||
if (key_info->name.streq((*hint)->get_name()))
|
||||
{
|
||||
(*hint)->set_resolved();
|
||||
(*hint)->set_fixed();
|
||||
keyinfo_array[j]= static_cast<Opt_hints_key *>(*hint);
|
||||
incr_resolved_children();
|
||||
incr_fully_fixed_children();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Do not increase number of resolved tables
|
||||
if there are unresolved key objects. It's
|
||||
important for check_unresolved() function.
|
||||
*/
|
||||
if (is_all_resolved())
|
||||
get_parent()->incr_resolved_children();
|
||||
if (are_children_fully_fixed())
|
||||
return false;
|
||||
|
||||
return true; // Some children are not fully fixed
|
||||
}
|
||||
|
||||
|
||||
@@ -1105,7 +1116,12 @@ ulonglong Parser::Max_execution_time_hint::get_milliseconds() const
|
||||
}
|
||||
|
||||
|
||||
bool Opt_hints_global::resolve(THD *thd)
|
||||
/*
|
||||
@brief
|
||||
Fix global-level hints (and only them)
|
||||
*/
|
||||
|
||||
bool Opt_hints_global::fix_hint(THD *thd)
|
||||
{
|
||||
if (thd->lex->is_ps_or_view_context_analysis())
|
||||
return false;
|
||||
@@ -1113,7 +1129,7 @@ bool Opt_hints_global::resolve(THD *thd)
|
||||
if (!max_exec_time_hint)
|
||||
{
|
||||
/* No possible errors */
|
||||
set_resolved();
|
||||
set_fixed();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1136,7 +1152,7 @@ bool Opt_hints_global::resolve(THD *thd)
|
||||
thd->reset_query_timer();
|
||||
thd->set_query_timer_force(max_exec_time_hint->get_milliseconds() * 1000);
|
||||
}
|
||||
set_resolved();
|
||||
set_fixed();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user