203396 Commits

Author SHA1 Message Date
e3bf4c826c MDEV-34860 Make the hint override global/session/statement setting of max_statement_time 2025-05-05 12:02:47 +07:00
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
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
1e2774d829 MDEV-33281 Make BNL() hint work for join_cache_levels from 0 to 3
BNL() hint effectively increases join_cache_level up to 4 if it is
set to value less than 4.
This commit also makes the BKA() hint override not only
`join_cache_bka` optimizer switch but `join_cache_level` as well.
I.e., BKA() hint enables BKA and BKAH join buffers both flat and
incremental despite `join_cache_level` and `join_cache_bka` setting.
2025-05-05 12:02:47 +07:00
e4af72bd5d MDEV-33281 Optimizer hints cleanup: add const specifiers, comments 2025-05-05 12:02:47 +07:00
cd9ac306c3 MDEV-33281 Make BNL() hint work for join_cache_level=0
join_cache_level=0 disables join cache buffers, but the hint
BNL() now allows to employ BNL(H) buffers for particular tables
or query blocks.

This commit also adds a number of test cases including
OUTER JOINs to make sure hints do not break the rules of
join buffers application
2025-05-05 12:02:47 +07:00
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
4bb2669d18 MDEV-33281 Optimizer hints Cleanup: fix formatting, rename objects 2025-05-05 12:02:47 +07:00
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
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
6340c23933 MDEV-33281 Implement optimizer hints
Implementing a recursive descent parser for optimizer hints.
2025-05-05 12:02:43 +07:00
495d96709f MDEV-35866 CHECK TABLE get number of rows without HA_STATS_RECORDS_IS_EXACT
Call ha_rnd_init followed by two ha_rnd_next's to find whether there
is more than one row.
2025-05-05 11:36:56 +10:00
d52ddae57b MDEV-22491 Support mariadb-check and CHECK TABLE with SEQUENCE
The check go through the following steps:

1. Run check on the underlying engine. If not ok, then return.
2. Check that there's only one row in the table, and
   2.1 warn if more than one row
   2.2 return HA_ADMIN_CORRUPT if fewer than one row (i.e. 0 rows)
3. If the sequence is not initialised (e.g. after an ALTER TABLE ...
   SEQUENCE=1), initialise the sequence by reading the sequence
   metadata from the table. This will also flush the next_free_value,
   i.e. set it to the next not cached value (SEQUENCE::reserved_until)
4. Check that the sequence metadata is valid, i.e. nothing out of
   order e.g. minvalue < maxvalue etc. If invalid it reports
   HA_ERR_SEQUENCE_INVALID_DATA
5. Check that the sequence has not been exhausted. It reports
   ER_SEQUENCE_RUN_OUT as a warning if and only if a SELECT NEXTVAL
   would do so

Limitations:

1. The check is independent of flags, so the vanilla check is the same
   as CHECK ... EXTENDED or CHECK ... FOR UPGRADE etc.
2. When the check discovers invalid metadata from the table,
   subsequent SELECT NEXTVAL will carry on (or fail) without this
   piece of knowledge, independent of the CHECK. This is to ensure
   consistency, i.e. CHECK does not modify behaviour of SELECT, and if
   anything it makes more sense that SELECT reports
   HA_ERR_SEQUENCE_INVALID_DATA in this case, regardless of prior
   CHECK
2025-05-05 11:36:55 +10:00
26ea37be5d MDEV-36405 Session tracking does not report changes from COM_CHANGE_USER
report all sysvar tracker changes, as for the new login.
also report db and other session state changes.
2025-05-03 12:06:36 +02:00
07de0ac69e MDEV-20299 SET SESSION AUTHORIZATION
a.k.a. "sudo"
2025-05-03 12:06:36 +02:00
0f4a35a327 cleanup: extract reusable code chunks
move user_name parser rule out of user_maybe_role

extract setting privileges on login from acl_authenticate() into a
  separate function
2025-05-02 13:56:25 +02:00
78d23a3e60 fix error messages
when a definer for SP/view is wrong - it shold be ER_MALFORMED_DEFINER,
not ER_NO_SUCH_USER

when one uses current_role as a definer or grantee but there's no
current role - it should be ER_INVALID_ROLE not ER_MALFORMED_DEFINER

when a non-existent user is specified - it should be ER_NO_SUCH_USER,
which should say "The user does not exist", not "Definer does not exist"

clarify ER_CANT_CHANGE_TX_CHARACTERISTICS to say what cannot be changed
2025-05-02 13:56:25 +02:00
02b81afff8 cleanup: THD::change_user 2025-05-02 13:56:25 +02:00
fa47c73561 MDEV-12182 post-merge
* fix plugin version
* don't print :unavaliable for localhost
2025-05-02 13:56:25 +02:00
1aba30b8f9 MDEV-12182 Add Client TCP Port Number to MySQL Audit Plugin Logs
In environments with load balancers or proxies, the audit plugin logs
only the IP address, making it difficult to differentiate individual client
connections from the same IP.

