Commit graph

11 commits

Author SHA1 Message Date
Oleg Smirnov
7d7c2b4971 MDEV-35504 Fix post-rebase conflicts 2025-03-18 18:28:19 +01:00
Oleg Smirnov
4468a19a3e MDEV-34860 Make the hint override global/session/statement setting of max_statement_time 2025-03-18 18:28:19 +01:00
Oleg Smirnov
cb2a79db8c MDEV-33281 MDEV-33281 Make BNL() hint enable hashed join buffers 2025-03-18 18:28:19 +01:00
Oleg Smirnov
e22980ad52 MDEV-34760 Fix potential problem with append_args() 2025-03-18 18:28:19 +01:00
Oleg Smirnov
991cec8cee MDEV-34860 Fix review comments 2025-03-18 18:28:19 +01:00
Oleg Smirnov
fcba1ff661 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-03-18 18:28:19 +01:00
Sergei Petrunia
fd91219b0b Make parsed output: SELECT_LEX::parsed_optimizer_hints const.
This required changing some other functions to const too.
2025-03-18 18:28:18 +01:00
Oleg Smirnov
3923b10894 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-03-18 18:28:18 +01:00
Oleg Smirnov
28a59a4e29 MDEV-33281 Fix code review comments 2025-03-18 18:28:18 +01:00
Alexander Barkov
8879474654 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-03-18 18:28:18 +01:00
Oleg Smirnov
52c96bef29 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-03-18 18:28:18 +01:00