Skip to content

Commit

Permalink
Merge 10.6 into 10.7
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed Mar 15, 2022
2 parents de4ec44 + 4ef44cc commit dc4b7f3
Show file tree
Hide file tree
Showing 16 changed files with 245 additions and 54 deletions.
2 changes: 1 addition & 1 deletion mysql-test/lib/mtr_cases.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ sub get_tags_from_file($$) {
}

# Check for a sourced include file.
if ($line =~ /^(--)?[[:space:]]*source[[:space:]]+([^;[:space:]]+)/)
if ($line =~ /^[[:space:]]*(--)?[[:space:]]*source[[:space:]]+([^;[:space:]]+)/)
{
my $include= $2;
# The rules below must match open_file() function of mysqltest.cc
Expand Down
24 changes: 24 additions & 0 deletions mysql-test/main/sql_safe_updates.result
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
#
# MDEV-14429 sql_safe_updates in my.cnf not work
#
select @@sql_safe_updates;
@@sql_safe_updates
1
#
# MDEV-18304 sql_safe_updates does not work with OR clauses
#
create table t1 (a int, b int, primary key (a), key (b));
update t1 set b=2 where a=1 or b=2;
ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
explain update t1 set b=2 where a=1 or b=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 1 Using where
delete from t1 where a=1 or b=2;
ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
explain delete from t1 where a=1 or b=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 1 Using where
insert into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8);
update t1 set b=2 where a=1 or b=2;
delete from t1 where a=1 or b=2;
drop table t1;
#
# End of 10.3 tests
#
25 changes: 22 additions & 3 deletions mysql-test/main/sql_safe_updates.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
#
# MDEV-14429 sql_safe_updates in my.cnf not work
#
--echo #
--echo # MDEV-14429 sql_safe_updates in my.cnf not work
--echo #
select @@sql_safe_updates;

--echo #
--echo # MDEV-18304 sql_safe_updates does not work with OR clauses
--echo #
create table t1 (a int, b int, primary key (a), key (b));
--error ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE
update t1 set b=2 where a=1 or b=2;
explain update t1 set b=2 where a=1 or b=2;
--error ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE
delete from t1 where a=1 or b=2;
explain delete from t1 where a=1 or b=2;
insert into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8);
update t1 set b=2 where a=1 or b=2;
delete from t1 where a=1 or b=2;
drop table t1;

--echo #
--echo # End of 10.3 tests
--echo #
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
========= Set server_id to 99 and prepare test table.
SET GLOBAL server_id= 99;
CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb;
========= Crash the server.
SET SESSION debug_dbug="+d,crash_commit_after_log";
INSERT INTO t1 VALUES (1, NULL);
Got one of the listed errors
========= Restart the server with default config file in which server_id= 1.
========= Check that recover succeeds and server is up.
connection default;
========= Check that all transactions are recovered.
SELECT a FROM t1 ORDER BY a;
a
1
========= Cleanup.
connection default;
DROP TABLE t1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This test verifies attempt to xa recover using a new server id that
# different from the transaction's original server_id.
#

--source include/have_innodb.inc
--source include/have_debug.inc
--source include/have_binlog_format_row.inc
# Valgrind does not work well with test that crashes the server
--source include/not_valgrind.inc


--echo ========= Set server_id to 99 and prepare test table.
SET GLOBAL server_id= 99;
CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb;


--echo ========= Crash the server.
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait-binlog_xa_recover_using_new_server_id.test
EOF
SET SESSION debug_dbug="+d,crash_commit_after_log";
--error 2006,2013
INSERT INTO t1 VALUES (1, NULL);


--echo ========= Restart the server with default config file in which server_id= 1.
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart-binlog_xa_recover_using_new_server_id.test
EOF


--echo ========= Check that recover succeeds and server is up.
connection default;
--enable_reconnect
--source include/wait_until_connected_again.inc


--echo ========= Check that all transactions are recovered.
SELECT a FROM t1 ORDER BY a;


