Commit graph

76,677 commits

Author SHA1 Message Date
Monty
ffb9f88fcc MDEV-38683 SIGSEGV (dbg), SIGABRT or ER_EMPTY_QUERY when using ROWS EXAMINED with log_output=TABLE
The bug was that thd->lex->limit_rows_examined_cnt was not reset after
queries. It is reset in lex_start() at the start of the next query
execution.
This causes general_log_write(), which is called before lex_start(), to
exceed the limit. The effect is a crash or the next query would not be
executed.

Fixed by resetting limit_rows_examined_cnt at end of query.
2026-02-04 14:37:36 +02:00
Sergei Golubchik
054a893f16 Merge branch '10.11' into 11.4 2026-01-31 11:45:10 +01:00
Brandon Nesterenko
3218602d31 MDEV-25039: MDL BF-BF conflict because of foreign key
Fix rpl suite tests added by MDEV-25039.

rpl_foreign_key_lock_table_insert.test is removed altogether because it
is unclear what the purpose of the test is. The changes of the patch
were done on the slave, yet all operations in the test were done on the
master. Nothing different could happen on the slave because it is
configured to be serial, so all transactions would run sequentially
anyway, and no validations were performed.

rpl_foreign_key_ddl_insert.test was renamed to
rpl_row_foreign_key_mdl.test and the test itself was re-written to be
a minimal test case to ensure that MDL locking behavior is different
pre- and post- patch. A few problems with the original test:
 * No foreign-key locking was done on the slave because the table
   engine was not InnoDB.
 * rpl_fk_ddl.inc had inconsistent validation checking. I.e., the child
   query validation checks were done on the master (which is incorrect)
   and because the slave was configured to be serial, the two
   transactions could not run concurrently on the slave anyway.
2026-01-31 11:42:12 +01:00
Hemant Dangi
d5db6c1daa MDL BF-BF conflict on ALTER and INSERT with multi-level foreign key parents
Issue:
On galera write node INSERT statements does not acquire MDL locks on it's all child
tables and thereby wsrep certification keys are also added for limited tables, but
on applier nodes it does acquire MDL locks for all child tables. This can result
into MDL BF-BF conflict on applier node when transactions referring to parent and
child tables are executed concurrently. For example:

Tables with foreign keys: t1<-t2<-t3<-t4
Conflicting transactions: INSERT t1 and DROP TABLE t4

Wsrep certification keys taken on write node:
- for INSERT t1: t1 and t2
- for DROP TABLE t4: t4

On applier node MDL BF-BF conflict happened between two transaction because
MDL locks on t1, t2, t3 and t4 were taken for INSERT t1, which conflicted
with MDL lock on t4 taken by DROP TABLE t4.
The Wsrep certification keys helps in resolving this MDL BF-BF conflict by
prioritizing and scheduling concurrent transactions. But to generate Wsrep
certification keys it needs to open and take MDL locks on all the child tables.

On applier nodes Write_rows event is implicitly a REPLACE, deleting all conflicting
rows which can cause cascading FK actions and locks on foreign key children tables.

Solution:
For Galera applier nodes the Write_rows event is considered pure INSERT
which will never cause cascading FK actions and locks on foreign key children tables.
2026-01-31 11:42:12 +01:00
Sergei Golubchik
4802bfe4f9 MDEV-38710 Assertion is_lock_owner on error returning from auto-create in mysql_admin_table
don't auto-add new partitions if we're already at TIMESTAMP_MAX_VALUE
2026-01-31 11:42:12 +01:00
Sergei Golubchik
40f7084661 Merge branch '10.11' into 11.4 2026-01-28 21:52:18 +01:00
Sergei Golubchik
b29d3779e4 Merge branch '10.6' into 10.11 2026-01-28 14:22:20 +01:00
Yuchen Pei
8070033e47
MDEV-36230 Fix SERVER port field bound check
The Port field in the system table mysql.servers has type INT,
which translates to Field_long.

