Commit graph

76458 commits

Author SHA1 Message Date
Sergei Petrunia
80067a69fe MDEV-36057: Assertion failure on 2nd execution of parameterized PS
Followup to fix for MDEV-35318: In Prepared_statement::execute_loop(),
if we enter this function with lex->needs_reprepare=true, we need to
re-prepare the statement.
We also need to call set_parameters() to get PS parameter values. We
failed to do this and that's the bug.

Note that we need to also handle the other reprepare scenario: when
we get into Prepared_statement::execute_loop(), call set_parameters()
and then hit a "DDL was changed" error with reprepare_observer,
we should NOT call set_parameters() again.
The parameters have already been transferred to the reprepared statement
in Prepared_statement::reprepare()|swap_parameter_array().
2025-02-11 18:33:44 +02:00
Sergei Golubchik
2d971709a8 MDEV-36026 Problem with INSERT SELECT on NOT NULL columns while having BEFORE UPDATE trigger
MDEV-8605 and MDEV-19761 didn't handle INSERT (columns) SELECT

followup for a69da0c31e
2025-02-10 15:26:08 +01:00
Sergei Golubchik
2b17265ae2 MDEV-35186 IGNORED attribute has no effect on vector keys 2025-02-10 12:22:05 +01:00
Sergey Vojtovich
55d1f6c229 MDEV-35069 IMPORT TABLESPACE does not work for tables with vector, although allowed
Propagate discard/import tablespace request to hlindexes.

Let FLUSH TABLES ... FOR EXPORT open/lock hlindexes, so that InnoDB
prepares hlindexes for export.

Moved reset_hlindexes() to external_lock(F_UNLCK), so that hlindexes
are available for export until UNLOCK TABLES.

Closes #3631
2025-02-10 12:22:05 +01:00
Sergei Golubchik
e240da3b19 MDEV-35146 Vector-related error messages worth improving when possible
use THD::push_warning_truncated_value_for_field() to push the
truncated warning consistently with other data types
2025-02-10 12:22:05 +01:00
Sergei Golubchik
a37eb6d013 MDEV-35792 Adding a regular index on a vector column leads to invalid table structure
don't create a prefix key for types that don't support prefix keys
2025-02-10 12:22:05 +01:00
Sergei Golubchik
a2f0234c82 MDEV-36011 Server crashes in Charset::mbminlen / Item_func_vec_fromtext::val_str upon mixing vector type with string 2025-02-06 21:47:01 +01:00
Sergei Golubchik
6fc75e0868 MDEV-35922 Server crashes in mhnsw_read_first upon using vector key with views 2025-02-06 21:47:01 +01:00
Sergei Golubchik
69041af67d only enforce innodb_force_primary_key when a table is created
not when a hlindex table is auto-discovered internally
2025-02-06 21:47:01 +01:00
Sergei Golubchik
5b8c087e84 MDEV-36005 Server crashes when checking/updating a table having vector key after enabling innodb_force_primary_key
if creating a hlindex table failed, it should not unlock
main table's plugin
2025-02-06 21:47:01 +01:00
Sergey Vojtovich
e928bf1c0e MDEV-35292 - ALTER TABLE re-creating vector key is no-op with non-copying alter algorithms (default)
ALTER TABLE didn't recognize VECTOR index options change and kept table
intact.

VECTOR indexes have their own options_struct, let ALTER TABLE use it.
2025-02-06 21:47:01 +01:00
Sergei Golubchik
c453391187 MDEV-35834 Server crash in FVector::distance_to upon concurrent SELECT
a start node in the shared context must be atomically assigned
to a valid and fully initialized node otherwise a concurrent
thread might use it before it's safe
2025-02-06 21:47:01 +01:00
Sergei Golubchik
ba01c2aaf0 Merge branch '11.4' into 11.7
* rpl.rpl_system_versioning_partitions updated for MDEV-32188
* innodb.row_size_error_log_warnings_3 changed error for MDEV-33658
  (checks are done in a different order)
2025-02-06 16:46:36 +01:00
Sergei Petrunia
14a80f0929 MDEV-35318 Assertion `tl->jtbm_subselect' failed... - PART 2
After the fix in the previous commit, we should never end up in a
situation where select_lex->first_cond_optimization=false (i.e, "it's done")
but select_lex->leaf_tables_saved==false ("not done").

So, in setup_tables(), revert the the condition added in the fix for
MDEV-25008. Add an assert instead.
2025-02-04 18:27:24 +02:00
Sergei Petrunia
0e21ff8ca4 MDEV-35318 Assertion `tl->jtbm_subselect' failed in JOIN::calc_allowed_top_level_tables
Alternative, more general fix, Variant 2.

The problem was as follows: Suppose we are running a PS/SP statement and
we get an error while doing optimization that is done once per statement
life. This may leave the statement data structures in an undefined state,
where it is not safe to execute it again.

The fix: introduce LEX::needs_reprepare and set it in such cases.
Make PS and SP runtime check it and re-prepare the statement before
executing it again.

We do not use Reprepare_observer, because it turns out it is tightly tied
to watching versions of statement's objects. For example, it must not be
used when running the statement for the first time, exactly when the
once-per-statement-lifetime optimizations are done.
2025-02-04 18:27:24 +02:00
Sergey Vojtovich
491e2b17a9 MDEV-35081 - Assertion `!n_mysql_tables_in_use' failed after error upon binary logging of DML involving vector table
InnoDB is limited to row-logging when transaction isolation level is
READ COMMITTED or READ UNCOMMITTED. This limitation is enforced by
a check within ha_innobase::external_lock().

InnoDB also expects number of "successful external locks" to match
number of "external unlocks", which is controlled by the assertion
in subject.

However "unlock" was called even after failing "lock" for high-level
indexes.

Fixed by calling "unlock" only after "successful lock".
2025-02-03 19:41:33 +01:00
ParadoxV5
697b88bf75 SHOW REPLICA STATUS: mark columns as unsigned
Update all integer columns of SHOW REPLICA STATUS (technically
INFORMATION_SCHEMA.SLAVE_STATUS) to unsigned because, well, they are (:.

Some `uint32` ones were accidentally using the `Field::store(double nr)`
overload because they forgot the `, true` for
`Field::store(longlong nr, bool unsigned_val)`.
The mistake’s harmless, fortunately, as `double` supports over 15
significant decimal digits, well over `uint32`’s 9-and-a-half.
2025-01-31 20:56:41 -07:00
ParadoxV5
aaa02f6aa3 MDEV-35693: Improve SHOW REPLICA STATUS column sizes
Resize the types and widths of SHOW REPLICA STATUS
(technically `INFORMATION_SCHEMA.SLAVE_STATUS`)
columns to better match their possible values

In case of intentionally but absurdly long lists,
text columns that list an uncapped number of elements
have expanded to accept as many bytes as we could support.

Particularly, the first-gen `Replicate_` filters were
incorrectly typed as singlular `Name()`s during MDEV-33526.
Under `Name`s’ 64-char limit, they could overflow
(read: truncate) even before their lengths got absurd.

In response to `‘MAX_SLAVE_ERRMSG’ was not declared in this scope` in
Embedded builds, a new `#ifdef HAVE_REPLICATION` guard wraps
`slave_status_info` to skip this unused data in Replication-less builds.

For testing, this commit forward-ports a modified cherry-pick of #3795
(the latter targets our oldest maintained LTS as part of MDEV-35948).

> Assert that 1st-gen `replicate_*` filter variables display
> their input – including long but reasonable lists –
> correctly (without truncation) in
> * direct SELECT
> * [semi-new] INFORMATION_SCHEMA.GLOBAL_VARIABLES.VARIABLE_VALUE
> * [new] SHOW REPLICA STATUS

Reviewed-by: Brandon Nesterenko <brandon.nesterenko@mariadb.com>
2025-01-31 20:56:41 -07:00
Sergei Golubchik
0771110266 MDEV-33658 1/2 FULLTEXT and SPATIAL keys are not "too long"
max_key_length applies only to PRIMARY/UNIQUE/MULTIPLE keys,
but not to FULLTEXT/SPATIAL/VECTOR keys.

this fixes main.partition_geometries test

followup for ecaedbe299
2025-01-30 18:48:50 +01:00
Sergei Golubchik
7d657fda64 Merge branch '10.11 into 11.4 2025-01-30 12:01:11 +01:00
Sergei Golubchik
e69f8cae1a Merge branch '10.6' into 10.11 2025-01-30 11:55:13 +01:00
Sergei Golubchik
066e8d6aea Merge branch '10.5' into 10.6 2025-01-29 11:17:38 +01:00
Sergei Golubchik
38d3b6027b MDEV-35943 ASAN errors in Query_arena::free_items / fill_schema_table_from_frm
shouldn't try to close the table if open failed.

followup for deb20fb751
2025-01-29 10:43:34 +01:00
Sergei Golubchik
03d2328785 MDEV-35944 DELETE fails to notice transaction abort, violating ACID
Process errors of read_record().

Also, add an assert that Marko requested
2025-01-29 10:43:29 +01:00
Sergei Golubchik
1fec4fc4f8 more C API methods in the service_sql
for columnstore
2025-01-28 19:31:29 +01:00
Sergei Golubchik
66cf3c6974 MDEV-35612 fix for system-versioning
only ignore fully invisible fields
2025-01-28 19:31:29 +01:00
Sergei Golubchik
9a0ac0cdf7 MDEV-35911 Assertion `marked_for_write_or_computed()' failed in bool Field_new_decimal::store_value(const my_decimal*, int*)
disable the assert.

also, use the same check for check_that_all_fields_are_given_values()
as it's used in not_null_fields_have_null_values() - to avoid
issuing the same warning twice.
2025-01-28 19:29:54 +01:00
Daniele Sciascia
0018df2b55 galera fix: Assertion WSREP(thd) failed in wsrep_restore_kill_after_commit()
Wsrep_commit_empty happens too early when wsrep is disabled. Let the
cleanup happen at end of statement.

Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
2025-01-27 19:05:27 +01:00
Daniele Sciascia
c43db43a7c MENT-2038 Assert WSREP(thd) fails in wsrep_restore_kill_after_commit
Fix wrong assertion: function wsrep_restore_kill_after_commit()
asserts `WSREP(thd)`, however for the caller (wsrep_after_statement())
it is enough that the THD  has an active transaction. Fixed the
assertion accordingly.

Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
2025-01-27 19:05:27 +01:00
Julius Goryavsky
479a5832f0 galera fix: MSAN reports use-of-uninitialized-value on binlog_encryption
This commit fixes a bug in MSAN verification in debug builds
related to the member of a lex->definer structure field that may
be uninitialized for some SET statements. The bug is caused by
debug output in a wsrep-specific insert and does not affect
server functionality.
2025-01-27 19:05:26 +01:00
Julius Goryavsky
862d1be2e6 MDEV-25718 addendum: stabilization of test success (especially for 11.4+)
Added DEBUG_SYNC_С("ha_write_row_end") in the WSREP branch,
and added a new status to the list of pending statuses in
the mtr test.
2025-01-27 19:05:26 +01:00
Hemant Dangi
c0b11e75ff MDEV-34218: Mariadb Galera cluster fails when replicating from Mysql 5.7 on use of DDL
Issue:
Mariadb Galera cluster fails to replicate from
Mysql 5.7 when configured with MASTER_USE_GTID=no
option for CHANGE MASTER.

HOST: mysql, mysql 5.7.44 binlog_format=ROW
HOST: m1, mariadb 10.6 GALERA NODE replicating from HOST mysql, Using_Gtid: No (log file and position)
HOST: m2 mariadb 10.6 GALERA NODE
HOST: m3 mariadb 10.6 GALERA NODE

Error on m1:
2024-05-22 16:11:07 1 [ERROR] WSREP: Vote 0 (success) on 78cebda7-1876-11ef-896b-8a58fca50d36:2565 is inconsistent with group. Leaving cluster.

Error on m2 and m3:
2024-05-22 16:11:06 2 [ERROR] Error in Log_event::read_log_event(): 'Found invalid event in binary log', data_len: 42, event_type: -94
2024-05-22 16:11:06 2 [ERROR] WSREP: applier could not read binlog event, seqno: 2565, len: 482

It fails in Gtid_log_event::is_valid() check on
secondary node when sequence number sent from primary
is 0. On primary for applier or slave thread sequence
number is set to 0, when both thd->variables.gtid_seq_no
and thd->variables.wsrep_gtid_seq_no have value 0.

Solution:
Skip adding Gtid Event on primary for applier or
slave thread when both thd->variables.gtid_seq_no
and thd->variables.wsrep_gtid_seq_no have value 0.

Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
2025-01-27 17:17:11 +01:00
Alexander Barkov
25b1c3505f MDEV-35677 Assertion `thd->is_error()' failed in virtual bool Field::sp_prepare_and_store_item(THD*, Item**)
The Count_handler (derived from Internal_error_handler) used in
Type_handler_datetime_common::convert_item_for_comparison()
suppressed all error codes. This caused a DBUG_ASSERT(thd->is_error())
in Field::sp_prepare_and_store_item() when the error happened
while evaluating a subselect in a scenario like this:

CREATE FUNCTION f() RETURNS INT DETERMINISTIC RETURN (SELECT a FROM t);
CREATE TABLE t (c TIMESTAMP);
SELECT * FROM t WHERE c=f();

Notice there is no such column 'a' in in the table 't'.

Fix:

Handle only DATETIME->TIMESTAMP conversion related errors in Count_handler:
- ER_TRUNCATED_WRONG_VALUE
- ER_DATETIME_FUNCTION_OVERFLOW
thus let other error kinds be processed in their usual way.

The reported scenario now returns this (expected) error:

ERROR 1054 (42S22): Unknown column 'a' in 'SELECT'
2025-01-27 16:33:09 +04:00
Galina Shalygina
dffe3d1fb2 MDEV-35910 Conditions with SP local variables are not pushed into derived table
This bug prevented building conditions that could be pushed into a derived
table if the derived table was used in a query of a stored procedure and
the conditions contained local variables of the procedure. This could lead
to a slow execution of the procedure.
Also in some cases the bug prevented building conditions that could be
pushed from the HAVING condition into the WHERE condition of a query if
the conditions to be built used local variables of a stored procedure.

To failure to build such pushable conditions was due to lack of a proper
implementation of the virtual method to copy items for the objects of the
class Item_splocal.

Approved by Igor Babaev <igor@mariadb.com>
who had to change the original fix that just added the regular copying of
the nodes of the Item_splocal class to take into account the wrappers
do_get_copy() and do_build_clone() introduced after the fix had been
prepared. He also changed the test case to demonstrate that the fix
was really needed for pushdown from HAVING into WHERE.
2025-01-26 20:42:17 -08:00
Nikita Malyavin
765458c93c fix my_error usage 2025-01-26 16:15:46 +01:00
Nikita Malyavin
e7cc1a3047 MDEV-33658 2/2 Cannot add a foreign key on a table with a matching long UNIQUE
Cannot add a foreign key on a table with a long UNIQUE multi-column index, that
contains a foreign key as a prefix.

Check that index algorithms match during the "generated" keys duplicate removal.
2025-01-26 16:15:46 +01:00
Nikita Malyavin
ecaedbe299 MDEV-33658 1/2 Refactoring: extract Key length initialization
mysql_prepare_create_table: Extract a Key initialization part that
relates to length calculation and long unique index designation.

append_system_key_parts call also moves there.

Move this initialization before the duplicate elimination.

Extract WITHOUT OVERPLAPS check into a separate function. It had to be moved
earlier in the code to preserve the order of the error checks, as in the tests.
2025-01-26 16:15:46 +01:00
Nikita Malyavin
e33064e0fc MDEV-27769 Assertion failed in Field::ptr_in_record upon UPDATE in ORACLE mode
table->move_fields has some limitations:
1. It cannot be used in cascade
2. It should always have a restoring pair

In this case, an error has occurred before the field ptr was restored, returning
from the function in that state. Even in case of an error, the table can be
reused afterwards and table->field[i]->ptr is not reset in between.

The solution is to restore the field pointers immanently whenever they've been
deviated.

Also add an assertion that ensures that table fields are restored after the use
in close_thread_tables.
2025-01-26 16:15:46 +01:00
Oleksandr Byelkin
47f87c5f88 MDEV-20281 "[ERROR] Failed to write to mysql.slow_log:" without error reason
Add "backup" (in case of absence issued by error) reasons for failed logging.
2025-01-25 20:37:51 +01:00
sjaakola
552cba92de MDEV-35710 support for threadpool
When client connections use threadpool, i.e. configuration has:
thread_handling = pool-of-threads it turned out that during wsrep
replication shutdown, not all client connections could be closed.
Reason was that some client threads has stmt_da in state DA_EOF,
and this state was earlier used to detect if client connection
was issuing SHUTDOWN command.

To fix this, the connection executing SHUTDOWN is now detected by
looking at the actual command being executed:
thd->get_command() == COM_SHUTDOWN
During replication shutdown, all other connections but the
SHUTDOWN executor, are terminated.

This commit has new mtr test galera.galera_threadpool, which
opens a number of threadpool client connections, and then
restarts the node to verify that connections in threadpool are
terminated during shutdown.

Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
2025-01-24 17:09:34 +01:00
Julius Goryavsky
50cf189717 MDEV-35018 addendum: improved warnings handling
Fixed regression after original MDEV-35018 fix related
to warnings appearing when running MDEV-26266 test and
other possible problems with warnings.
2025-01-24 17:09:21 +01:00
Daniele Sciascia
841a7d391b MDEV-35018 MDL BF-BF conflict on DROP TABLE
DROP TABLE on child and UPDATE of parent table can cause an MDL BF-BF
conflict when applied concurrently.
DROP TABLE takes MDL locks on both child and its parent table, however
it only it did not add certification keys for the parent table.
This patch adds the following:
 * Append certification keys corresponding to all parent tables
   before DROP TABLE replication.
 * Fix wsrep_append_fk_parent_table() so that it works when it is
   given a table list containing temporary tables.
 * Make sure function wsrep_append_fk_parent_table() is only called
   for local transaction. That was not the case for ALTER TABLE.
 * Add a test case that verifies that UPDATE parent depends on
   preceeding DROP TABLE child.
 * Adapt galera_ddl_fk_conflict test to work with DROP TABLE as well.

Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
2025-01-24 17:02:44 +01:00
Dmitry Shulga
73f415c955 MDEV-24935: Server crashes in Field_iterator_natural_join::next or Field_iterator_table_ref::set_field_iterator upon 2nd execution of SP
Calling a stored routine that executes a join on three or more tables
and referencing not-existent column name in the USING clause resulted in
a crash on its second invocation.

Server crash taken place by the reason of dereferencing null pointer
in condition of DBUG_ASSERT inside the method
Field_iterator_natural_join::next()
There the data member
  cur_column_ref->table_field->field
has the nullptr value that was reset at the end of first
execution of a stored routine when the standalone procedure
cleanup_items() called by the method sp_head::execute.
Later this data member is not re-initialized and never referenced
in any place except the DBUG_ASSERT on second and later invocations
of the stored routine.

To fix the issue, the assert's condition should be augmented by
a condition '|| !cur_column_ref->table_field' before dereferencing
cur_column_ref->table_field. Such extra checking is aligned with
conditions used by DBUG_ASSERT macros used by implementation of
the class Field_iterator_table_ref that aggregated the class
Field_iterator_natural_join.
2025-01-24 17:07:19 +07:00
Kristian Nielsen
72e1cc8f52 MDEV-35806: Error in read_log_event() corrupts relay log writer, crashes server
In Log_event::read_log_event(), don't use IO_CACHE::error of the relay log's
IO_CACHE to signal an error back to the caller. When reading the active
relay log, this flag is also being used by the IO thread, and setting it can
randomly cause the IO thread to wrongly detect IO error on writing and
permanently disable the relay log.

This was seen sporadically in test case rpl.rpl_from_mysql80. The read
error set by the SQL thread in the IO_CACHE would be interpreted as a
write error by the IO thread, which would cause it to throw a fatal
error and close the relay log. And this would later cause CHANGE
MASTER to try to purge a closed relay log, resulting in nullptr crash.

SQL thread is not able to parse an event read from the relay log. This
can happen like here when replicating unknown events from a MySQL master,
potentially also for other reasons.

Also fix a mistake in my_b_flush_io_cache() introduced back in 2001
(fa09f2cd7e) where my_b_flush_io_cache() could wrongly return an error set
in IO_CACHE::error, even if the flush operation itself succeeded.

Also fix another sporadic failure in rpl.rpl_from_mysql80 where the outout
of MASTER_POS_WAIT() depended on timing of SQL and IO thread.

Reviewed-by: Monty <monty@mariadb.org>
Reviewed-by: Andrei Elkin <andrei.elkin@mariadb.com>
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2025-01-24 09:15:20 +00:00
Igor Babaev
77ea99a4b5 MDEV-35869 Wrong result using degenerated subquery with window function
This bug affected queries containing degenerated single-value subqueries
with window functions. The bug led mostly to wrong results for such
queries.

A subquery is called degenerated if it is of the form (SELECT <expr>...).

For degenerated subqueries of the form (SELECT <expr>) the transformation
   (SELECT <expr>) => <expr>
usually is applied. However if <expr> contains set functions or window
functions such rewriting is not valid for an obvious reason. The code
before this patch erroneously applied the transformation when <expr>
contained window functions and did not contain set functions.

Approved by Rex Johnston <rex.johnston@mariadb.com>
2025-01-23 13:50:29 -08:00
Oleksandr Byelkin
b214ca7219 MDEV-35090 (Item_func_current_user) Assertion `typeid(*copy) == typeid(*this)' failed in Item_func_or_sum::do_build_clone
Added missing do_get_copy of Item_func_current_user.
2025-01-23 11:29:52 +01:00
Sergey Vojtovich
b730abda09 MDEV-33285 - Assertion `m_table' failed in ha_perfschema::rnd_end on CHECKSUM TABLE
CHECKSUM TABLE causes variety of crashes when killed. This bug it not
specific to PERFORMANCE_SCHEMA.

Removed duplicate handler::ha_rnd_end() call.
2025-01-22 15:28:44 +01:00
Yuchen Pei
068d061454
MDEV-34813 A simple implementation of ha_partition::compare_key_parts
It is not clear that the three Compare_key enums form a hierarchy like
alter algorithms do. So on the safe side (in case MDEV-22168 gets
implemented without looking at this code) we should return NotEqual if
partition engines do not return the same enum value. There's a static
merge function that merges these enums, but it is used to merge the
Compare_keys of different key parts (horizontally), rather than
different partitions (vertically).
2025-01-22 11:16:56 +11:00
Monty
fa74c1a40f Non partitioned table could be marked as partitioned in ddl.log
partion_engine_name was not reset when looping over tables in
mysql_rm_table_no_locks.

This could cause maria_backup to think that at normal droped
table was partitioned.

This issue was discovered in 11.8 as part of atomic created and replace
and only the fix was backported.
2025-01-21 19:21:06 +02:00
ParadoxV5
91585fff3e MDEV-35665 Potential Buffer Overrun in Gtid_log_event::write()
Two-Phase ALTER added a sa_seq_no field, but `Gtid_log_event::write()`'s
size calculation doesn't have an addend in its name.

This patch resizes the buffer to match `write()`'s code.
2025-01-21 10:17:28 -07:00