--echo ========= Cleanup.
connection default;
DROP TABLE t1;
9 changes: 9 additions & 0 deletions mysql-test/suite/innodb/r/instant_alter_bugs.result
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,13 @@ ALTER TABLE t ADD d INT;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
DROP TABLE t;
#
# MDEV-28060 Online DDL fails while checking for instant
# alter condition
#
CREATE TABLE t1(f1 CHAR(10) NOT NULL)ROW_FORMAT=REDUNDANT,ENGINE=InnoDB;
ALTER TABLE t1 ADD COLUMN(f2 INT NOT NULL, f3 INT NOT NULL,
f4 INT NOT NULL, f5 INT NOT NULL),
CHANGE COLUMN f1 f1 CHAR(10) DEFAULT NULL;
DROP TABLE t1;
SET GLOBAL innodb_purge_rseg_truncate_frequency=@save_frequency;
2 changes: 2 additions & 0 deletions mysql-test/suite/innodb/r/undo_truncate.result
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ connection con2;
commit;
disconnect con2;
connection default;
SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
SET GLOBAL innodb_max_purge_lag_wait=0;
set global innodb_fast_shutdown=0;
# restart
drop table t1, t2;
9 changes: 9 additions & 0 deletions mysql-test/suite/innodb/t/instant_alter_bugs.test
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,13 @@ ALTER TABLE t ADD d INT;
--disable_info
DROP TABLE t;

--echo #
--echo # MDEV-28060 Online DDL fails while checking for instant
--echo # alter condition
--echo #
CREATE TABLE t1(f1 CHAR(10) NOT NULL)ROW_FORMAT=REDUNDANT,ENGINE=InnoDB;
ALTER TABLE t1 ADD COLUMN(f2 INT NOT NULL, f3 INT NOT NULL,
f4 INT NOT NULL, f5 INT NOT NULL),
CHANGE COLUMN f1 f1 CHAR(10) DEFAULT NULL;
DROP TABLE t1;
SET GLOBAL innodb_purge_rseg_truncate_frequency=@save_frequency;
2 changes: 2 additions & 0 deletions mysql-test/suite/innodb/t/undo_truncate.test
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ connection default;
let $trx_before= `SHOW ENGINE INNODB STATUS`;
let $trx_before= `select substr('$trx_before',9)+2`;

SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
SET GLOBAL innodb_max_purge_lag_wait=0;
set global innodb_fast_shutdown=0;
--source include/restart_mysqld.inc
--replace_regex /.*Trx id counter ([0-9]+).*/\1/
Expand Down
19 changes: 12 additions & 7 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2411,7 +2411,7 @@ struct xarecover_st
*/
static xid_recovery_member*
xid_member_insert(HASH *hash_arg, my_xid xid_arg, MEM_ROOT *ptr_mem_root,
XID *full_xid_arg)
XID *full_xid_arg, decltype(::server_id) server_id_arg)
{
xid_recovery_member *member= (xid_recovery_member *)
alloc_root(ptr_mem_root, sizeof(xid_recovery_member));
Expand All @@ -2425,7 +2425,7 @@ xid_member_insert(HASH *hash_arg, my_xid xid_arg, MEM_ROOT *ptr_mem_root,

if (full_xid_arg)
*xid_full= *full_xid_arg;
*member= xid_recovery_member(xid_arg, 1, false, xid_full);
*member= xid_recovery_member(xid_arg, 1, false, xid_full, server_id_arg);

return
my_hash_insert(hash_arg, (uchar*) member) ? NULL : member;
Expand All @@ -2440,14 +2440,15 @@ xid_member_insert(HASH *hash_arg, my_xid xid_arg, MEM_ROOT *ptr_mem_root,
*/
static bool xid_member_replace(HASH *hash_arg, my_xid xid_arg,
MEM_ROOT *ptr_mem_root,
XID *full_xid_arg)
XID *full_xid_arg,
decltype(::server_id) server_id_arg)
{
xid_recovery_member* member;
if ((member= (xid_recovery_member *)
my_hash_search(hash_arg, (uchar *)& xid_arg, sizeof(xid_arg))))
member->in_engine_prepare++;
else
member= xid_member_insert(hash_arg, xid_arg, ptr_mem_root, full_xid_arg);
member= xid_member_insert(hash_arg, xid_arg, ptr_mem_root, full_xid_arg, server_id_arg);

return member == NULL;
}
Expand Down Expand Up @@ -2499,7 +2500,8 @@ static void xarecover_do_commit_or_rollback(handlerton *hton,
Binlog_offset *ptr_commit_max= arg->binlog_coord;

if (!member->full_xid)
x.set(member->xid);
// Populate xid using the server_id from original transaction
x.set(member->xid, member->server_id);
else
x= *member->full_xid;

Expand Down Expand Up @@ -2655,9 +2657,12 @@ static my_bool xarecover_handlerton(THD *unused, plugin_ref plugin,
*/
if (info->mem_root)
{
// remember "full" xid too when it's not in mysql format
// remember "full" xid too when it's not in mysql format.
// Also record the transaction's original server_id. It will be used for
// populating the input XID to be searched in hash.
if (xid_member_replace(info->commit_list, x, info->mem_root,
is_server_xid? NULL : &info->list[i]))
is_server_xid? NULL : &info->list[i],
is_server_xid? info->list[i].get_trx_server_id() : server_id))
{
info->error= true;
sql_print_error("Error in memory allocation at xarecover_handlerton");
Expand Down
16 changes: 12 additions & 4 deletions sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -902,12 +902,13 @@ struct xid_t {
if ((bqual_length= bl))
memcpy(data+gl, b, bl);
}
void set(ulonglong xid)
// Populate server_id if it's specified, otherwise use the current server_id
void set(ulonglong xid, decltype(::server_id) trx_server_id= server_id)
{
my_xid tmp;
formatID= 1;
set(MYSQL_XID_PREFIX_LEN, 0, MYSQL_XID_PREFIX);
memcpy(data+MYSQL_XID_PREFIX_LEN, &server_id, sizeof(server_id));
memcpy(data+MYSQL_XID_PREFIX_LEN, &trx_server_id, sizeof(trx_server_id));
tmp= xid;
memcpy(data+MYSQL_XID_OFFSET, &tmp, sizeof(tmp));
gtrid_length=MYSQL_XID_GTRID_LEN;
Expand All @@ -933,6 +934,12 @@ struct xid_t {
!memcmp(data, MYSQL_XID_PREFIX, MYSQL_XID_PREFIX_LEN) ?
quick_get_my_xid() : 0;
}
decltype(::server_id) get_trx_server_id()
{
decltype(::server_id) trx_server_id;
memcpy(&trx_server_id, data+MYSQL_XID_PREFIX_LEN, sizeof(trx_server_id));
return trx_server_id;
}
uint length()
{
return static_cast<uint>(sizeof(formatID)) + key_length();
Expand Down Expand Up @@ -974,11 +981,12 @@ struct xid_recovery_member
bool decided_to_commit;
Binlog_offset binlog_coord; // semisync recovery binlog offset
XID *full_xid; // needed by wsrep or past it recovery
decltype(::server_id) server_id; // server id of orginal server

xid_recovery_member(my_xid xid_arg, uint prepare_arg, bool decided_arg,
XID *full_xid_arg)
XID *full_xid_arg, decltype(::server_id) server_id_arg)
: xid(xid_arg), in_engine_prepare(prepare_arg),
decided_to_commit(decided_arg), full_xid(full_xid_arg) {};
decided_to_commit(decided_arg), full_xid(full_xid_arg) , server_id(server_id_arg) {};
};

/* for recover() handlerton call */
Expand Down
7 changes: 4 additions & 3 deletions sql/sql_delete.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2019, Oracle and/or its affiliates.
Copyright (c) 2010, 2021, MariaDB
Copyright (c) 2010, 2022, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -417,7 +417,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
DBUG_RETURN(TRUE);

const_cond= (!conds || conds->const_item());
safe_update= MY_TEST(thd->variables.option_bits & OPTION_SAFE_UPDATES);
safe_update= (thd->variables.option_bits & OPTION_SAFE_UPDATES) &&
!thd->lex->describe;
if (safe_update && const_cond)
{
my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
Expand Down Expand Up @@ -542,7 +543,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
}

/* If running in safe sql mode, don't allow updates without keys */
if (table->opt_range_keys.is_clear_all())
if (!select || !select->quick)
{
thd->set_status_no_index_used();
if (safe_update && !using_limit)
Expand Down
7 changes: 4 additions & 3 deletions sql/sql_update.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates.
Copyright (c) 2011, 2021, MariaDB
Copyright (c) 2011, 2022, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -370,7 +370,8 @@ int mysql_update(THD *thd,
ha_rows *found_return, ha_rows *updated_return)
{
bool using_limit= limit != HA_POS_ERROR;
bool safe_update= thd->variables.option_bits & OPTION_SAFE_UPDATES;
bool safe_update= (thd->variables.option_bits & OPTION_SAFE_UPDATES)
&& !thd->lex->describe;
bool used_key_is_modified= FALSE, transactional_table;
bool will_batch= FALSE;
bool can_compare_record;
Expand Down Expand Up @@ -597,7 +598,7 @@ int mysql_update(THD *thd,
}

/* If running in safe sql mode, don't allow updates without keys */
if (table->opt_range_keys.is_clear_all())
if (!select || !select->quick)
{
thd->set_status_no_index_used();
if (safe_update && !using_limit)
Expand Down
Loading

0 comments on commit dc4b7f3

Please sign in to comment.