During parsing it is parsed as ulong_num, and in this patch we add
bound checks there.
2026-01-28 16:23:05 +11:00
bsrikanth-mariadb
6f2a99589b MDEV-35815: use-after-poison_in_get_hash_symbol
In find_field_in_view(), we call field_it.create_item() which
creates item on a statement mem_root.
Then we set its name. Make sure the name is allocated on a statement
mem_root, too.
2026-01-27 22:17:41 +02:00
Aleksey Midenkov
eba938f9eb MDEV-37275 Cannot remove default value of NOT NULL column
Run-time has semantics duplication in unireg_check, default_value and
flags, so all three must be in sync before FRM creation. Special
unireg_check values for temporal field types was introduced by
32b28f9298 WL#1266 "Separate auto-set logic from TIMESTAMP type."
2026-01-27 19:02:16 +03:00
Aleksey Midenkov
8906e6a214 MDEV-32317 ref_ptrs exhaust on multiple ORDER by func from winfunc
Each ORDER and WHERE slot may generate split, see code like this:

  if ((item->with_sum_func() && item->type() != Item::SUM_FUNC_ITEM) ||
    item->with_window_func())
  item->split_sum_func(thd, ref_ptrs, all_fields, SPLIT_SUM_SELECT);

Such kind of code is done in JOIN::prepare(), setup_order(),
setup_fields(), setup_group() and split_sum_func2() itself.

Since we are at the phase of ref_ptrs allocation, items are not fixed
yet and we cannot calculate precisely how much ref_ptrs is needed. We
can estimate at most how much is needed. In the worst case each window
function generates split on each ORDER BY field, GROUP BY field and
WHERE field, so the counts of these should be multiplied by window
funcs count.

As the split can be done in both setup_without_group() and
JOIN::prepare() simultaneously, the factor of window funcs should be
multiplied by 2.

The similar case may be with inner sumfunc items as of the condition

  item->with_sum_func() && item->type() != Item::SUM_FUNC_ITEM

but factor of these is harder to predict at the stage of unfixed
items.
2026-01-27 16:19:46 +01:00
bsrikanth-mariadb
dc28140c89 MDEV-31255: Crash with fulltext search subquery in explain delete/update
ft_handler isn't getting initialized for subqueries inside explain
delete/update queries. However, ft_handler is accessed inside ha_ft_read(),
and is the reason for NULL pointer exception.
This is not the case with non-explain delete/update queries, as
well as explain/non-explain select queries.

Follow the approach the SELECT statements are using in
JOIN::optimize_constant_subqueries(): remove SELECT_DESCRIBE
flag when invoking optimization of constant subqueries.

Single-table UPDATE/DELETEs have SELECT_LEX but don't have JOIN.
So, we make optimize_constant_subqueries() not to be a member
of JOIN class, and instead move it to SELECT_LEX, and then
invoke it from single-table UPDATE/DELETE as well as for SELECT queries.
2026-01-27 16:42:41 +05:30
Thirunarayanan Balathandayuthapani
5b6ad325d2 MDEV-38667 Assertion in diagnostics area on DDL stats timeout
Reason:
======
 During InnoDB DDL, statistics updation fails due to lock wait
timeout and calls push_warning_printf() to generate warnings
but then returns success, causing the SQL layer
to attempt calling set_ok_status() when the diagnostics area
is already set.

Solution:
=========
By temporarily setting abort_on_warning to false around operations
that prevents warning to error escalation and restore the original
setting after calling HA_EXTRA_END_ALTER_COPY for alter operation.
2026-01-27 13:51:32 +05:30
Sergei Golubchik
12578d8a69 MDEV-38604 fix SP execution too 2026-01-26 23:15:34 +01:00
Rucha Deodhar
ca39e66060 MDEV-38620: Server crashes in setup_returning_fields upon 2nd execution
of multi-table-styled DELETE from a view

