Commit 0a99d033 authored by Sergei Petrunia's avatar Sergei Petrunia

Input to: MDEV-33281 Implement optimizer hints: Comments and renames

parent 6edc0225
...@@ -52,7 +52,8 @@ const LEX_CSTRING sys_qb_prefix= {"select#", 7}; ...@@ -52,7 +52,8 @@ const LEX_CSTRING sys_qb_prefix= {"select#", 7};
static const Lex_ident_sys null_ident_sys; static const Lex_ident_sys null_ident_sys;
static void print_warn(THD *thd, uint err_code, opt_hints_enum hint_type, static
void print_warn(THD *thd, uint err_code, opt_hints_enum hint_type,
bool hint_state, bool hint_state,
const Lex_ident_sys *qb_name_arg, const Lex_ident_sys *qb_name_arg,
const Lex_ident_sys *table_name_arg, const Lex_ident_sys *table_name_arg,
...@@ -221,7 +222,7 @@ static Opt_hints_table *get_table_hints(Parse_context *pc, ...@@ -221,7 +222,7 @@ static Opt_hints_table *get_table_hints(Parse_context *pc,
bool Opt_hints::get_switch(opt_hints_enum type_arg) const bool Opt_hints::get_switch(opt_hints_enum type_arg) const
{ {
if (is_specified(type_arg)) if (is_specified(type_arg))
return hints_map.switch_on(type_arg); return hints_map.is_switched_on(type_arg);
if (opt_hint_info[type_arg].check_upper_lvl) if (opt_hint_info[type_arg].check_upper_lvl)
return parent->get_switch(type_arg); return parent->get_switch(type_arg);
...@@ -263,7 +264,7 @@ void Opt_hints::print(THD *thd, String *str) ...@@ -263,7 +264,7 @@ void Opt_hints::print(THD *thd, String *str)
void Opt_hints::append_hint_type(String *str, opt_hints_enum type) void Opt_hints::append_hint_type(String *str, opt_hints_enum type)
{ {
if(!hints_map.switch_on(type)) if (!hints_map.is_switched_on(type))
str->append(STRING_WITH_LEN("NO_")); str->append(STRING_WITH_LEN("NO_"));
str->append(opt_hint_info[type].hint_name); str->append(opt_hint_info[type].hint_name);
} }
...@@ -330,6 +331,11 @@ Opt_hints_table *Opt_hints_qb::adjust_table_hints(TABLE *table, ...@@ -330,6 +331,11 @@ Opt_hints_table *Opt_hints_qb::adjust_table_hints(TABLE *table,
} }
/*
@brief
For each index IDX, put its hints into keyinfo_array[IDX]
*/
void Opt_hints_table::adjust_key_hints(TABLE *table) void Opt_hints_table::adjust_key_hints(TABLE *table)
{ {
set_resolved(); set_resolved();
...@@ -339,7 +345,7 @@ void Opt_hints_table::adjust_key_hints(TABLE *table) ...@@ -339,7 +345,7 @@ void Opt_hints_table::adjust_key_hints(TABLE *table)
return; return;
} }
/* Make sure that adjustement is called only once. */ /* Make sure that adjustment is called only once. */
DBUG_ASSERT(keyinfo_array.size() == 0); DBUG_ASSERT(keyinfo_array.size() == 0);
keyinfo_array.resize(table->s->keys, NULL); keyinfo_array.resize(table->s->keys, NULL);
...@@ -414,6 +420,14 @@ static bool get_hint_state(Opt_hints *hint, ...@@ -414,6 +420,14 @@ static bool get_hint_state(Opt_hints *hint,
} }
/*
@brief
Check whether a given optimization is enabled for table.keyno.
@detail
First check if a hint is present, then check optimizer_switch
*/
bool hint_key_state(const THD *thd, const TABLE *table, bool hint_key_state(const THD *thd, const TABLE *table,
uint keyno, opt_hints_enum type_arg, uint keyno, opt_hints_enum type_arg,
uint optimizer_switch) uint optimizer_switch)
...@@ -690,7 +704,7 @@ bool Optimizer_hint_parser::Hint_list::resolve(Parse_context *pc) ...@@ -690,7 +704,7 @@ bool Optimizer_hint_parser::Hint_list::resolve(Parse_context *pc)
while(Optimizer_hint_parser::Hint *hint= li++) while(Optimizer_hint_parser::Hint *hint= li++)
{ {
if (const Table_level_hint &table_hint= if (const Table_level_hint &table_hint=
static_cast<const Table_level_hint &>(*hint)) /*static_cast<const Table_level_hint &>*/(*hint))
{ {
if (table_hint.resolve(pc)) if (table_hint.resolve(pc))
return true; return true;
......
...@@ -112,7 +112,7 @@ class Opt_hints_map : public Sql_alloc ...@@ -112,7 +112,7 @@ class Opt_hints_map : public Sql_alloc
@return switch value. @return switch value.
*/ */
bool switch_on(opt_hints_enum type_arg) const bool is_switched_on(opt_hints_enum type_arg) const
{ {
return hints.is_set(type_arg); return hints.is_set(type_arg);
} }
...@@ -128,10 +128,10 @@ class Opt_hints_key; ...@@ -128,10 +128,10 @@ class Opt_hints_key;
Opt_hints_global class is hierarchical structure. Opt_hints_global class is hierarchical structure.
It contains information about global hints and also It contains information about global hints and also
conains array of QUERY BLOCK level objects (Opt_hints_qb class). contains array of QUERY BLOCK level objects (Opt_hints_qb class).
Each QUERY BLOCK level object contains array of TABLE level hints Each QUERY BLOCK level object contains array of TABLE level hints
(class Opt_hints_table). Each TABLE level hint contains array of (class Opt_hints_table). Each TABLE level hint contains array of
KEY lelev hints (Opt_hints_key class). KEY level hints (Opt_hints_key class).
Hint information(specified, on|off state) is stored in hints_map object. Hint information(specified, on|off state) is stored in hints_map object.
*/ */
......
...@@ -196,7 +196,7 @@ class Parser_templates ...@@ -196,7 +196,7 @@ class Parser_templates
/* /*
A rule consisting of three other rules in a row: A rule consisting of four other rules in a row:
rule ::= rule1 rule2 rule3 rule4 rule ::= rule1 rule2 rule3 rule4
*/ */
template<class PARSER, class A, class B, class C, class D> template<class PARSER, class A, class B, class C, class D>
......
...@@ -10684,7 +10684,7 @@ bool LEX::parsed_insert_select(SELECT_LEX *first_select) ...@@ -10684,7 +10684,7 @@ bool LEX::parsed_insert_select(SELECT_LEX *first_select)
return true; return true;
// fix "main" select // fix "main" select
resolve_optimizer_hints(); resolve_optimizer_hints_in_last_select();
SELECT_LEX *blt __attribute__((unused))= pop_select(); SELECT_LEX *blt __attribute__((unused))= pop_select();
DBUG_ASSERT(blt == &builtin_select); DBUG_ASSERT(blt == &builtin_select);
push_select(first_select); push_select(first_select);
...@@ -12453,7 +12453,7 @@ LEX::parse_optimizer_hints(const Lex_comment_st &hints_str) ...@@ -12453,7 +12453,7 @@ LEX::parse_optimizer_hints(const Lex_comment_st &hints_str)
} }
void LEX::resolve_optimizer_hints() void LEX::resolve_optimizer_hints_in_last_select()
{ {
SELECT_LEX *select_lex; SELECT_LEX *select_lex;
if (likely(select_stack_top)) if (likely(select_stack_top))
......
...@@ -3725,7 +3725,7 @@ struct LEX: public Query_tables_list ...@@ -3725,7 +3725,7 @@ struct LEX: public Query_tables_list
DBUG_RETURN(select_lex); DBUG_RETURN(select_lex);
} }
void resolve_optimizer_hints(); void resolve_optimizer_hints_in_last_select();
SELECT_LEX *current_select_or_default() SELECT_LEX *current_select_or_default()
{ {
......
...@@ -8765,7 +8765,7 @@ query_specification: ...@@ -8765,7 +8765,7 @@ query_specification:
opt_having_clause opt_having_clause
opt_window_clause opt_window_clause
{ {
Lex->resolve_optimizer_hints(); Lex->resolve_optimizer_hints_in_last_select();
$$= Lex->pop_select(); $$= Lex->pop_select();
} }
; ;
...@@ -8779,7 +8779,7 @@ select_into_query_specification: ...@@ -8779,7 +8779,7 @@ select_into_query_specification:
opt_having_clause opt_having_clause
opt_window_clause opt_window_clause
{ {
Lex->resolve_optimizer_hints(); Lex->resolve_optimizer_hints_in_last_select();
$$= Lex->pop_select(); $$= Lex->pop_select();
} }
; ;
...@@ -13339,7 +13339,7 @@ insert: ...@@ -13339,7 +13339,7 @@ insert:
insert_field_spec opt_insert_update opt_returning insert_field_spec opt_insert_update opt_returning
insert_stmt_end insert_stmt_end
{ {
Lex->resolve_optimizer_hints(); Lex->resolve_optimizer_hints_in_last_select();
Lex->mark_first_table_as_inserting(); Lex->mark_first_table_as_inserting();
thd->get_stmt_da()->reset_current_row_for_warning(0); thd->get_stmt_da()->reset_current_row_for_warning(0);
} }
...@@ -13361,7 +13361,7 @@ replace: ...@@ -13361,7 +13361,7 @@ replace:
insert_field_spec opt_returning insert_field_spec opt_returning
insert_stmt_end insert_stmt_end
{ {
Lex->resolve_optimizer_hints(); Lex->resolve_optimizer_hints_in_last_select();
Lex->mark_first_table_as_inserting(); Lex->mark_first_table_as_inserting();
thd->get_stmt_da()->reset_current_row_for_warning(0); thd->get_stmt_da()->reset_current_row_for_warning(0);
} }
...@@ -13377,7 +13377,7 @@ insert_start: { ...@@ -13377,7 +13377,7 @@ insert_start: {
; ;
stmt_end: { stmt_end: {
Lex->resolve_optimizer_hints(); Lex->resolve_optimizer_hints_in_last_select();
Lex->pop_select(); //main select Lex->pop_select(); //main select
if (Lex->check_main_unit_semantics()) if (Lex->check_main_unit_semantics())
MYSQL_YYABORT; MYSQL_YYABORT;
...@@ -13744,7 +13744,7 @@ delete: ...@@ -13744,7 +13744,7 @@ delete:
{ {
if (Lex->check_cte_dependencies_and_resolve_references()) if (Lex->check_cte_dependencies_and_resolve_references())
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->resolve_optimizer_hints(); Lex->resolve_optimizer_hints_in_last_select();
} }
; ;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment