mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-33281 Implement optimizer hints
- Using Lex_ident_sys to scan identifiers, like the SQL parser does. This fixes handling of double-quote-delimited and backtick-delimited identifiers, as well as handling of non-ASCII identifiers. Unescaping and converting from the client character set to the system character set is now done using Lex_ident_cli_st and Lex_ident_sys, like it's done in the SQL tokenizer/parser. Adding helper methods to_ident_cli() and to_ident_sys() in Optimizer_hint_parser::Token. - Fixing the hint parser to report a syntax error when an empty identifiers: SELECT /*+ BKA(``) */ * FROM t1; - Moving a part of the code from opt_hints_parser.h to opt_hints_parser.cc Moving these method definitions: - Optimizer_hint_tokenizer::find_keyword() - Optimizer_hint_tokenizer::get_token() to avoid huge pieces of the code in the header file. - A Lex_ident_cli_st cleanup Fixing a few Lex_ident_cli_st methods to return Lex_ident_cli_st & instead of void, to use them easier in the caller code. - Fixing the hint parser to display the correct line number Adding a new data type Lex_comment_st (a combination of LEX_CSTRING and a line number) Using it in sql_yacc.yy - Getting rid of redundant dependencies on sql_hints_parser.h Moving void LEX::resolve_optimizer_hints() from sql_lex.h to sql_lex.cc Adding a class Optimizer_hint_parser_output, deriving from Optimizer_hint_parser::Hint_list. Fixing the hint parser to return a pointer to an allocated instance of Optimizer_hint_parser_output rather than an instance of Optimizer_hint_parser::Hint_list. This allows to use a forward declaration of Optimizer_hint_parser_output in sql_lex.h and thus avoid dependencies on sql_hints_parser.h.
This commit is contained in:
committed by
Oleg Smirnov
parent
877e4a386c
commit
bd30c796fa
@@ -145,7 +145,7 @@ class Opt_hints : public Sql_alloc
|
||||
table name for table level and key name
|
||||
for key level.
|
||||
*/
|
||||
const LEX_CSTRING *name;
|
||||
Lex_ident_sys name;
|
||||
/*
|
||||
Parent object. There is no parent for global level,
|
||||
for query block level parent is Opt_hints_global object,
|
||||
@@ -165,7 +165,7 @@ class Opt_hints : public Sql_alloc
|
||||
|
||||
public:
|
||||
|
||||
Opt_hints(const LEX_CSTRING *name_arg,
|
||||
Opt_hints(const Lex_ident_sys &name_arg,
|
||||
Opt_hints *parent_arg,
|
||||
MEM_ROOT *mem_root_arg)
|
||||
: name(name_arg), parent(parent_arg), child_array(mem_root_arg),
|
||||
@@ -209,8 +209,11 @@ public:
|
||||
*/
|
||||
bool get_switch(opt_hints_enum type_arg) const;
|
||||
|
||||
virtual const LEX_CSTRING *get_name() const { return name; }
|
||||
void set_name(const LEX_CSTRING *name_arg) { name= name_arg; }
|
||||
virtual const LEX_CSTRING *get_name() const
|
||||
{
|
||||
return name.str ? &name : nullptr;
|
||||
}
|
||||
void set_name(const Lex_ident_sys &name_arg) { name= name_arg; }
|
||||
Opt_hints *get_parent() const { return parent; }
|
||||
void set_resolved() { resolved= true; }
|
||||
bool is_resolved() const { return resolved; }
|
||||
@@ -249,7 +252,7 @@ public:
|
||||
@return hint if found,
|
||||
NULL otherwise
|
||||
*/
|
||||
Opt_hints *find_by_name(const LEX_CSTRING *name_arg) const;
|
||||
Opt_hints *find_by_name(const LEX_CSTRING &name_arg) const;
|
||||
/**
|
||||
Print all hints except of QB_NAME hint.
|
||||
|
||||
@@ -303,7 +306,7 @@ public:
|
||||
PT_hint_max_execution_time *max_exec_time;
|
||||
|
||||
Opt_hints_global(MEM_ROOT *mem_root_arg)
|
||||
: Opt_hints(NULL, NULL, mem_root_arg)
|
||||
: Opt_hints(Lex_ident_sys(), NULL, mem_root_arg)
|
||||
{
|
||||
max_exec_time= NULL;
|
||||
}
|
||||
@@ -375,7 +378,8 @@ public:
|
||||
@return pointer Opt_hints_table object if this object is found,
|
||||
NULL otherwise.
|
||||
*/
|
||||
Opt_hints_table *adjust_table_hints(TABLE *table, const LEX_CSTRING *alias);
|
||||
Opt_hints_table *adjust_table_hints(TABLE *table,
|
||||
const Lex_ident_table &alias);
|
||||
};
|
||||
|
||||
|
||||
@@ -388,7 +392,7 @@ class Opt_hints_table : public Opt_hints
|
||||
public:
|
||||
Mem_root_array<Opt_hints_key*, true> keyinfo_array;
|
||||
|
||||
Opt_hints_table(const LEX_CSTRING *table_name_arg,
|
||||
Opt_hints_table(const Lex_ident_sys &table_name_arg,
|
||||
Opt_hints_qb *qb_hints_arg,
|
||||
MEM_ROOT *mem_root_arg)
|
||||
: Opt_hints(table_name_arg, qb_hints_arg, mem_root_arg),
|
||||
@@ -429,7 +433,7 @@ class Opt_hints_key : public Opt_hints
|
||||
{
|
||||
public:
|
||||
|
||||
Opt_hints_key(const LEX_CSTRING *key_name_arg,
|
||||
Opt_hints_key(const Lex_ident_sys &key_name_arg,
|
||||
Opt_hints_table *table_hints_arg,
|
||||
MEM_ROOT *mem_root_arg)
|
||||
: Opt_hints(key_name_arg, table_hints_arg, mem_root_arg)
|
||||
|
Reference in New Issue
Block a user