Analysis:
The item_list of builtin_select stores the fields that are there in the
RETURNING clause.
During the "EXECUTE" command, a "dummy item" is added into the item_list
of the select_lex(builtin_select) representing DELETE during
Sql_cmd_delete::precheck(). This snippet that adds a dummy item is added
because columnstore needs for temporary table. Results are put into a
temporary table and to create a temporary table we need to know what
columns are there which we get from the select_lex->item_list.
As a result, the item_list now has an item even when there is not really
RETURNING clause, resulting in execution of the setup_returning_fields()
when it should have exited already.

Fix:
Instead of checking whether builint_select's item_list is empty to
determine whether there is RETURNING clause, use a flag.
2026-01-26 23:32:38 +05:30
Yuchen Pei
2c2a418591 MDEV-38327 Do not use rowid filter in ref_to_range when the range method is index merge
Index merge and rowid filter should not be used together, however,
even if index merge is not chosen earlier in best_access_path, it may
be chosen again in make_join_select, inside ref_to_range. Therefore
this patch ensures that rowid filter is not used when index merge is
chosen there.
2026-01-26 14:50:23 +02:00
Yuchen Pei
6229192647 MDEV-38327 Minor optimizer comment cleanups and refactoring
factor out common index merge checks of quick select types
2026-01-26 14:50:23 +02:00
Sergei Golubchik
c0acc3cc8f MDEV-38209 REFERENCES permission on particular schema is sometimes ignored
some I_S tables require "any non-SELECT privilege on the table".
If only SELECT was granted on the global level and something non-SELECT
on the schema level, then we need to check schema level privileges
explicitly, because check_grant() doesn't do that and get_all_tables()
doesn't look deeper if SELECT is present on the global level.
2026-01-26 10:01:31 +01:00
Sergei Golubchik
7b9d3a4df6 MDEV-38654 Assertion `str[strlen(str)-1] != '\n'' failed upon federated discovery error
relax the assert, allowing '\n' at the end if the string is exactly
MYSQL_ERRMSG_SIZE-1 bytes long. It likely doesn't end with '\n' but
was truncated at the middle.

also, use MYSQL_ERRMSG_SIZE in my_error.c not a separate define
that must be "kept in sync"
2026-01-26 10:01:31 +01:00
Sergei Golubchik
d7702e0b0f MDEV-37481 empty value inserted if BEFORE trigger and ENUM NOT NULL field
must use field->make_empty_rec_reset() for resetting a field
to its type default value. ENUM is historically weird.
2026-01-26 10:01:31 +01:00
Sergei Golubchik
387de3d5b8 cleanup: remove unused argument 2026-01-26 10:01:31 +01:00
Sergei Golubchik
ac49387199 MDEV-37506 Assertion if FLUSH PRIVILEGES is interrupted in --skip-grant-tables
* fail acl_load() if it was killed, this will cause all privileges to
  be reset to their original pre-load values.
* only increment grant_version if privileges were, in fact, updated
2026-01-26 10:01:31 +01:00
Sergei Golubchik
71d4cae866 MDEV-37503 UBSAN: downcast Item_func_plus to Item_field invalid in sql_prepare.cc:1516
use reinterpret_cast to silence UBSAN.
add a debug check to make sure the wrong value is never used.
2026-01-26 10:01:31 +01:00
Sergei Golubchik
7e14749d96 MDEV-37341 Assertion failures null_ptr < ptr' and ptr - null_ptr <= (int)table->s->rec_buff_length' with BEFORE trigger and UPDATE
in SIMULTANEOUS_ASSIGNMENT there is no need to switch value items
to new nullable copies of table Field's - they must refer to old
values in the row, which can never be null anyway.

skipping this redundant step simplifies moving field to record[1]
and back in fill_record()
2026-01-26 10:01:31 +01:00
Sergei Golubchik
b930eef317 MDEV-37326 Assertion failure upon update on versioned partitioned table with long unique under READ COMMITTED
if ha_partition::position() is asked for a position of a closed partition,
don't ask the underlying engine, just set the partition number.

in fact, the partition is open and can be perfectly used, the assert
is over-zealous. but in the future it might be actually closed.
2026-01-26 10:01:31 +01:00
Sergei Golubchik
387fe5ecc3 MDEV-36787 Error 153: No savepoint with that name upon ROLLBACK TO SAVEPOINT, assertion failure
1. InnoDB should return HA_ERR_ROLLBACK if it aborts a transaction internally
2. the server should recognize it and perform an automatic rollback
2026-01-26 10:01:31 +01:00
Aleksey Midenkov
b68f878fdc MDEV-36876 Crash during the Item_subselect::init - outer_select is NULL
Comparison between vector and scalar is invalid (ER_OPERAND_COLUMNS)
and handled by the parser. The problem is outer_context is missing
because relink_hack() cannot recover it due to
!builtin_select.first_inner_unit() condition. This condition was set
by previous relink hack called for previous expression some(select 1).

Since there can be arbitrary number of such expressions there seems to
be no point in such a limitation. MTR test do not fail without that
condition, so the fix proposes to remove it.
2026-01-23 14:48:57 +03:00
Aleksey Midenkov
6fcd87ba4d MDEV-33985 Server crashes at Item_func_nextval::val_int
Pure aliases are not handled properly by Item_func_nextval::val_int().

add_table_to_list() does not create MDL request for pure aliases,
i.e. when there is no table_list->db set or TL_OPTION_ALIAS was
set. When the expression is not inside CTE the case with empty db is
handled by:

  else if (!lex->with_cte_resolution && lex->copy_db_to(&db))
    DBUG_RETURN(0);

So, table_list gets current database name and the query is failed with
ER_NO_SUCH_TABLE error.

The fix adds the case of is_pure_alias() for
Item_func_nextval::val_int() and fails it with ER_NOT_SEQUENCE2 error.

Note: semantics for TL_OPTION_ALIAS cannot be based on empty db, only
parser can set TL_OPTION_ALIAS as resolve_references_to_cte() relies
on TL_OPTION_ALIAS after copy_db_to().
2026-01-23 14:48:24 +03:00
Aleksey Midenkov
5597f877fe MDEV-33289 INTERVAL partitioning by system time does not work close to the end of timestamp range
1. Fix empty part_elem->id in prep_alter_part_table().

   On auto-create newly added partition has id 0. It came from
   set_up_default_partitions() for new part_info
   (thd->work_part_info). vers_update_el_ids() can work only with
   unassigned ids (UINT_MAX32), so we assign it explicitly on pushing
   into tab_part_info.

2. If range value is out of TIMESTAMP_MAX_VALUE set it to
   TIMESTAMP_MAX_VALUE, but only if the history partition is the last
   one, otherwise push ER_DATA_OUT_OF_RANGE. Error is to create
   multiple out-of-range partitions (e.g. with PARTITIONS clause in
   CREATE TABLE).
2026-01-23 14:42:25 +03:00
Aleksey Midenkov
3b07a44a23 MDEV-32724 Segmentation fault due to Deep Recursion in table.cc and sql_lex.cc
Recursive CTE wrongly detected anchor because inner non-recursive CTE
wrongly assigned with-element table to itself due to inner-outer name
clash.
2026-01-23 14:40:42 +03:00
Aleksey Midenkov
7a88776dc1 MDEV-28650 Server crashes in Item_func_nextval::val_int after select from view
default_used was missing as view is parsed on its own
lex. extend_table_list() decides maybe_need_prelocking based on
default_used and prelocking_strategy->handle_table() was skipped for
view, so internal_tables was not updated (they could be stale from
previous statement).
2026-01-23 14:25:06 +03:00
Sergei Golubchik
cb31d7536b MDEV-38604 Assertion `thd->utime_after_query >= thd->utime_after_lock' failed in query_response_time_audit_notify on 2nd execution of SP with query cache
even when PS is served from a query cache, thd->utime_after_query
must be updated.

