13 Commits

Author SHA1 Message Date
Oleg Smirnov
6e2a0501b6 MDEV-36638 Some optimizer hint warnings are returned as errors
With strict SQL_MODE warnings generated during DDL statements
are threated as errors. This is done to prevent potential data
corruption. However, optimizer hints cannot affect the integrity
of data, so warnings during their parsing or application should not
be escalated to the level of errors.

This commit introduces `push_warning_safe()` method that guarantees
that a warning is not treated as an error, and generation of warnings
during hints processing now uses this method instead of traditional
`push_warning_printf()`
2025-05-05 12:02:47 +07:00
Oleg Smirnov
349f5bf2da MDEV-34870: implement join order hints
This commit implements optimizer hints allowing to affect the order
of joining tables:

 - JOIN_FIXED_ORDER similar to existing STRAIGHT_JOIN hint;
 - JOIN_ORDER to apply the specified table order;
 - JOIN_PREFIX to hint what tables should be first in the join;
 - JOIN_SUFFIX to hint what tables should be last in the join.
2025-05-05 12:02:47 +07:00
Sergei Petrunia
c4fe794d22 MDEV-33281 Optimizer hints code cleanup:
- remove get_args_printer() from hints printing
 - add append_hint_arguments(THD *thd, opt_hints_enum hint, String *str)
 - add more comments
 - rename st_opt_hint_info::hint_name to hint_type
 - add pptimizer trace support for hints
 - add dbug_print_hints()
 - make print_warn() not be a template
 - introduce Printable_parser_rule interface, make grammar rules that
     emit warnings implement it  and print_warn invokes its function)
 - remove Parser::Hint::append_args() as it is not used anywhere
     (it used to be necessary call print_warn(... (Parser::Hint*)NULL);
2025-05-05 12:02:47 +07:00
Sergei Petrunia
d2918e10fc 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
2025-05-05 12:02:47 +07:00
Oleg Smirnov
2c8f6058c1 MDEV-34888 Implement SEMIJOIN() and SUBQUERY() hints 2025-05-05 12:02:47 +07:00
Oleg Smirnov
e3bf4c826c MDEV-34860 Make the hint override global/session/statement setting of max_statement_time 2025-05-05 12:02:47 +07:00
Oleg Smirnov
af14196b8a MDEV-33281 Make BNL() hint enable hashed join buffers
Since BNL() hint does not specify which whether hashed or non-hashed
join cache should be employed, allow usage of hashed ones
where possible
2025-05-05 12:02:47 +07:00
Oleg Smirnov
67319f3e8d MDEV-34860 Implement MAX_EXECUTION_TIME hint
It places a limit N (a timeout value in milliseconds) on how long
a statement is permitted to execute before the server terminates it.

Syntax:
SELECT /*+ MAX_EXECUTION_TIME(milliseconds) */ ...

Only top-level SELECT statements support the hint.
2025-05-05 12:02:47 +07:00
Sergei Petrunia
e4af72bd5d MDEV-33281 Optimizer hints cleanup: add const specifiers, comments 2025-05-05 12:02:47 +07:00
Oleg Smirnov
1cd928c297 MDEV-33281 Implement optimizer hints
Forbid adding optimizer hints to view definitions.
In the case when optimizer hints are added to the view definition
at a `CREATE (OR REPLACE) VIEW`/`ALTER VIEW` statement, a warning is
generated and the hints are ignored.

This commit also disables ps-protocol for test cases where
`Unresolved table/index name` warnings are generated. The reason
for this is such warnings are generated during both PREPARE
and EXECUTE stages. Since opt_hints.test has `--enable_prepare_warnings`,
running it with `--ps-protocol` causes duplication of warning messages
2025-05-05 12:02:47 +07:00
Oleg Smirnov
4bb2669d18 MDEV-33281 Optimizer hints Cleanup: fix formatting, rename objects 2025-05-05 12:02:47 +07:00
Alexander Barkov
bd30c796fa 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.
2025-05-05 12:02:47 +07:00
Oleg Smirnov
877e4a386c MDEV-33281 Implement optimizer hints
This commit introduces:
    - the infrastructure for optimizer hints;
    - hints for join buffering: BNL(), NO_BNL(), BKA(), NO_BKA();
    - NO_ICP() hint for disabling index condition pushdown;
    - MRR(), MO_MRR() hint for multi-range reads control;
    - NO_RANGE_OPTIMIZATION() for disabling range optimization;
    - QB_NAME() for assigning names for query blocks.
2025-05-05 12:02:47 +07:00