Commit aed17abe authored by Oleg Smirnov's avatar Oleg Smirnov

MDEV-33281 Fix code review comments

parent ff7f3f0a
......@@ -209,7 +209,7 @@ DROP PACKAGE test.pkg;
# End of 11.4 tests
#
#
# Start of 11.6 tests
# Start of 11.7 tests
#
#
# MDEV-33281 Implement optimizer hints like in MySQL
......@@ -233,5 +233,5 @@ Warnings:
Warning 4202 Hint BKA("A") is ignored as conflicting/duplicated
DROP TABLE t1;
#
# End of 11.6 tests
# End of 11.7 tests
#
......@@ -208,7 +208,7 @@ DROP PACKAGE test.pkg;
--echo #
--echo # Start of 11.6 tests
--echo # Start of 11.7 tests
--echo #
--echo #
......@@ -233,5 +233,5 @@ SELECT /*+BKA(a) BKA(A)*/ a.a FROM t1 a;
DROP TABLE t1;
--echo #
--echo # End of 11.6 tests
--echo # End of 11.7 tests
--echo #
......@@ -190,7 +190,7 @@ DROP DATABASE MYSQL;
# End of 10.5 tests
#
#
# Start of 11.6 tests
# Start of 11.7 tests
#
#
# MDEV-33281 Implement optimizer hints like in MySQL
......@@ -212,5 +212,5 @@ a a
2 2
DROP TABLE t1;
#
# End of 11.6 tests
# End of 11.7 tests
#
......@@ -189,7 +189,7 @@ DROP DATABASE MYSQL;
--echo #
--echo #
--echo # Start of 11.6 tests
--echo # Start of 11.7 tests
--echo #
--echo #
......@@ -212,5 +212,5 @@ SELECT /*+BKA(a) BKA(A)*/ a.a, A.a FROM t1 a, t1 A;
DROP TABLE t1;
--echo #
--echo # End of 11.6 tests
--echo # End of 11.7 tests
--echo #
......@@ -34,12 +34,12 @@
struct st_opt_hint_info opt_hint_info[]=
{
{Lex_cstring_strlen("BKA"), true, true},
{Lex_cstring_strlen("BNL"), true, true},
{Lex_cstring_strlen("ICP"), true, true},
{Lex_cstring_strlen("MRR"), true, true},
{Lex_cstring_strlen("NO_RANGE_OPTIMIZATION"), true, true},
{Lex_cstring_strlen("QB_NAME"), false, false},
{{STRING_WITH_LEN("BKA")}, true, true},
{{STRING_WITH_LEN("BNL")}, true, true},
{{STRING_WITH_LEN("ICP")}, true, true},
{{STRING_WITH_LEN("MRR")}, true, true},
{{STRING_WITH_LEN("NO_RANGE_OPTIMIZATION")}, true, true},
{{STRING_WITH_LEN("QB_NAME")}, false, false},
{null_clex_str, 0, 0}
};
......@@ -234,9 +234,9 @@ Opt_hints* Opt_hints::find_by_name(const LEX_CSTRING &name_arg) const
{
for (uint i= 0; i < child_array.size(); i++)
{
const LEX_CSTRING *name= child_array[i]->get_name();
const LEX_CSTRING name= child_array[i]->get_name();
CHARSET_INFO *cs= child_array[i]->charset_info();
if (name && !cs->strnncollsp(*name, name_arg))
if (name.str && !cs->strnncollsp(name, name_arg))
return child_array[i];
}
return NULL;
......@@ -356,7 +356,7 @@ void Opt_hints_table::adjust_key_hints(TABLE *table)
KEY *key_info= table->key_info;
for (uint j= 0 ; j < table->s->keys ; j++, key_info++)
{
if (key_info->name.streq((*hint)->get_name()[0]))
if (key_info->name.streq((*hint)->get_name()))
{
(*hint)->set_resolved();
keyinfo_array[j]= static_cast<Opt_hints_key *>(*hint);
......@@ -666,7 +666,7 @@ bool Optimizer_hint_parser::Qb_name_hint::resolve(Parse_context *pc) const
const Lex_ident_sys qb_name_sys= Query_block_name::to_ident_sys(pc->thd);
if (qb->get_name() || // QB name is already set
if (qb->get_name().str || // QB name is already set
qb->get_parent()->find_by_name(qb_name_sys)) // Name is already used
{
print_warn(pc->thd, ER_WARN_CONFLICTING_HINT, QB_NAME_HINT_ENUM, true,
......
......@@ -139,6 +139,7 @@ class Opt_hints_key;
class Opt_hints : public Sql_alloc
{
protected:
/*
Name of object referred by the hint.
This name is empty for global level,
......@@ -147,6 +148,7 @@ class Opt_hints : public Sql_alloc
for key level.
*/
Lex_ident_sys name;
private:
/*
Parent object. There is no parent for global level,
for query block level parent is Opt_hints_global object,
......@@ -215,9 +217,9 @@ class Opt_hints : public Sql_alloc
return Lex_ident_column::charset_info();
}
virtual const LEX_CSTRING *get_name() const
const LEX_CSTRING get_name() const
{
return name.str ? &name : nullptr;
return name;
}
void set_name(const Lex_ident_sys &name_arg) { name= name_arg; }
Opt_hints *get_parent() const { return parent; }
......@@ -326,10 +328,9 @@ class Opt_hints_qb : public Opt_hints
MEM_ROOT *mem_root_arg,
uint select_number_arg);
const LEX_CSTRING *get_print_name()
const LEX_CSTRING get_print_name()
{
const LEX_CSTRING *str= Opt_hints::get_name();
return str ? str : &sys_name;
return name.str ? name : sys_name;
}
/**
......@@ -340,10 +341,10 @@ class Opt_hints_qb : public Opt_hints
*/
void append_qb_hint(THD *thd, String *str)
{
if (get_name())
if (name.str)
{
str->append(STRING_WITH_LEN("QB_NAME("));
append_identifier(thd, str, get_name()->str, get_name()->length);
append_identifier(thd, str, &name);
str->append(STRING_WITH_LEN(") "));
}
}
......@@ -356,7 +357,8 @@ class Opt_hints_qb : public Opt_hints
virtual void append_name(THD *thd, String *str) override
{
str->append(STRING_WITH_LEN("@"));
append_identifier(thd, str, get_print_name()->str, get_print_name()->length);
const LEX_CSTRING print_name= get_print_name();
append_identifier(thd, str, &print_name);
}
/**
......@@ -405,7 +407,7 @@ class Opt_hints_table : public Opt_hints
*/
virtual void append_name(THD *thd, String *str) override
{
append_identifier(thd, str, get_name()->str, get_name()->length);
append_identifier(thd, str, &name);
get_parent()->append_name(thd, str);
}
/**
......@@ -447,7 +449,7 @@ class Opt_hints_key : public Opt_hints
{
get_parent()->append_name(thd, str);
str->append(' ');
append_identifier(thd, str, get_name()->str, get_name()->length);
append_identifier(thd, str, &name);
}
virtual uint get_warn_unresolved_code() const override
......@@ -505,14 +507,4 @@ bool hint_table_state(const THD *thd, const TABLE *table,
bool hint_table_state_or_fallback(const THD *thd, const TABLE *table,
opt_hints_enum type_arg,
bool fallback_value);
class Hints_string_buffer : public StringBuffer<64>
{
public:
Hints_string_buffer()
:StringBuffer(system_charset_info)
{ }
};
#endif /* OPT_HINTS_INCLUDED */
......@@ -31665,10 +31665,10 @@ void st_select_lex::print_hints(THD *thd,
// Some hints were printed, close the hint string
str->append(STRING_WITH_LEN("*/ "));
}
else
else
{
// No hints were added, rollback the previouly added header
str->chop(header.length);
str->length(len_before_hints - header.length);
}
}
......@@ -363,21 +363,6 @@ class Binary_string: public Sql_alloc
}
}
/*
Remove `num_of_chars` trailing characters from the string.
If `num_of_chars` is larger than the string length, the methods chops all
characters
*/
void chop(uint32 num_of_chars)
{
if (num_of_chars < str_length)
str_length-= num_of_chars;
else
str_length= 0;
Ptr[str_length]= '\0';
DBUG_ASSERT(strlen(Ptr) == str_length);
}
// Returns offset to substring or -1
int strstr(const Binary_string &search, uint32 offset=0) const;
int strstr(const char *search, uint32 search_length, uint32 offset=0) const;
......
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