also, backport the assert from 11.8
2026-01-23 12:15:34 +01:00
Rex Johnston
b061b5ab1f MDEV-31632 Unresolvable outer reference causes null pointer exception
SELECT 1 union select 2 UNION SELECT 1 from a JOIN a b ON
  (SELECT 1 FROM dual WHERE AAA)

Crashes during fix_outer_field while resolving field item AAA

In our resolver, once we have determined that a field item isn't
local to our select, we call Item::fix_outer_field(), which
iterates outwards towards the top level select, looking for where
our Item_field might be resolvable.

In our example here, the item isn't resolvable and we expose
fragility in the loop, which i will detail here.

After we initialize the variable 'outer_context' (to a context
containing /* select#3 */ select 1 AS `1` from (a join a b on
((subquery#4))) ) we enter a loop

│     5927   for (;
│     5928        outer_context;
│     5929        outer_context= outer_context->outer_context)
│     5930   {
│     5931     select= outer_context->select_lex;
│     5932     Item_subselect *prev_subselect_item=
│     5933       last_checked_context->select_lex->master_unit()->item;
│     5934     last_checked_context= outer_context;

here 'last_checked_context' is the context inner to the current
'outer_context', and we initialize prev_subselect_item to the
Item enclosing the unit containing this inner select.

So for the first iteration of the loop,
  select: select #3
  last_checked_context: from select #4 to select #3.
  prev_subselect_item: item enclosing select #4 (where
    field item AAA is defined)

The rest of the loop calls find_field_in_tables() /
resolve_ref_in_select_and_group() in an attempt to
resolve this item with this 'outer_context'.

After the item fails resolution, we move to an outer context
  select: select #4294967295 (fake_select_lex)
  last_checked_context: from select #3 to the fake select lex
    containing the union (i.e. outermost)
  prev_subselect_item: null, there is no Item that contains this,
    it is the outermost select.

We still need to execute the rest of the loop to determine whether
AAA is resolvable here, but executing

│     5937     place= prev_subselect_item->parsing_place;

We are now following a null pointer.  We introduce a test for this
null pointer, indicating that we are now evaluating the outermost
select and we are not to try accessing the enclosing subselect item.

Approved by: Oleksandr "Sanja" Byelkin (sanja@mariadb.com)
2026-01-23 07:48:16 +13:00
bsrikanth-mariadb
be4e1ecdc2 MDEV-37510: crash when tracing with max_sel_arg_weight equal to 1
When the optimizer_max_sel_arg_weight is set to 1, a nested query
crashed while tracing.

SEL_ARG object has a field named 'field', that is not set when the
type is other than KEY_RANGE. But, the field was accessed to store
its name, and weight to the trace. This resulted in a crash due to NULL
pointer.

Added a check to access field if the type is KEY_RANGE, and if not, just
trace the type.
2026-01-22 17:57:50 +05:30
Oleg Smirnov
cd02709a31 MDEV-38574 Rename cloning functions of class Item and descendants
Rename `Item::clone_item()` to `clone_constant()`, and do
the same for any overloads in descendant items.
The function returns non-NULL only for items that represent
constant literals.
2026-01-22 12:57:48 +01:00
Oleg Smirnov
f2b48e565c MDEV-38574 Rename cloning functions of class Item and descendants
Rename cloning methods of class Item and its descendants
in the following way:

   (from)            (to)
do_build_clone  -> deep_copy
   build_clone  -> deep_copy_with_checks

do_get_copy  -> shallow_copy
   get_copy  -> shallow_copy_with_checks

to better reflect their functionality.

Also make Item::deep_copy() and shallow_copy() protected.
Outside users should call deep_copy_with_checks()
and shallow_copy_with_checks().
2026-01-22 12:57:48 +01:00
bsrikanth-mariadb
251f76d39e MDEV-36353: Crash with explain for connection
SHOW EXPLAIN FOR, and EXPLAIN/DESC FOR CONNECTION should behave
identically. However, for a query with an addition expression containing
INTERVAL and NOT IN sub-select SHOW EXPLAIN FOR was correctly throwing
parse error, where as EXPLAIN/DESC FOR CONNECTION was crashing.

The reason for the crash is that select block was not initialized and
was being accessed inside the NOT IN sub-select in the EXPLAIN/DESC FOR
CONNECTION case.
2026-01-22 16:20:33 +05:30
Alexander Barkov
a84b8ec5b1 MDEV-38626 Unexpected Data too long error on subselect as a multiplication argument
Item_singerow_subselect::fix_length_and_dec() incorrectly calculated
its Item::max_length when the underlying expression was Item_int.

The reason of the problem:
Item_int has an optimized max_length to make CONCAT(1) create a VARCHAR(1)
column rather than a VARCHAR(2) column. Its max_length does not include one
extra character for the sign in case the value is positive but the value
is not marked as Item::unsigned==true.

So copying max_length from the underlying Item_int (with value==9)
in cases like this:
  SELECT CONCAT((SELECT 9 FROM t0));
was not correct.

Implementing a new virtual method
  Type_handler::Item_type_std_attributes_generic(const Item *item)

- The default implementation just copies attributes from "item" as is.

- In case of Type_handler_int_result it evaluates max_length
  using item->decimal_precision() rather than item->max_length.
  This works correctly for both "optimized" items like Item_int and
  non-"optimized" Items whose max_length includes +1 for the sign
  in case of signed expressions.
2026-01-22 12:47:52 +04:00
Raghunandan Bhat
16b5bf03d7 MDEV-37474: Privilege check of information_schema.TRIGGERS does not correspond to the standards
According to SQL standard, rows from `INFORMATION_SCHEMA.TRIGGERS` table
should be visible to users with non-SELECT privileges on the columns.
`ACTION_CONDITION`, `ACTION_STATEMENT` and `DEFINER` columns should be
visible only if the user is the owner of the schema.
MariaDB uses `TRIGGER` privilege instead of owner, which controls the
visibilty of all columns, including those which only need non-SELECT
privileges.

This fix
- Allows users with non-SELECT privileges- INSERT, DELETE or UPDATE,
  to see rows in `INFORMATION_SCHEMA.TRIGGERS` table.
- Ensure `ACTION_CONDITION`, `ACTION_STATEMENT` and `DEFINER` columns
  are `NULL` unless the user is the owner of the schema or has `TRIGGER`
  privilege.
2026-01-22 10:43:18 +05:30
Brandon Nesterenko
11f228cbb2 MDEV-38506: Failed GRANT on a procedure breaks replication
When GRANT EXECUTE ON PROCEDURE fails on the master, it will
erroneously be replicated and executed successfully on the slave.
This both breaks replication and is a security violation.

The underlying issue is that a failed GRANT EXECUTE ON PROCEDURE will
still be replicated when sql_mode does not have NO_AUTO_CREATE_USER.
This is because the function mysql_routine_grant() does not check if an
error occured while performing the GRANT before binlogging, it simply
always binlogs.

This patch fixes this problem by checking if an error happened
previously before binlogging, and if so, then skip binlogging.

Note there is still a broader issue in this area leading to replication
divergence. Reported in MDEV-29848, a partially-completed GRANT
statment (where some earlier GRANTS succeed and a later fails) will not
binlog. Note this affects all grant types, whereas the issue addressed
in this patch is limited to GRANT EXECUTE ON PROCEDURE. This patch
makes GRANT EXECUTE ON PROCEDURE binlogging behavior consistent with
the other grant types. A separate follow-up patch will address the
broader MDEV-29848 issue.

Also note that a test case in rpl_do_grant.test took advantage of
MDEV-38506 so a partially-failing REVOKE EXECUTE ON PROCEDURE would
still replicate.  This test case is disabled with a TODO note to
re-enable it once MDEV-29848 is fixed

Reviewed-by: Sergei Golubchik <serg@mariadb.org>
Signed-off-by: Brandon Nesterenko <brandon.nesterenko@mariadb.com>
2026-01-21 14:31:21 -07:00
Rex Johnston
6a32ccc5b9 MDEV-38473 Incorrect Empty Set with HAVING clause when SELECT and GROUP BY use different aliases for the same column
MDEV-29300 fix causes a wrong result by incorrectly removing a wrapper to
an item that needed to be wrapped for the correct result.  Direct access
to the item causes an incorrect table reference to be used during
join evaluation.  We revert that fix.

Our original problem query is this
SELECT (SELECT 0 GROUP BY c1 HAVING (SELECT c1)) FROM t1 group by c1;

JOIN::prepare on
/* select#2 */ select 0 group by t1.c1 having (subquery#3)

fixing t1.c1 in group by clause, calls fix_outer_field()
this item is resolved in an outer select (#1) and it is a grouping select,
so we wrap it in Item_outer_ref and set this item to unfixed for later
fixing in fix_inner_refs().

JOIN::prepare continues onto the having clause and fixes (subquery#3) which
calls initiates the prepare series of calls, leading to setup_fields on the
fields in this JOIN, one of which is an outer reference c1.
This is resolved to the item in the next most outer select in the group by
clause. This item has been wrapped with an unfixed Item_outer_ref.
It is found in resolve_ref_in_select_and_group() is it expected that
this item will have already been fixed, hence this call in

Item_field::fix_outer_field()

DBUG_ASSERT(*ref && (*ref)->fixed());

but as explained above, it isn't fixed and debug builds assert here.

Because this wrapper cannot be resolved here for reasons detailed in
fix_inner_refs, and we cannot remove this wrapper without potentially
returning an incorrect result, we have to relax this assertion.

Approved by: Oleksandr "Sanja" Byelkin (sanja@mariadb.com)
2026-01-22 07:21:12 +13:00
Jan Lindström
48d08d6e99 MDEV-38558 : MariaDB does not support writes during MySQL --> MariaDB migration
When MariaDB node has joined to MySQL Galera cluster if any writes
to existing tables are done cluster requests to use protocol
version 7 (max protocol version used by MySQL Galera cluster).
MariaDB had support to protocol version up to 4. While writeset
keys are prepared allow using protocol version 7, it has no
effect on writeset key format i.e. protocol version 4 and 7
are identical on that case.

Note that there is no mtr test case because currently there is no
way to test both MySQL and MariaDB in mtr.
2026-01-21 12:41:26 +02:00
Oleksandr Byelkin
8575b07f11 MDEV-35288 Assertion `!is_cond()' failed in virtual longlong Item_bool_func::val_int()
Boolean function now uses val_bool to get string result (val_str())
2026-01-20 16:58:08 +01:00
Vladislav Vaintroub
52b1d7eb7f libfmt 12.1 - Suppress warning, MSVC-specific
discarding return value of function with [[nodiscard]] attribute
for std::isalpha

This comes from libfmt templated code
2026-01-20 15:41:19 +01:00
Raghunandan Bhat
a8471426f4 MDEV-38487: Prevent aggregate function cloning when pushing HAVING into WHERE
Problem:
  When building a pushable condition that can be pushed from HAVING into
  WHERE, the server tries to clone aggregate functions. This is not
  necessary because aggregate functions can not be pushed into WHERE
  anyway.

Fix:
  This fix introduces a check within `Item::build_pushable_cond` to skip
  cloning aggregate functions.

Also fixes assert failure in MDEV-38492, by adding a missing copy method
for `Item_aggregate_ref`.
2026-01-20 09:46:35 +01:00
Jan Lindström
e40277d29b MDEV-38218 : Galera test failure on galera_bf_abort_flush_for_export
Problem was in wsrep_handle_mdl_conflict function was comparing
thd->lex->sql_command variable for granted MDL-lock.

There is two possible schedules:

    (1) FLUSH TABLES ... FOR EXPORT that will take MDL-lock (granted_thd).
        INSERT from other node is conflicting operation (request_thd)
        and sees MDL-conflict. Because granted_thd has not executed anything
        else thd->lex->sql_command == SQLCOM_FLUSH and this case was
        correctly handled in wsrep_handle_mdl_conflict i.e. INSERT needs
        to wait.

    (2) FLUSH TABLES ... FOR EXPORT that will take MDL-lock (granted_thd).
        SET SESSION wsrep_sync_wait=0; (granted_thd)
        INSERT from other node is conflicting operation (request_thd)

        However, thd->lex->sql_command is not stored to taken MDL-lock. Now
        as granted_thd is executing SET thd->lex->sql_command != SQLCOM_FLUSH
        and INSERT that is BF will abort it and that means also FTFE is
        killed and MDL-lock relesed. This is incorrect as FTFE has written
        file on filesystem and it can't be really killed.

In this fix wsrep_handle_mdl_conflict is refactored not to use
thd->lex->sql_command as a variable used for decisions. Instead
connection state can be determined also via THD members. E.g.:

    * wsrep_thd_is_toi() || wsrep_thd_is_applying - ongoing TOI or applier
    * wsrep_thd_is_BF - thread is brute force
    * wsrep_thd_is_SR - thread is streaming replication thread
    * thd->current_backup_stage != BACKUP_FINISHED - there's ongoing BACKUP
    * thd->global_read_lock.is_acquired() - ongoing FTWRL
    * thd->locked_tables_mode == LTM_LOCK_TABLES - ongoing FTFE or LOCK TABLES
2026-01-20 10:23:44 +02:00
Rucha Deodhar
8c6ebbacce MDEV-25148: Unexpected success and result set upon erroneous JSON_VALUE call
Analysis:
When scanning json and reaching a path, the path type is
JSON_PATH_ARRAY_WILD. So it should not return any value. But the code
does not check that.

Fix:
Use path_setup_nwc() to check for range queries because json_value() should
not accept range queries.
2026-01-18 20:14:53 +05:30
Kristian Nielsen
13aad4ed2b MDEV-20586: Incorrect commit of transaction in GTID table processing
The initial scanning of the GTID pos table in find_gtid_pos_tables_cb() used
the wrong call to commit the transaction, ha_commit_trans(thd, TRUE) instead
of trans_commit(thd). This could cause an assertion
  Assertion '!thd->in_active_multi_stmt_transaction() || thd->in_multi_stmt_transaction_mode()' failed in mysql_execute_command
and possibly other issues due to incorrect state in the SQL thread THD.

Similar problem in rpl_slave_state::truncate_state_table() also fixed.

Note there is a sister patch cd88b0831f
which applied this same pattern which fixed a hang due to locks
not being released in the ha_commit_trans(thd, TRUE) call.

Test-case-by: Alice Sherepa <alice.sherepa@gmail.com>
Reviewed-by: Brandon Nesterenko <brandon.nesterenko@mariadb.com>
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2026-01-15 16:19:34 -07:00
Sergei Golubchik
d12a5333fd MDEV-37888 unexpected type changing after changing AVG to MAX
set collation for AVG, like it's done for MAX
2026-01-14 19:44:54 +01:00
Sergei Golubchik
2c983b5ebb MDEV-38006 Inconsistent behaviors when casting into time
number-to-time conversion was too eagerly capping the value.

A string "9000090" was invalid time, because of 90 seconds.
But number-to-time was capping first, validating later,
to 9000090->time worked. Let's fix it.

also, let's make invalid time values in a string field include
the field name in the warning message, just like invalid time
values in a numeric field do.
2026-01-14 19:44:54 +01:00