Add a new 'port' field to the appropriate event objects to capture the
client's TCP port number. Populate the port field with thd->port  in the
appropriate functions. The audit plugin receives and logs this port field
along  with  other connection information, enabling better identification
of individual client connections.

All new code of the whole pull request, including one or several files that
are either new files or modified ones, are contributed under the BSD-new license.
I am contributing on behalf of my employer Amazon Web Services, Inc.
2025-05-02 13:56:25 +02:00
c1f2b5a141 MDEV-33834 post-merge
* move TLS version into the "object" column
* show that TLS version follows db name
* correctly check for have_ssl
2025-05-02 13:56:25 +02:00
2b464774f2 MDEV-33834 Extend audit plugin to include tls_version and tls_version_length variables
Add tls_version and tls_version_length variables to the audit plugin so
they can be logged. This is useful to help identify suspicious or
malformed connections attempting to use unsupported TLS versions. A log
with this information will allow to detect and block more malicious
connection attempts.

Users with 'server_audit_events' empty will have these two new variables
automatically visible in their logs, but if users don't want them, they
can always configure what fields to include by listing the fields in
'server_audit_events'.

In connection event, The TLS version will be populated in `object` field
in key=value format, and the key-value pair will be omitted when the
value is empty.

To ensure the MTR test result matches in all environments, the TLS
version string is replaced with a general `TLS_VERSION` to avoid the MTR
test failing unexpectedly. It stores the version with query `SHOW STATUS
LIKE 'Ssl_version'` and replace the output with `replace_result` command.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.

[1]: https://docs.openssl.org/3.2/man3/SSL_get_version/
2025-05-02 13:56:25 +02:00
88cc11dc54 MDEV-36714: Rows_log_event::write_data_header overallocates buffer size
Nothing is broken by this, but the function
Rows_log_event::write_data_header
slightly over-allocates its buf by 2 bytes. It allocates 10
(ROWS_HEADER_LEN_V2), but only 8 are ever written.

This patch fixes the buf size to match what is written (i.e.
ROWS_HEADER_LEN_V1, or 8 bytes).

Reviewed By:
============
Kristian Nielsen <knielsen@knielsen-hq.org>
2025-05-01 08:45:44 -06:00
da5a4d05b9 MDEV-35850 make HOSTNAME a cmake configure variable
As seen with openwrt and some other distros, the
determination of hostname can sometime need alternate
commmands.

This provides a cmake option HOSTNAME for non-windows machines
for the mariadb-install-db and mariadbd-safe scripts
and the support-files init scripts..
2025-05-01 18:09:45 +10:00
3e9e1a25b7 MDEV-36566 SELECT create_temporary_table_binlog_formats should show exactly what it is SET to
added a warning
2025-04-30 12:33:24 +02:00
ee9359de89 MDEV-36425 fix test results
followup for ce8a74f235
2025-04-30 12:33:24 +02:00
c626715439 MDEV-35452 [fixup] fix spider/bugfix.perfschema view protocol
mtr with --view-protocol creates new threads
2025-04-30 10:38:44 +10:00
76e8e24b0b Merge branch '10.5' into 10.6 2025-04-30 10:35:11 +10:00
c29e83f226 MDEV-30189 Add remaining replication options as system variables
Promote the last few SQL-inaccessible replication options (command line
or `mariadb.cnf`) as these GLOBAL read-only system variables:
```
@@master_info_file
@@replicate_same_server_id
@@show_slave_auth_info
```

Side effect: The latter two options changed from no argument
to optional argument. Quote `include/my_getopt.h`:
> It should be noted that for historical reasons variables with the
> combination arg_type=NO_ARG, my_option::var_type=GET_BOOL still
> accepts arguments. This is someone counter intuitive and care should
> be taken if the code is refactored.

Reviewed-by: Brandon Nesterenko <brandon.nesterenko@mariadb.com>
2025-04-29 15:27:55 -04:00
74c189c312 MDEV-35304: Fix multi_source.connects_tried
Test multi_source.connects tried would sporadically fail with a result
mismatch resembling the following diff:

@@ -29,6 +29,7 @@
 SELECT @time_begin, CURRENT_TIMESTAMP(1)
 WHERE TIMESTAMPDIFF(SECOND, @time_begin, CURRENT_TIMESTAMP(1)) < 1;
 @time_begin  CURRENT_TIMESTAMP(1)
+2025-04-28 17:10:08.3  2025-04-28 17:10:09.2
 CREATE TEMPORARY TABLE status_sleep AS SELECT 'named' Connection_name, Connects_Tried Connects_Tried;
 SET @@SESSION.default_master_connection= '';
 include/wait_for_slave_param.inc [Connects_Tried]

This happened due to the reference variable @time_begin being set
_after_ the slave was started. That is, @time_begin was used as the
anchor point at which the time should start ticking for when
Connects_Tried should be incremented; however, MTR may not actually
be able to set it for some time after the slave had started due to
OS scheduling or heavy server load. The failure can be reproduced by
adding a 0.1s sleep statement in-between the aformentioned statements.

The fix is to set @time_begin before starting the slave so it is at
least always valid to reference as the start of the test case.
2025-04-29 11:00:37 -06:00
e1da2c3d67 increase tolerance in socket_summary_check.inc
for approx. stat P_S calculations.

fixes perfschema.socket_summary_by_instance_func
2025-04-29 16:53:02 +02:00
16c4621400 remove unused non-standard tokens from the parser
keep unused standard tokens, like LOCATOR or INSENSITIVE
2025-04-29 16:53:02 +02:00
11f6b9d12a remove features that were deprecated in 10.5
--big-tables
--large-page-size
--storage-engine

performance_schema.setup_timers (WL#10986)
2025-04-29 16:53:02 +02:00
24fd8c7856 update deprecation.h to match the latest policy changes 2025-04-29 16:53:01 +02:00
068fc787ee MDEV-36168 ASAN error in Item_func_latlongfromgeohash::decode_geohash (postfix)
pppc64le, aarch64, and s390x have char defined as unsigned so
a < 0 comparison is a compile error. The CHAR_MIN defined in limits.h
is 0 on these platforms, false, meaning the if condition is only on
signed char platforms.

To make the interface cleaner we return true on out == 255 to simplify
the calling function.
2025-04-29 07:52:55 -04:00
55ddfe1c95 MDEV-36684 - main.mdl_sync fails under valgrind (test for Bug#42643)
Valgrind is single threaded and only changes threads as part of
system calls or waits.

Some busy loops were identified and fixed where the server assumes
that some other thread will change the state, which will not happen
with valgrind.

Based on patch by Monty. Original patch introduced VALGRIND_YIELD,
which emits pthread_yield() only in valgrind builds. However it was
agreed that it is a good idea to emit yield() unconditionally, such
that other affected schedulers (like SCHED_FIFO) benefit from this
change. Also avoid pthread_yield() in favour of standard
std::this_thread::yield().
2025-04-29 15:05:20 +04:00
83e0438f62 MDEV-36536 post-review changes
that were apparently partially lost in a rebase
2025-04-29 11:34:35 +02:00
98e02217c7 Fix version 2025-04-29 08:27:07 +02:00
36dfe08672 Clarify .frm field parsing comments: use C-style block comments, reposition loop comment, and add end marker 2025-04-29 15:32:08 +10:00
865b05bf4a MDEV-35837: Update CODING_STANDARDS to C++17 [skip ci]
also annotate with MariaDB version
2025-04-29 13:55:22 +10:00
1b95e46524 Fix typos in mysql-test/ 2025-04-29 13:53:16 +10:00
40c5b62531 Fix remaining typos 2025-04-29 11:18:00 +10:00
aae8c5a5aa Update 11.8 man pages 2025-04-29 10:42:46 +10:00
bc87abc381 MDEV-36694 spatial_utility_function{_collect,_isvalid} broken for --view-protocol
In spatial_utility_function_collect, temporarily exclude the two affected
queries because the DISTINCT flag isn't consistently passed to the
Item_func_collect class.  Created MDEV-36695 to address that bug.

In spatial_utility_function_isvalid, add an alias for queries to allow the
test to pass under view protocol.
2025-04-29 09:05:23 +10:00
4c6a59f120 Merge branch '11.4' into 11.8 2025-04-28 19:10:10 +02:00
739578915f Make the test more stable. 2025-04-28 17:47:45 +02:00
63a5552e76 Merge branch '10.11' into 11.4 mariadb-11.4.6 2025-04-28 17:08:53 +02:00
cafd22db79 Code cleanup in mark_common_columns(): nj_col_2 is non-NULL here
Done after fix for MDEV-36592
mariadb-10.11.12
2025-04-28 15:58:16 +03:00
5033da6ed6 Fix rocksdb_sys_vars.rocksdb_stats_level_basic test
The minimum statistics level now is rocksdb::StatsLevel::kDisableAll.
The default remains rocksdb::StatsLevel::kExceptHistogramOrTimers
which is now 1 (it used to be 0).
2025-04-28 15:12:44 +03:00
4042652d7f Improvements to mtr
- Added option $backup_on_restart to store a backup of the var/
  directory after restart. This is useful for debugging recovery.
- The list_files option in mysqltest is now returning the number of
  found files in $sys_files. This is useful to break test if there are
  unknown or lost files in the data directory.
2025-04-28 12:59:39 +03:00