From 184f718fef0101a7559364cb97e22ee568e64c12 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Fri, 13 Mar 2015 10:46:00 +0100 Subject: [PATCH 01/13] MDEV-7249: Performance problem in parallel replication with multi-level slaves Parallel replication (in 10.0 / "conservative" mode) relies on binlog group commits to group transactions that can be safely run in parallel on the slave. The --binlog-commit-wait-count and --binlog-commit-wait-usec options exist to increase the number of commits per group. But in case of conflicts between transactions, this can cause unnecessary delay and reduced througput, especially on a slave where commit order is fixed. This patch adds a heuristics to reduce this problem. When transaction T1 goes to commit, it will first wait for N transactions to queue up for a group commit. However, if we detect that another transaction T2 is waiting for a row lock held by T1, then we will skip the wait and let T1 commit immediately, releasing locks and let T2 continue. On a slave, this avoids the unfortunate situation where T1 is waiting for T2 to join the group commit, but T2 is waiting for T1 to release locks, causing no work to be done for the duration of the --binlog-commit-wait-usec timeout. (The heuristic seems reasonable on the master as well, so it is enabled for all transactions, not just replication transactions). --- .../suite/binlog/r/binlog_commit_wait.result | 57 ++++++++ .../suite/binlog/t/binlog_commit_wait.test | 123 ++++++++++++++++++ sql/handler.cc | 6 + sql/log.cc | 60 ++++++++- sql/log.h | 2 + sql/sql_class.cc | 6 +- sql/sql_class.h | 12 ++ sql/transaction.cc | 2 + storage/innobase/lock/lock0lock.cc | 2 +- storage/xtradb/lock/lock0lock.cc | 2 +- 10 files changed, 267 insertions(+), 5 deletions(-) create mode 100644 mysql-test/suite/binlog/r/binlog_commit_wait.result create mode 100644 mysql-test/suite/binlog/t/binlog_commit_wait.test diff --git a/mysql-test/suite/binlog/r/binlog_commit_wait.result b/mysql-test/suite/binlog/r/binlog_commit_wait.result new file mode 100644 index 00000000000..e3d4b9e5d97 --- /dev/null +++ b/mysql-test/suite/binlog/r/binlog_commit_wait.result @@ -0,0 +1,57 @@ +ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; +CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; +SET @old_count= @@GLOBAL.binlog_commit_wait_count; +SET GLOBAL binlog_commit_wait_count= 3; +SET @old_usec= @@GLOBAL.binlog_commit_wait_usec; +SET GLOBAL binlog_commit_wait_usec= 20000000; +SET @a= current_timestamp(); +BEGIN; +INSERT INTO t1 VALUES (1,0); +COMMIT; +INSERT INTO t1 VALUES (1,1); +SET @b= unix_timestamp(current_timestamp()) - unix_timestamp(@a); +SELECT IF(@b < 20, "Ok", CONCAT("Error: too much time elapsed: ", @b, " seconds >= 20")); +IF(@b < 20, "Ok", CONCAT("Error: too much time elapsed: ", @b, " seconds >= 20")) +Ok +ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +SET @a= current_timestamp(); +INSERT INTO t1 VALUES (2,0); +INSERT INTO t1 VALUES (3,0); +INSERT INTO t1 VALUES (4,0); +SET @b= unix_timestamp(current_timestamp()) - unix_timestamp(@a); +SELECT IF(@b < 20, "Ok", CONCAT("Error: too much time elapsed: ", @b, " seconds >= 20")); +IF(@b < 20, "Ok", CONCAT("Error: too much time elapsed: ", @b, " seconds >= 20")) +Ok +SET @a= current_timestamp(); +INSERT INTO t1 VALUES (6,0); +BEGIN; +UPDATE t1 SET b=b+1 WHERE a=1; +UPDATE t1 SET b=b+10 WHERE a=1; +SELECT SLEEP(0.25); +SLEEP(0.25) +0 +UPDATE t1 SET b=b+1 WHERE a=3; +COMMIT; +SET @b= unix_timestamp(current_timestamp()) - unix_timestamp(@a); +SELECT IF(@b < 20, "Ok", CONCAT("Error: too much time elapsed: ", @b, " seconds >= 20")); +IF(@b < 20, "Ok", CONCAT("Error: too much time elapsed: ", @b, " seconds >= 20")) +Ok +SET @a= current_timestamp(); +INSERT INTO t1 VALUES (7,0); +INSERT INTO t1 VALUES (8,0); +SET @b= unix_timestamp(current_timestamp()) - unix_timestamp(@a); +SELECT IF(@b < 20, "Ok", CONCAT("Error: too much time elapsed: ", @b, " seconds >= 20")); +IF(@b < 20, "Ok", CONCAT("Error: too much time elapsed: ", @b, " seconds >= 20")) +Ok +SELECT * FROM t1 ORDER BY a; +a b +1 11 +2 0 +3 1 +4 0 +6 0 +7 0 +8 0 +DROP TABLE t1; +SET GLOBAL binlog_commit_wait_count= @old_count; +SET GLOBAL binlog_commit_wait_usec= @old_usec; diff --git a/mysql-test/suite/binlog/t/binlog_commit_wait.test b/mysql-test/suite/binlog/t/binlog_commit_wait.test new file mode 100644 index 00000000000..5b3fb0a5e25 --- /dev/null +++ b/mysql-test/suite/binlog/t/binlog_commit_wait.test @@ -0,0 +1,123 @@ +--source include/have_innodb.inc +--source include/have_log_bin.inc + +ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; +CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; + +SET @old_count= @@GLOBAL.binlog_commit_wait_count; +SET GLOBAL binlog_commit_wait_count= 3; +SET @old_usec= @@GLOBAL.binlog_commit_wait_usec; +SET GLOBAL binlog_commit_wait_usec= 20000000; + +connect(con1,localhost,root,,test); +connect(con2,localhost,root,,test); +connect(con3,localhost,root,,test); + +# Check that if T2 goes to wait for a row lock of T1 while T1 is waiting for +# more transactions to arrive for group commit, the commit of T1 will complete +# immediately. +# We test this by setting a very high timeout (20 seconds), and testing that +# that much time does not elapse. + +--connection default +SET @a= current_timestamp(); + +--connection con1 +BEGIN; +INSERT INTO t1 VALUES (1,0); +send COMMIT; + +--connection con2 +send INSERT INTO t1 VALUES (1,1); + +--connection con1 +reap; + +--connection default +SET @b= unix_timestamp(current_timestamp()) - unix_timestamp(@a); +SELECT IF(@b < 20, "Ok", CONCAT("Error: too much time elapsed: ", @b, " seconds >= 20")); + +--connection con2 +--error ER_DUP_ENTRY +reap; + + +# Test that the commit triggers when sufficient commits have queued up. +--connection default +SET @a= current_timestamp(); + +--connection con1 +send INSERT INTO t1 VALUES (2,0); + +--connection con2 +send INSERT INTO t1 VALUES (3,0); + +--connection con3 +INSERT INTO t1 VALUES (4,0); + +--connection con1 +reap; +--connection con2 +reap; + +--connection default +SET @b= unix_timestamp(current_timestamp()) - unix_timestamp(@a); +SELECT IF(@b < 20, "Ok", CONCAT("Error: too much time elapsed: ", @b, " seconds >= 20")); + + +# Test that commit triggers immediately if there is already a transaction +# waiting on another transaction that reaches its commit. + +--connection default +SET @a= current_timestamp(); + +--connection con1 +send INSERT INTO t1 VALUES (6,0); + +--connection con2 +BEGIN; +UPDATE t1 SET b=b+1 WHERE a=1; + +--connection con3 +send UPDATE t1 SET b=b+10 WHERE a=1; + +--connection con2 +# A small sleep to let con3 have time to wait on con2. +# The sleep might be too small on loaded host, but that is not a big problem; +# it only means we will trigger a different code path (con3 waits after con2 +# is ready to commit rather than before); and either path should work the same. +# So we will not get false positive in case of different timing; at worst false +# negative. +SELECT SLEEP(0.25); +UPDATE t1 SET b=b+1 WHERE a=3; +COMMIT; + +--connection con1 +reap; + +--connection default +SET @b= unix_timestamp(current_timestamp()) - unix_timestamp(@a); +SELECT IF(@b < 20, "Ok", CONCAT("Error: too much time elapsed: ", @b, " seconds >= 20")); + +--connection default +SET @a= current_timestamp(); + +# Now con3 will be waiting for a following group commit to trigger. +--connection con1 +send INSERT INTO t1 VALUES (7,0); +--connection con2 +INSERT INTO t1 VALUES (8,0); +--connection con3 +reap; + +--connection default +SET @b= unix_timestamp(current_timestamp()) - unix_timestamp(@a); +SELECT IF(@b < 20, "Ok", CONCAT("Error: too much time elapsed: ", @b, " seconds >= 20")); + +--connection default +SELECT * FROM t1 ORDER BY a; + +--connection default +DROP TABLE t1; +SET GLOBAL binlog_commit_wait_count= @old_count; +SET GLOBAL binlog_commit_wait_usec= @old_usec; diff --git a/sql/handler.cc b/sql/handler.cc index 9a2ba6bb732..70bce6f3963 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1545,7 +1545,10 @@ commit_one_phase_2(THD *thd, bool all, THD_TRANS *trans, bool is_real_trans) } /* Free resources and perform other cleanup even for 'empty' transactions. */ if (is_real_trans) + { + thd->has_waiter= false; thd->transaction.cleanup(); + } DBUG_RETURN(error); } @@ -1626,7 +1629,10 @@ int ha_rollback_trans(THD *thd, bool all) /* Always cleanup. Even if nht==0. There may be savepoints. */ if (is_real_trans) + { + thd->has_waiter= false; thd->transaction.cleanup(); + } if (all) thd->transaction_rollback_request= FALSE; diff --git a/sql/log.cc b/sql/log.cc index 6fa6156c489..30ecd51ab77 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -7029,6 +7029,14 @@ MYSQL_BIN_LOG::queue_for_group_commit(group_commit_entry *orig_entry) } } + /* + Handle the heuristics that if another transaction is waiting for this + transaction (or if it does so later), then we want to trigger group + commit immediately, without waiting for the binlog_commit_wait_usec + timeout to expire. + */ + entry->thd->waiting_on_group_commit= true; + /* Add the entry to the group commit queue. */ next_entry= entry->next; entry->next= group_commit_queue; @@ -7044,7 +7052,7 @@ MYSQL_BIN_LOG::queue_for_group_commit(group_commit_entry *orig_entry) cur= entry->thd->wait_for_commit_ptr; } - if (opt_binlog_commit_wait_count > 0) + if (opt_binlog_commit_wait_count > 0 && orig_queue != NULL) mysql_cond_signal(&COND_prepare_ordered); mysql_mutex_unlock(&LOCK_prepare_ordered); DEBUG_SYNC(orig_entry->thd, "commit_after_release_LOCK_prepare_ordered"); @@ -7218,6 +7226,11 @@ MYSQL_BIN_LOG::trx_group_commit_leader(group_commit_entry *leader) while (current) { group_commit_entry *next= current->next; + /* + Now that group commit is started, we can clear the flag; there is no + longer any use in waiters on this commit trying to trigger it early. + */ + current->thd->waiting_on_group_commit= false; current->next= queue; queue= current; current= next; @@ -7530,7 +7543,7 @@ MYSQL_BIN_LOG::wait_for_sufficient_commits() mysql_mutex_assert_owner(&LOCK_prepare_ordered); for (e= last_head= group_commit_queue, count= 0; e; e= e->next) - if (++count >= opt_binlog_commit_wait_count) + if (++count >= opt_binlog_commit_wait_count || unlikely(e->thd->has_waiter)) return; mysql_mutex_unlock(&LOCK_log); @@ -7545,13 +7558,20 @@ MYSQL_BIN_LOG::wait_for_sufficient_commits() &wait_until); if (err == ETIMEDOUT) break; + if (unlikely(last_head->thd->has_waiter)) + break; head= group_commit_queue; for (e= head; e && e != last_head; e= e->next) + { ++count; + if (unlikely(e->thd->has_waiter)) + goto after_loop; + } if (count >= opt_binlog_commit_wait_count) break; last_head= head; } +after_loop: /* We must not wait for LOCK_log while holding LOCK_prepare_ordered. @@ -7575,6 +7595,42 @@ MYSQL_BIN_LOG::wait_for_sufficient_commits() } +void +MYSQL_BIN_LOG::binlog_trigger_immediate_group_commit() +{ + group_commit_entry *head; + mysql_mutex_lock(&LOCK_prepare_ordered); + head= group_commit_queue; + if (head) + { + head->thd->has_waiter= true; + mysql_cond_signal(&COND_prepare_ordered); + } + mysql_mutex_unlock(&LOCK_prepare_ordered); +} + + +/* + This function is called when a transaction T1 goes to wait for another + transaction T2. It is used to cut short any binlog group commit delay from + --binlog-commit-wait-count in the case where another transaction is stalled + on the wait due to conflicting row locks. + + If T2 is already ready to group commit, any waiting group commit will be + signalled to proceed immediately. Otherwise, a flag will be set in T2, and + when T2 later becomes ready, immediate group commit will be triggered. +*/ +void +binlog_report_wait_for(THD *thd1, THD *thd2) +{ + if (opt_binlog_commit_wait_count == 0) + return; + thd2->has_waiter= true; + if (thd2->waiting_on_group_commit) + mysql_bin_log.binlog_trigger_immediate_group_commit(); +} + + /** Wait until we get a signal that the relay log has been updated. diff --git a/sql/log.h b/sql/log.h index a93e2e1c0b9..78a55f90292 100644 --- a/sql/log.h +++ b/sql/log.h @@ -690,6 +690,7 @@ public: void set_max_size(ulong max_size_arg); void signal_update(); void wait_for_sufficient_commits(); + void binlog_trigger_immediate_group_commit(); void wait_for_update_relay_log(THD* thd); int wait_for_update_bin_log(THD* thd, const struct timespec * timeout); void init(ulong max_size); @@ -1005,6 +1006,7 @@ bool general_log_print(THD *thd, enum enum_server_command command, bool general_log_write(THD *thd, enum enum_server_command command, const char *query, uint query_length); +void binlog_report_wait_for(THD *thd, THD *other_thd); void sql_perror(const char *message); bool flush_error_log(); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 9cdf5cec54d..8c52d5dd92d 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -887,6 +887,7 @@ THD::THD() in_lock_tables(0), bootstrap(0), derived_tables_processing(FALSE), + waiting_on_group_commit(FALSE), has_waiter(FALSE), spcont(NULL), m_parser_state(NULL), #if defined(ENABLED_DEBUG_SYNC) @@ -4233,6 +4234,8 @@ thd_need_wait_for(const MYSQL_THD thd) { rpl_group_info *rgi; + if (mysql_bin_log.is_open() && opt_binlog_commit_wait_count > 0) + return true; if (!thd) return false; rgi= thd->rgi_slave; @@ -4267,13 +4270,14 @@ thd_need_wait_for(const MYSQL_THD thd) not harmful, but could lead to unnecessary kill and retry, so best avoided). */ extern "C" void -thd_report_wait_for(const MYSQL_THD thd, MYSQL_THD other_thd) +thd_report_wait_for(MYSQL_THD thd, MYSQL_THD other_thd) { rpl_group_info *rgi; rpl_group_info *other_rgi; if (!thd || !other_thd) return; + binlog_report_wait_for(thd, other_thd); rgi= thd->rgi_slave; other_rgi= other_thd->rgi_slave; if (!rgi || !other_rgi) diff --git a/sql/sql_class.h b/sql/sql_class.h index 5d64837a2c1..3252bc1bbe2 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2674,6 +2674,18 @@ public: it returned an error on master, and this is OK on the slave. */ bool is_slave_error; + /* + True when a transaction is queued up for binlog group commit. + Used so that if another transaction needs to wait for a row lock held by + this transaction, it can signal to trigger the group commit immediately, + skipping the normal --binlog-commit-wait-count wait. + */ + bool waiting_on_group_commit; + /* + Set true when another transaction goes to wait on a row lock held by this + transaction. Used together with waiting_on_group_commit. + */ + bool has_waiter; /* In case of a slave, set to the error code the master got when executing the query. 0 if no error on the master. diff --git a/sql/transaction.cc b/sql/transaction.cc index 51d8a08e981..a70c075e142 100644 --- a/sql/transaction.cc +++ b/sql/transaction.cc @@ -149,6 +149,8 @@ bool trans_begin(THD *thd, uint flags) when we come here. We should at some point change this to an assert. */ thd->transaction.all.modified_non_trans_table= FALSE; + thd->has_waiter= false; + thd->waiting_on_group_commit= false; if (res) DBUG_RETURN(TRUE); diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index b822b400153..850d81cad02 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -375,7 +375,7 @@ struct lock_stack_t { ulint heap_no; /*!< heap number if rec lock */ }; -extern "C" void thd_report_wait_for(const MYSQL_THD thd, MYSQL_THD other_thd); +extern "C" void thd_report_wait_for(MYSQL_THD thd, MYSQL_THD other_thd); extern "C" int thd_need_wait_for(const MYSQL_THD thd); extern "C" int thd_need_ordering_with(const MYSQL_THD thd, const MYSQL_THD other_thd); diff --git a/storage/xtradb/lock/lock0lock.cc b/storage/xtradb/lock/lock0lock.cc index aa36202f76f..f9ea52470d5 100644 --- a/storage/xtradb/lock/lock0lock.cc +++ b/storage/xtradb/lock/lock0lock.cc @@ -375,7 +375,7 @@ struct lock_stack_t { ulint heap_no; /*!< heap number if rec lock */ }; -extern "C" void thd_report_wait_for(const MYSQL_THD thd, MYSQL_THD other_thd); +extern "C" void thd_report_wait_for(MYSQL_THD thd, MYSQL_THD other_thd); extern "C" int thd_need_wait_for(const MYSQL_THD thd); extern "C" int thd_need_ordering_with(const MYSQL_THD thd, const MYSQL_THD other_thd); From 2e82a8233c841dc2c2ace77d749363dec0bd4f98 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Mon, 16 Mar 2015 10:54:47 +0100 Subject: [PATCH 02/13] MDEV-7785: errorneous -> erroneous spelling mistake --- mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result | 2 +- mysql-test/suite/rpl/t/rpl_gtid_errorhandling.test | 2 +- sql/rpl_rli.cc | 2 +- sql/share/errmsg-utf8.txt | 2 +- sql/slave.cc | 2 +- sql/sql_repl.cc | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result b/mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result index 385a374888c..a2bf8b567e8 100644 --- a/mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result +++ b/mysql-test/suite/rpl/r/rpl_gtid_errorhandling.result @@ -179,7 +179,7 @@ a SET sql_log_bin=0; CALL mtr.add_suppression("Slave: Could not update replication slave gtid state"); SET sql_log_bin=1; -*** MDEV-4906: When event apply fails, next SQL thread start errorneously commits the failing GTID to gtid_slave_pos *** +*** MDEV-4906: When event apply fails, next SQL thread start erroneously commits the failing GTID to gtid_slave_pos *** include/stop_slave.inc SET sql_log_bin=0; DELETE FROM t2; diff --git a/mysql-test/suite/rpl/t/rpl_gtid_errorhandling.test b/mysql-test/suite/rpl/t/rpl_gtid_errorhandling.test index 31492b7c096..9739ba8bc43 100644 --- a/mysql-test/suite/rpl/t/rpl_gtid_errorhandling.test +++ b/mysql-test/suite/rpl/t/rpl_gtid_errorhandling.test @@ -230,7 +230,7 @@ CALL mtr.add_suppression("Slave: Could not update replication slave gtid state") SET sql_log_bin=1; ---echo *** MDEV-4906: When event apply fails, next SQL thread start errorneously commits the failing GTID to gtid_slave_pos *** +--echo *** MDEV-4906: When event apply fails, next SQL thread start erroneously commits the failing GTID to gtid_slave_pos *** --connection slave --source include/stop_slave.inc diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index 4ca8282956c..a324c3c30da 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -1769,7 +1769,7 @@ void rpl_group_info::cleanup_context(THD *thd, bool error) trans_rollback(thd); // if a "real transaction" /* Now that we have rolled back the transaction, make sure we do not - errorneously update the GTID position. + erroneously update the GTID position. */ gtid_pending= false; } diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 4980ba06604..6954170e86c 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7080,7 +7080,7 @@ ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_GTID_DOMAIN_ID_SEQ_NO ER_STORED_FUNCTION_PREVENTS_SWITCH_GTID_DOMAIN_ID_SEQ_NO eng "Cannot modify @@session.gtid_domain_id or @@session.gtid_seq_no inside a stored function or trigger" ER_GTID_POSITION_NOT_FOUND_IN_BINLOG2 - eng "Connecting slave requested to start from GTID %u-%u-%llu, which is not in the master's binlog. Since the master's binlog contains GTIDs with higher sequence numbers, it probably means that the slave has diverged due to executing extra errorneous transactions" + eng "Connecting slave requested to start from GTID %u-%u-%llu, which is not in the master's binlog. Since the master's binlog contains GTIDs with higher sequence numbers, it probably means that the slave has diverged due to executing extra erroneous transactions" ER_BINLOG_MUST_BE_EMPTY eng "This operation is not allowed if any GTID has been logged to the binary log. Run RESET MASTER first to erase the log" ER_NO_SUCH_QUERY diff --git a/sql/slave.cc b/sql/slave.cc index 703338c435c..cd628c36c99 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -3352,7 +3352,7 @@ int apply_event_and_update_pos(Log_event* ev, THD* thd, else { /* - Make sure we do not errorneously update gtid_slave_pos with a lingering + Make sure we do not erroneously update gtid_slave_pos with a lingering GTID from this failed event group (MDEV-4906). */ rgi->gtid_pending= false; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 26355e4de5d..4055c8ea8af 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -943,7 +943,7 @@ give_error_start_pos_missing_in_binlog(int *err, const char **errormsg, binlog_gtid.seq_no >= error_gtid->seq_no) { *errormsg= "Requested slave GTID state not found in binlog. The slave has " - "probably diverged due to executing errorneous transactions"; + "probably diverged due to executing erroneous transactions"; *err= ER_GTID_POSITION_NOT_FOUND_IN_BINLOG2; } else @@ -2751,7 +2751,7 @@ err: "%u-%u-%llu, which is not in the master's binlog. Since the " "master's binlog contains GTIDs with higher sequence numbers, " "it probably means that the slave has diverged due to " - "executing extra errorneous transactions", + "executing extra erroneous transactions", error_gtid.domain_id, error_gtid.server_id, error_gtid.seq_no); /* Use this error code so slave will know not to try reconnect. */ my_errno = ER_MASTER_FATAL_ERROR_READING_BINLOG; From 3d4850158fdd62a57cf76515db99f07457f344d5 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Tue, 17 Mar 2015 10:36:38 +0100 Subject: [PATCH 03/13] Fix embarrassing bug in test case that caused sporadic test failures. --- mysql-test/suite/rpl/t/rpl_gtid_basic.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/suite/rpl/t/rpl_gtid_basic.test b/mysql-test/suite/rpl/t/rpl_gtid_basic.test index 778cf427d99..4c4a9063a0b 100644 --- a/mysql-test/suite/rpl/t/rpl_gtid_basic.test +++ b/mysql-test/suite/rpl/t/rpl_gtid_basic.test @@ -525,8 +525,8 @@ SELECT * FROM t1 WHERE a >= 30 ORDER BY a; --save_master_pos --connection server_4 -SELECT * FROM t1 WHERE a >= 30 ORDER BY a; --sync_with_master +SELECT * FROM t1 WHERE a >= 30 ORDER BY a; # Clean up. From 99a2c061d7bfc181b04a0adc14ce036fab821d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Tue, 17 Mar 2015 20:35:05 +0200 Subject: [PATCH 04/13] MDEV-7754: innodb assert "array->n_elems < array->max_elems" on a huge blob update Problem was that static array was used for storing thread mutex sync levels. Fixed by using std::vector instead. Does not contain test case to avoid too big memory/disk space usage on buildbot VMs. --- storage/innobase/sync/sync0sync.cc | 78 ++++++------------------------ storage/xtradb/sync/sync0sync.cc | 78 ++++++------------------------ 2 files changed, 30 insertions(+), 126 deletions(-) diff --git a/storage/innobase/sync/sync0sync.cc b/storage/innobase/sync/sync0sync.cc index fb559f26bd4..d00aabd6ff1 100644 --- a/storage/innobase/sync/sync0sync.cc +++ b/storage/innobase/sync/sync0sync.cc @@ -47,6 +47,8 @@ Created 9/5/1995 Heikki Tuuri #include "ha_prototypes.h" #include "my_cpu.h" +#include + /* REASONS FOR IMPLEMENTING THE SPIN LOCK MUTEX ============================================ @@ -225,12 +227,9 @@ static const ulint SYNC_THREAD_N_LEVELS = 10000; /** Array for tracking sync levels per thread. */ struct sync_arr_t { - ulint in_use; /*!< Number of active cells */ ulint n_elems; /*!< Number of elements in the array */ - ulint max_elems; /*!< Maximum elements */ - ulint next_free; /*!< ULINT_UNDEFINED or index of next - free slot */ - sync_level_t* elems; /*!< Array elements */ + + std::vector elems; /*!< Vector of elements */ }; /** Mutexes or rw-locks held by a thread */ @@ -1069,10 +1068,9 @@ sync_thread_add_level( SYNC_LEVEL_VARYING, nothing is done */ ibool relock) /*!< in: TRUE if re-entering an x-lock */ { - ulint i; - sync_level_t* slot; sync_arr_t* array; sync_thread_t* thread_slot; + sync_level_t sync_level; if (!sync_order_checks_on) { @@ -1097,21 +1095,11 @@ sync_thread_add_level( thread_slot = sync_thread_level_arrays_find_slot(); if (thread_slot == NULL) { - ulint sz; - - sz = sizeof(*array) - + (sizeof(*array->elems) * SYNC_THREAD_N_LEVELS); /* We have to allocate the level array for a new thread */ - array = static_cast(calloc(sz, sizeof(char))); + array = static_cast(calloc(1, sizeof(sync_arr_t))); ut_a(array != NULL); - - array->next_free = ULINT_UNDEFINED; - array->max_elems = SYNC_THREAD_N_LEVELS; - array->elems = (sync_level_t*) &array[1]; - thread_slot = sync_thread_level_arrays_find_free(); - thread_slot->levels = array; thread_slot->id = os_thread_get_curr_id(); } @@ -1321,26 +1309,11 @@ sync_thread_add_level( } levels_ok: - if (array->next_free == ULINT_UNDEFINED) { - ut_a(array->n_elems < array->max_elems); - i = array->n_elems++; - } else { - i = array->next_free; - array->next_free = array->elems[i].level; - } - - ut_a(i < array->n_elems); - ut_a(i != ULINT_UNDEFINED); - - ++array->in_use; - - slot = &array->elems[i]; - - ut_a(slot->latch == NULL); - - slot->latch = latch; - slot->level = level; + array->n_elems++; + sync_level.latch = latch; + sync_level.level = level; + array->elems.push_back(sync_level); mutex_exit(&sync_thread_mutex); } @@ -1358,7 +1331,6 @@ sync_thread_reset_level( { sync_arr_t* array; sync_thread_t* thread_slot; - ulint i; if (!sync_order_checks_on) { @@ -1387,36 +1359,16 @@ sync_thread_reset_level( array = thread_slot->levels; - for (i = 0; i < array->n_elems; i++) { - sync_level_t* slot; + for (std::vector::iterator it = array->elems.begin(); it != array->elems.end(); ++it) { + sync_level_t level = *it; - slot = &array->elems[i]; - - if (slot->latch != latch) { + if (level.latch != latch) { continue; } - slot->latch = NULL; - - /* Update the free slot list. See comment in sync_level_t - for the level field. */ - slot->level = array->next_free; - array->next_free = i; - - ut_a(array->in_use >= 1); - --array->in_use; - - /* If all cells are idle then reset the free - list. The assumption is that this will save - time when we need to scan up to n_elems. */ - - if (array->in_use == 0) { - array->n_elems = 0; - array->next_free = ULINT_UNDEFINED; - } - + array->elems.erase(it); + array->n_elems--; mutex_exit(&sync_thread_mutex); - return(TRUE); } diff --git a/storage/xtradb/sync/sync0sync.cc b/storage/xtradb/sync/sync0sync.cc index d02a0df70ca..7e104202f36 100644 --- a/storage/xtradb/sync/sync0sync.cc +++ b/storage/xtradb/sync/sync0sync.cc @@ -48,6 +48,8 @@ Created 9/5/1995 Heikki Tuuri #include "ha_prototypes.h" #include "my_cpu.h" +#include + /* REASONS FOR IMPLEMENTING THE SPIN LOCK MUTEX ============================================ @@ -229,12 +231,9 @@ static const ulint SYNC_THREAD_N_LEVELS = 10000; /** Array for tracking sync levels per thread. */ struct sync_arr_t { - ulint in_use; /*!< Number of active cells */ ulint n_elems; /*!< Number of elements in the array */ - ulint max_elems; /*!< Maximum elements */ - ulint next_free; /*!< ULINT_UNDEFINED or index of next - free slot */ - sync_level_t* elems; /*!< Array elements */ + + std::vector elems; /*!< Vector of elements */ }; /** Mutexes or rw-locks held by a thread */ @@ -1177,10 +1176,9 @@ sync_thread_add_level( SYNC_LEVEL_VARYING, nothing is done */ ibool relock) /*!< in: TRUE if re-entering an x-lock */ { - ulint i; - sync_level_t* slot; sync_arr_t* array; sync_thread_t* thread_slot; + sync_level_t sync_level; if (!sync_order_checks_on) { @@ -1205,21 +1203,11 @@ sync_thread_add_level( thread_slot = sync_thread_level_arrays_find_slot(); if (thread_slot == NULL) { - ulint sz; - - sz = sizeof(*array) - + (sizeof(*array->elems) * SYNC_THREAD_N_LEVELS); /* We have to allocate the level array for a new thread */ - array = static_cast(calloc(sz, sizeof(char))); + array = static_cast(calloc(1, sizeof(sync_arr_t))); ut_a(array != NULL); - - array->next_free = ULINT_UNDEFINED; - array->max_elems = SYNC_THREAD_N_LEVELS; - array->elems = (sync_level_t*) &array[1]; - thread_slot = sync_thread_level_arrays_find_free(); - thread_slot->levels = array; thread_slot->id = os_thread_get_curr_id(); } @@ -1446,26 +1434,11 @@ sync_thread_add_level( } levels_ok: - if (array->next_free == ULINT_UNDEFINED) { - ut_a(array->n_elems < array->max_elems); - i = array->n_elems++; - } else { - i = array->next_free; - array->next_free = array->elems[i].level; - } - - ut_a(i < array->n_elems); - ut_a(i != ULINT_UNDEFINED); - - ++array->in_use; - - slot = &array->elems[i]; - - ut_a(slot->latch == NULL); - - slot->latch = latch; - slot->level = level; + array->n_elems++; + sync_level.latch = latch; + sync_level.level = level; + array->elems.push_back(sync_level); mutex_exit(&sync_thread_mutex); } @@ -1483,7 +1456,6 @@ sync_thread_reset_level( { sync_arr_t* array; sync_thread_t* thread_slot; - ulint i; if (!sync_order_checks_on) { @@ -1512,36 +1484,16 @@ sync_thread_reset_level( array = thread_slot->levels; - for (i = 0; i < array->n_elems; i++) { - sync_level_t* slot; + for (std::vector::iterator it = array->elems.begin(); it != array->elems.end(); ++it) { + sync_level_t level = *it; - slot = &array->elems[i]; - - if (slot->latch != latch) { + if (level.latch != latch) { continue; } - slot->latch = NULL; - - /* Update the free slot list. See comment in sync_level_t - for the level field. */ - slot->level = array->next_free; - array->next_free = i; - - ut_a(array->in_use >= 1); - --array->in_use; - - /* If all cells are idle then reset the free - list. The assumption is that this will save - time when we need to scan up to n_elems. */ - - if (array->in_use == 0) { - array->n_elems = 0; - array->next_free = ULINT_UNDEFINED; - } - + array->elems.erase(it); + array->n_elems--; mutex_exit(&sync_thread_mutex); - return(TRUE); } From c14d9c21f0a6974d9909e00a23522114caad3bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 18 Mar 2015 06:25:10 +0200 Subject: [PATCH 05/13] Make sure that sync level vector is emptied. --- storage/innobase/sync/sync0sync.cc | 1 + storage/xtradb/sync/sync0sync.cc | 1 + 2 files changed, 2 insertions(+) diff --git a/storage/innobase/sync/sync0sync.cc b/storage/innobase/sync/sync0sync.cc index d00aabd6ff1..e62e4e7bc30 100644 --- a/storage/innobase/sync/sync0sync.cc +++ b/storage/innobase/sync/sync0sync.cc @@ -1454,6 +1454,7 @@ sync_thread_level_arrays_free(void) /* If this slot was allocated then free the slot memory too. */ if (slot->levels != NULL) { + slot->levels->elems.erase(slot->levels->elems.begin(),slot->levels->elems.end()); free(slot->levels); slot->levels = NULL; } diff --git a/storage/xtradb/sync/sync0sync.cc b/storage/xtradb/sync/sync0sync.cc index 7e104202f36..fcc2e01c1f4 100644 --- a/storage/xtradb/sync/sync0sync.cc +++ b/storage/xtradb/sync/sync0sync.cc @@ -1580,6 +1580,7 @@ sync_thread_level_arrays_free(void) /* If this slot was allocated then free the slot memory too. */ if (slot->levels != NULL) { + slot->levels->elems.erase(slot->levels->elems.begin(),slot->levels->elems.end()); free(slot->levels); slot->levels = NULL; } From 2bdbfd334bba93f75b2952e8e76f20ed29fb2bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 18 Mar 2015 12:18:39 +0200 Subject: [PATCH 06/13] Fix assertion failure seen on Buildbot win32-debug There is a bug in Visual Studio 2010 Visual Studio has a feature "Checked Iterators". In a debug build, every iterator operation is checked at runtime for errors, e g, out of range. Disable this "Checked Iterators" for Windows and Debug if defined. --- storage/innobase/sync/sync0sync.cc | 13 +++++++++++++ storage/xtradb/sync/sync0sync.cc | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/storage/innobase/sync/sync0sync.cc b/storage/innobase/sync/sync0sync.cc index e62e4e7bc30..2928fb0598b 100644 --- a/storage/innobase/sync/sync0sync.cc +++ b/storage/innobase/sync/sync0sync.cc @@ -47,6 +47,19 @@ Created 9/5/1995 Heikki Tuuri #include "ha_prototypes.h" #include "my_cpu.h" +/* There is a bug in Visual Studio 2010 +Visual Studio has a feature "Checked Iterators". In a debug build, every +iterator operation is checked at runtime for errors, e g, out of range. +Disable this "Checked Iterators" for Windows and Debug if defined. +*/ +#ifdef UNIV_DEBUG +#ifdef __WIN__ +#ifdef _ITERATOR_DEBUG_LEVEL +#define _ITERATOR_DEBUG_LEVEL 0 +#endif /* _ITERATOR_DEBUG_LEVEL */ +#endif /* __WIN__*/ +#endif /* UNIV_DEBUG */ + #include /* diff --git a/storage/xtradb/sync/sync0sync.cc b/storage/xtradb/sync/sync0sync.cc index fcc2e01c1f4..b8766699413 100644 --- a/storage/xtradb/sync/sync0sync.cc +++ b/storage/xtradb/sync/sync0sync.cc @@ -48,6 +48,19 @@ Created 9/5/1995 Heikki Tuuri #include "ha_prototypes.h" #include "my_cpu.h" +/* There is a bug in Visual Studio 2010 +Visual Studio has a feature "Checked Iterators". In a debug build, every +iterator operation is checked at runtime for errors, e g, out of range. +Disable this "Checked Iterators" for Windows and Debug if defined. +*/ +#ifdef UNIV_DEBUG +#ifdef __WIN__ +#ifdef _ITERATOR_DEBUG_LEVEL +#define _ITERATOR_DEBUG_LEVEL 0 +#endif /* _ITERATOR_DEBUG_LEVEL */ +#endif /* __WIN__*/ +#endif /* UNIV_DEBUG */ + #include /* From 1020d569343aab2de2a96cf630f3e7d9fa7ca84f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 18 Mar 2015 15:17:17 +0200 Subject: [PATCH 07/13] Better and more correct comment. --- storage/innobase/sync/sync0sync.cc | 10 ++++++++-- storage/xtradb/sync/sync0sync.cc | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/storage/innobase/sync/sync0sync.cc b/storage/innobase/sync/sync0sync.cc index 2928fb0598b..7225ac1a0dc 100644 --- a/storage/innobase/sync/sync0sync.cc +++ b/storage/innobase/sync/sync0sync.cc @@ -47,14 +47,20 @@ Created 9/5/1995 Heikki Tuuri #include "ha_prototypes.h" #include "my_cpu.h" -/* There is a bug in Visual Studio 2010 +/* There is a bug in Visual Studio 2010. Visual Studio has a feature "Checked Iterators". In a debug build, every -iterator operation is checked at runtime for errors, e g, out of range. +iterator operation is checked at runtime for errors, e.g., out of range. +Because of bug there is runtime error on following code +for (std::vector::iterator it = array->elems.begin(); it != +array->elems.end(); ++it) and runtime check fails on comparison +it != array->elems.end() that is correct and standard way to do end +of range comparison. Disable this "Checked Iterators" for Windows and Debug if defined. */ #ifdef UNIV_DEBUG #ifdef __WIN__ #ifdef _ITERATOR_DEBUG_LEVEL +#undef _ITERATOR_DEBUG_LEVEL #define _ITERATOR_DEBUG_LEVEL 0 #endif /* _ITERATOR_DEBUG_LEVEL */ #endif /* __WIN__*/ diff --git a/storage/xtradb/sync/sync0sync.cc b/storage/xtradb/sync/sync0sync.cc index b8766699413..131aa718dc9 100644 --- a/storage/xtradb/sync/sync0sync.cc +++ b/storage/xtradb/sync/sync0sync.cc @@ -48,14 +48,20 @@ Created 9/5/1995 Heikki Tuuri #include "ha_prototypes.h" #include "my_cpu.h" -/* There is a bug in Visual Studio 2010 +/* There is a bug in Visual Studio 2010. Visual Studio has a feature "Checked Iterators". In a debug build, every -iterator operation is checked at runtime for errors, e g, out of range. +iterator operation is checked at runtime for errors, e.g., out of range. +Because of bug there is runtime error on following code +for (std::vector::iterator it = array->elems.begin(); it != +array->elems.end(); ++it) and runtime check fails on comparison +it != array->elems.end() that is correct and standard way to do end +of range comparison. Disable this "Checked Iterators" for Windows and Debug if defined. */ #ifdef UNIV_DEBUG #ifdef __WIN__ #ifdef _ITERATOR_DEBUG_LEVEL +#undef _ITERATOR_DEBUG_LEVEL #define _ITERATOR_DEBUG_LEVEL 0 #endif /* _ITERATOR_DEBUG_LEVEL */ #endif /* __WIN__*/ From 323a7e93ee2445e6d5918b4946cbec99b1ab650c Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Wed, 25 Mar 2015 19:44:31 +0300 Subject: [PATCH 08/13] Backport from 10.1 to 10.0: Merge pull request #33 from k0da/mdev-7839 Fix BigEndian build for Cassandra SE --- storage/cassandra/ha_cassandra.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/cassandra/ha_cassandra.cc b/storage/cassandra/ha_cassandra.cc index 9b30445fcd2..e69e740bfcd 100644 --- a/storage/cassandra/ha_cassandra.cc +++ b/storage/cassandra/ha_cassandra.cc @@ -887,7 +887,7 @@ bool cassandra_to_dyncol_intLong(const char *cass_data, { value->type= DYN_COL_INT; #ifdef WORDS_BIGENDIAN - value->x.long_value= (longlong *)*cass_data; + value->x.long_value= (longlong)*cass_data; #else flip64(cass_data, (char *)&value->x.long_value); #endif From 0563f49ba355e27543e940052f35e1a904ef077b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Tue, 17 Mar 2015 16:03:05 +0200 Subject: [PATCH 09/13] MDEV-7754: innodb assert "array->n_elems < array->max_elems" on a huge blob update Replace static array of thread sync levels with std::vector. --- .../suite/innodb/r/innodb-bigblob.result | 7 +++++++ mysql-test/suite/innodb/t/innodb-bigblob.opt | 2 ++ mysql-test/suite/innodb/t/innodb-bigblob.test | 20 +++++++++++++++++++ storage/innobase/sync/sync0sync.cc | 2 ++ storage/xtradb/sync/sync0sync.cc | 2 ++ 5 files changed, 33 insertions(+) create mode 100644 mysql-test/suite/innodb/r/innodb-bigblob.result create mode 100644 mysql-test/suite/innodb/t/innodb-bigblob.opt create mode 100644 mysql-test/suite/innodb/t/innodb-bigblob.test diff --git a/mysql-test/suite/innodb/r/innodb-bigblob.result b/mysql-test/suite/innodb/r/innodb-bigblob.result new file mode 100644 index 00000000000..314bd3ed088 --- /dev/null +++ b/mysql-test/suite/innodb/r/innodb-bigblob.result @@ -0,0 +1,7 @@ +call mtr.add_suppression("Resizing redo log from *"); +call mtr.add_suppression("Starting to delete and rewrite log files."); +call mtr.add_suppression("New log files created, LSN=*"); +create table foo (id varchar(37) not null, content longblob) engine=INNODB; +insert into foo (id, content) values('xyz', ''); +update foo set content=repeat('a', 43941888) where id='xyz'; +drop table foo; diff --git a/mysql-test/suite/innodb/t/innodb-bigblob.opt b/mysql-test/suite/innodb/t/innodb-bigblob.opt new file mode 100644 index 00000000000..06cc9e2b979 --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb-bigblob.opt @@ -0,0 +1,2 @@ +--max-allowed-packet=128M +--innodb-log-file-size=210M diff --git a/mysql-test/suite/innodb/t/innodb-bigblob.test b/mysql-test/suite/innodb/t/innodb-bigblob.test new file mode 100644 index 00000000000..7665c890316 --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb-bigblob.test @@ -0,0 +1,20 @@ +-- source include/have_innodb.inc +-- source include/big_test.inc +-- source include/not_embedded.inc + +--disable_query_log +let $status_orig=`SELECT @@innodb_status_output`; +--enable_query_log + +call mtr.add_suppression("Resizing redo log from *"); +call mtr.add_suppression("Starting to delete and rewrite log files."); +call mtr.add_suppression("New log files created, LSN=*"); + +create table foo (id varchar(37) not null, content longblob) engine=INNODB; +insert into foo (id, content) values('xyz', ''); +update foo set content=repeat('a', 43941888) where id='xyz'; +drop table foo; + +--disable_query_log +EVAL SET GLOBAL innodb_status_output = $status_orig; +--enable_query_log diff --git a/storage/innobase/sync/sync0sync.cc b/storage/innobase/sync/sync0sync.cc index 7225ac1a0dc..6a524dc0027 100644 --- a/storage/innobase/sync/sync0sync.cc +++ b/storage/innobase/sync/sync0sync.cc @@ -47,6 +47,8 @@ Created 9/5/1995 Heikki Tuuri #include "ha_prototypes.h" #include "my_cpu.h" +#include + /* There is a bug in Visual Studio 2010. Visual Studio has a feature "Checked Iterators". In a debug build, every iterator operation is checked at runtime for errors, e.g., out of range. diff --git a/storage/xtradb/sync/sync0sync.cc b/storage/xtradb/sync/sync0sync.cc index 131aa718dc9..ed269f86f12 100644 --- a/storage/xtradb/sync/sync0sync.cc +++ b/storage/xtradb/sync/sync0sync.cc @@ -48,6 +48,8 @@ Created 9/5/1995 Heikki Tuuri #include "ha_prototypes.h" #include "my_cpu.h" +#include + /* There is a bug in Visual Studio 2010. Visual Studio has a feature "Checked Iterators". In a debug build, every iterator operation is checked at runtime for errors, e.g., out of range. From b53bcd438f171fcbc3a4ad5051434e1b87c844fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 30 Mar 2015 18:53:10 +0300 Subject: [PATCH 10/13] MDEV-7367: Updating a virtual column corrupts table which crashes server Analysis: MySQL table definition contains also virtual columns. Similarly, index fielnr references MySQL table fields. However, InnoDB table definition does not contain virtual columns. Therefore, when matching MySQL key fieldnr we need to use actual column name to find out referenced InnoDB dictionary column name. Fix: Add new function to match MySQL index key columns to InnoDB dictionary. --- .../innodb/r/innodb-virtual-columns.result | 322 ++++++++++++++++++ .../innodb/t/innodb-virtual-columns.test | 302 ++++++++++++++++ storage/innobase/dict/dict0dict.cc | 34 ++ storage/innobase/handler/ha_innodb.cc | 2 + storage/innobase/handler/handler0alter.cc | 17 +- storage/innobase/include/dict0dict.h | 11 + storage/innobase/include/row0merge.h | 1 + storage/innobase/row/row0merge.cc | 6 +- storage/xtradb/dict/dict0dict.cc | 34 ++ storage/xtradb/handler/ha_innodb.cc | 2 + storage/xtradb/handler/handler0alter.cc | 18 +- storage/xtradb/include/dict0dict.h | 11 + storage/xtradb/include/row0merge.h | 1 + storage/xtradb/row/row0merge.cc | 6 +- 14 files changed, 753 insertions(+), 14 deletions(-) create mode 100644 mysql-test/suite/innodb/r/innodb-virtual-columns.result create mode 100644 mysql-test/suite/innodb/t/innodb-virtual-columns.test diff --git a/mysql-test/suite/innodb/r/innodb-virtual-columns.result b/mysql-test/suite/innodb/r/innodb-virtual-columns.result new file mode 100644 index 00000000000..558bb23de0a --- /dev/null +++ b/mysql-test/suite/innodb/r/innodb-virtual-columns.result @@ -0,0 +1,322 @@ +CREATE TABLE IF NOT EXISTS gso_grad_supr ( +term char(4) NOT NULL DEFAULT '', +uw_id int(8) UNSIGNED NOT NULL DEFAULT 0, +plan varchar(10) NOT NULL DEFAULT '', +wdraw_rsn varchar(4) NOT NULL DEFAULT '', +admit_term char(4) NOT NULL DEFAULT '', +CONSTRAINT gso_grad_supr_pky PRIMARY KEY (uw_id, term) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO `gso_grad_supr` VALUES ('1031',2,'CSM','','1009'); +INSERT INTO `gso_grad_supr` VALUES ('1035',2,'CSM','ACAD','1009'); +CREATE TABLE IF NOT EXISTS grad_degree ( +student_id int(8) UNSIGNED NOT NULL, +plan varchar(10) NOT NULL, +admit_term char(4) NOT NULL, +wdraw_rsn varchar(4) NOT NULL DEFAULT '', +ofis_deg_status varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed' + ELSE 'Not Completed' + END) VIRTUAL, +deg_start_term char(4) NOT NULL DEFAULT '' COMMENT 'Educated guess at the beginning of the data', +deg_as_of_term char(4) NOT NULL COMMENT 'In most cases also end term', +CONSTRAINT grad_degree_stu_plan_admit_pky PRIMARY KEY (student_id, plan, admit_term) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE INDEX grad_degree_wdraw_rsn_ndx ON grad_degree (wdraw_rsn); +CREATE INDEX grad_degree_as_of_term_ndx ON grad_degree (deg_as_of_term); +INSERT IGNORE grad_degree ( +student_id, +plan, +admit_term, +wdraw_rsn, +deg_start_term, +deg_as_of_term +) +SELECT +ggs.uw_id AS c_student_id, +ggs.plan, +ggs.admit_term, +ggs.wdraw_rsn, +IF( (SELECT COUNT(*) FROM grad_degree AS gd WHERE gd.student_id = ggs.uw_id AND gd.admit_term = ggs.admit_term) > 0, ggs.term, ggs.admit_term ) AS c_deg_start_term, +ggs.term AS c_as_of_term +FROM gso_grad_supr AS ggs +LEFT OUTER JOIN +grad_degree AS gd +ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term ) +WHERE +ggs.term = 1031 AND +gd.student_id IS NULL +; +UPDATE grad_degree AS gd +INNER JOIN +gso_grad_supr AS ggs +ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term ) +SET +gd.wdraw_rsn = ggs.wdraw_rsn, +gd.deg_as_of_term = 1035 +WHERE +gd.wdraw_rsn NOT IN ('DCMP', 'TRDC') AND +ggs.term = 1035 +; +drop table grad_degree; +CREATE TABLE IF NOT EXISTS grad_degree ( +student_id int(8) UNSIGNED NOT NULL, +plan varchar(10) NOT NULL, +admit_term char(4) NOT NULL, +wdraw_rsn varchar(4) NOT NULL DEFAULT '', +ofis_deg_status varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed' + ELSE 'Not Completed' + END) VIRTUAL, +ofis_deg_status2 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress2' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed2' + ELSE 'Not Completed2' + END) VIRTUAL, +ofis_deg_status3 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress3' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed3' + ELSE 'Not Completed3' + END) VIRTUAL, +ofis_deg_status4 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress4' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed4' + ELSE 'Not Completed4' + END) VIRTUAL, +ofis_deg_status5 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress5' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed5' + ELSE 'Not Completed5' + END) VIRTUAL, +ofis_deg_status6 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress6' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed6' + ELSE 'Not Completed6' + END) VIRTUAL, +ofis_deg_status7 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress7' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed7' + ELSE 'Not Completed7' + END) VIRTUAL, +ofis_deg_status8 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress8' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed8' + ELSE 'Not Completed8' + END) VIRTUAL, +deg_start_term char(4) NOT NULL DEFAULT '' COMMENT 'Educated guess at the beginning of the data', +deg_as_of_term char(4) NOT NULL COMMENT 'In most cases also end term', +CONSTRAINT grad_degree_stu_plan_admit_pky PRIMARY KEY (student_id, plan, admit_term) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE INDEX grad_degree_wdraw_rsn_ndx ON grad_degree (wdraw_rsn); +CREATE INDEX grad_degree_as_of_term_ndx ON grad_degree (deg_as_of_term); +INSERT IGNORE grad_degree ( +student_id, +plan, +admit_term, +wdraw_rsn, +deg_start_term, +deg_as_of_term +) +SELECT +ggs.uw_id AS c_student_id, +ggs.plan, +ggs.admit_term, +ggs.wdraw_rsn, +IF( (SELECT COUNT(*) FROM grad_degree AS gd WHERE gd.student_id = ggs.uw_id AND gd.admit_term = ggs.admit_term) > 0, ggs.term, ggs.admit_term ) AS c_deg_start_term, +ggs.term AS c_as_of_term +FROM gso_grad_supr AS ggs +LEFT OUTER JOIN +grad_degree AS gd +ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term ) +WHERE +ggs.term = 1031 AND +gd.student_id IS NULL +; +UPDATE grad_degree AS gd +INNER JOIN +gso_grad_supr AS ggs +ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term ) +SET +gd.wdraw_rsn = ggs.wdraw_rsn, +gd.deg_as_of_term = 1035 +WHERE +gd.wdraw_rsn NOT IN ('DCMP', 'TRDC') AND +ggs.term = 1035 +; +ALTER TABLE grad_degree DROP INDEX grad_degree_wdraw_rsn_ndx; +ALTER TABLE grad_degree DROP COLUMN deg_start_term; +SHOW CREATE TABLE grad_degree; +Table Create Table +grad_degree CREATE TABLE `grad_degree` ( + `student_id` int(8) unsigned NOT NULL, + `plan` varchar(10) NOT NULL, + `admit_term` char(4) NOT NULL, + `wdraw_rsn` varchar(4) NOT NULL DEFAULT '', + `ofis_deg_status` varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed' + ELSE 'Not Completed' + END) VIRTUAL, + `ofis_deg_status2` varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress2' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed2' + ELSE 'Not Completed2' + END) VIRTUAL, + `ofis_deg_status3` varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress3' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed3' + ELSE 'Not Completed3' + END) VIRTUAL, + `ofis_deg_status4` varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress4' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed4' + ELSE 'Not Completed4' + END) VIRTUAL, + `ofis_deg_status5` varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress5' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed5' + ELSE 'Not Completed5' + END) VIRTUAL, + `ofis_deg_status6` varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress6' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed6' + ELSE 'Not Completed6' + END) VIRTUAL, + `ofis_deg_status7` varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress7' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed7' + ELSE 'Not Completed7' + END) VIRTUAL, + `ofis_deg_status8` varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress8' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed8' + ELSE 'Not Completed8' + END) VIRTUAL, + `deg_as_of_term` char(4) NOT NULL COMMENT 'In most cases also end term', + PRIMARY KEY (`student_id`,`plan`,`admit_term`), + KEY `grad_degree_as_of_term_ndx` (`deg_as_of_term`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 +DROP TABLE grad_degree; +CREATE TABLE IF NOT EXISTS grad_degree ( +student_id int(8) UNSIGNED NOT NULL, +plan varchar(10) NOT NULL, +admit_term char(4) NOT NULL, +wdraw_rsn varchar(4) NOT NULL DEFAULT '', +ofis_deg_status varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed' + ELSE 'Not Completed' + END) VIRTUAL, +ofis_deg_status2 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress2' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed2' + ELSE 'Not Completed2' + END) VIRTUAL, +ofis_deg_status3 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress3' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed3' + ELSE 'Not Completed3' + END) VIRTUAL, +ofis_deg_status4 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress4' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed4' + ELSE 'Not Completed4' + END) VIRTUAL, +ofis_deg_status5 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress5' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed5' + ELSE 'Not Completed5' + END) VIRTUAL, +ofis_deg_status6 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress6' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed6' + ELSE 'Not Completed6' + END) VIRTUAL, +ofis_deg_status7 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress7' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed7' + ELSE 'Not Completed7' + END) VIRTUAL, +ofis_deg_status8 varchar(15) AS ( +CASE +WHEN wdraw_rsn = '' THEN 'In progress8' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed8' + ELSE 'Not Completed8' + END) VIRTUAL, +deg_start_term char(4) NOT NULL DEFAULT '' COMMENT 'Educated guess at the beginning of the data', +deg_as_of_term char(4) NOT NULL COMMENT 'In most cases also end term', +CONSTRAINT grad_degree_stu_plan_admit_pky PRIMARY KEY (student_id, plan, admit_term) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE INDEX grad_degree_wdraw_rsn_ndx ON grad_degree (wdraw_rsn); +ALTER TABLE grad_degree DROP COLUMN ofis_deg_status2, DROP COLUMN ofis_deg_status3, +DROP COLUMN ofis_deg_status4, DROP COLUMN ofis_deg_status5, DROP COLUMN ofis_deg_status6, +DROP COLUMN ofis_deg_status7, DROP COLUMN ofis_deg_status8; +CREATE INDEX grad_degree_as_of_term_ndx ON grad_degree (deg_as_of_term); +INSERT IGNORE grad_degree ( +student_id, +plan, +admit_term, +wdraw_rsn, +deg_start_term, +deg_as_of_term +) +SELECT +ggs.uw_id AS c_student_id, +ggs.plan, +ggs.admit_term, +ggs.wdraw_rsn, +IF( (SELECT COUNT(*) FROM grad_degree AS gd WHERE gd.student_id = ggs.uw_id AND gd.admit_term = ggs.admit_term) > 0, ggs.term, ggs.admit_term ) AS c_deg_start_term, +ggs.term AS c_as_of_term +FROM gso_grad_supr AS ggs +LEFT OUTER JOIN +grad_degree AS gd +ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term ) +WHERE +ggs.term = 1031 AND +gd.student_id IS NULL +; +UPDATE grad_degree AS gd +INNER JOIN +gso_grad_supr AS ggs +ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term ) +SET +gd.wdraw_rsn = ggs.wdraw_rsn, +gd.deg_as_of_term = 1035 +WHERE +gd.wdraw_rsn NOT IN ('DCMP', 'TRDC') AND +ggs.term = 1035 +; +select * from grad_degree; +student_id plan admit_term wdraw_rsn ofis_deg_status deg_start_term deg_as_of_term +2 CSM 1009 ACAD Not Completed 1009 1035 +select * from gso_grad_supr; +term uw_id plan wdraw_rsn admit_term +1031 2 CSM 1009 +1035 2 CSM ACAD 1009 +drop table grad_degree; +drop table gso_grad_supr; diff --git a/mysql-test/suite/innodb/t/innodb-virtual-columns.test b/mysql-test/suite/innodb/t/innodb-virtual-columns.test new file mode 100644 index 00000000000..368c6fc8cb1 --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb-virtual-columns.test @@ -0,0 +1,302 @@ +--source include/have_innodb.inc + +# +# MDEV-7367: Updating a virtual column corrupts table which crashes server +# MySQL table columns contains virtual columns but InnoDB table +# definition does not. +# +CREATE TABLE IF NOT EXISTS gso_grad_supr ( + term char(4) NOT NULL DEFAULT '', + uw_id int(8) UNSIGNED NOT NULL DEFAULT 0, + plan varchar(10) NOT NULL DEFAULT '', + wdraw_rsn varchar(4) NOT NULL DEFAULT '', + admit_term char(4) NOT NULL DEFAULT '', + CONSTRAINT gso_grad_supr_pky PRIMARY KEY (uw_id, term) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +INSERT INTO `gso_grad_supr` VALUES ('1031',2,'CSM','','1009'); +INSERT INTO `gso_grad_supr` VALUES ('1035',2,'CSM','ACAD','1009'); + +CREATE TABLE IF NOT EXISTS grad_degree ( + student_id int(8) UNSIGNED NOT NULL, + plan varchar(10) NOT NULL, + admit_term char(4) NOT NULL, + wdraw_rsn varchar(4) NOT NULL DEFAULT '', + ofis_deg_status varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed' + ELSE 'Not Completed' + END) VIRTUAL, + deg_start_term char(4) NOT NULL DEFAULT '' COMMENT 'Educated guess at the beginning of the data', + deg_as_of_term char(4) NOT NULL COMMENT 'In most cases also end term', + CONSTRAINT grad_degree_stu_plan_admit_pky PRIMARY KEY (student_id, plan, admit_term) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE INDEX grad_degree_wdraw_rsn_ndx ON grad_degree (wdraw_rsn); +CREATE INDEX grad_degree_as_of_term_ndx ON grad_degree (deg_as_of_term); + +INSERT IGNORE grad_degree ( + student_id, + plan, + admit_term, + wdraw_rsn, + deg_start_term, + deg_as_of_term +) +SELECT + ggs.uw_id AS c_student_id, + ggs.plan, + ggs.admit_term, + ggs.wdraw_rsn, + IF( (SELECT COUNT(*) FROM grad_degree AS gd WHERE gd.student_id = ggs.uw_id AND gd.admit_term = ggs.admit_term) > 0, ggs.term, ggs.admit_term ) AS c_deg_start_term, + ggs.term AS c_as_of_term +FROM gso_grad_supr AS ggs +LEFT OUTER JOIN + grad_degree AS gd + ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term ) +WHERE + ggs.term = 1031 AND + gd.student_id IS NULL +; + +UPDATE grad_degree AS gd +INNER JOIN + gso_grad_supr AS ggs + ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term ) +SET + gd.wdraw_rsn = ggs.wdraw_rsn, + gd.deg_as_of_term = 1035 +WHERE + gd.wdraw_rsn NOT IN ('DCMP', 'TRDC') AND + ggs.term = 1035 +; + +drop table grad_degree; + +# +# Test with more virtual columns so that MySQL table has +# more columns than InnoDB and index definition is out +# of number of actual InnoDB columns. +# +CREATE TABLE IF NOT EXISTS grad_degree ( + student_id int(8) UNSIGNED NOT NULL, + plan varchar(10) NOT NULL, + admit_term char(4) NOT NULL, + wdraw_rsn varchar(4) NOT NULL DEFAULT '', + ofis_deg_status varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed' + ELSE 'Not Completed' + END) VIRTUAL, + ofis_deg_status2 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress2' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed2' + ELSE 'Not Completed2' + END) VIRTUAL, + ofis_deg_status3 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress3' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed3' + ELSE 'Not Completed3' + END) VIRTUAL, + ofis_deg_status4 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress4' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed4' + ELSE 'Not Completed4' + END) VIRTUAL, + ofis_deg_status5 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress5' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed5' + ELSE 'Not Completed5' + END) VIRTUAL, + ofis_deg_status6 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress6' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed6' + ELSE 'Not Completed6' + END) VIRTUAL, + ofis_deg_status7 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress7' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed7' + ELSE 'Not Completed7' + END) VIRTUAL, + ofis_deg_status8 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress8' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed8' + ELSE 'Not Completed8' + END) VIRTUAL, + deg_start_term char(4) NOT NULL DEFAULT '' COMMENT 'Educated guess at the beginning of the data', + deg_as_of_term char(4) NOT NULL COMMENT 'In most cases also end term', + CONSTRAINT grad_degree_stu_plan_admit_pky PRIMARY KEY (student_id, plan, admit_term) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE INDEX grad_degree_wdraw_rsn_ndx ON grad_degree (wdraw_rsn); +CREATE INDEX grad_degree_as_of_term_ndx ON grad_degree (deg_as_of_term); + +INSERT IGNORE grad_degree ( + student_id, + plan, + admit_term, + wdraw_rsn, + deg_start_term, + deg_as_of_term +) +SELECT + ggs.uw_id AS c_student_id, + ggs.plan, + ggs.admit_term, + ggs.wdraw_rsn, + IF( (SELECT COUNT(*) FROM grad_degree AS gd WHERE gd.student_id = ggs.uw_id AND gd.admit_term = ggs.admit_term) > 0, ggs.term, ggs.admit_term ) AS c_deg_start_term, + ggs.term AS c_as_of_term +FROM gso_grad_supr AS ggs +LEFT OUTER JOIN + grad_degree AS gd + ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term ) +WHERE + ggs.term = 1031 AND + gd.student_id IS NULL +; + +UPDATE grad_degree AS gd +INNER JOIN + gso_grad_supr AS ggs + ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term ) +SET + gd.wdraw_rsn = ggs.wdraw_rsn, + gd.deg_as_of_term = 1035 +WHERE + gd.wdraw_rsn NOT IN ('DCMP', 'TRDC') AND + ggs.term = 1035 +; + +# +# Verify that indexes can be dropped +# +ALTER TABLE grad_degree DROP INDEX grad_degree_wdraw_rsn_ndx; + +# +# Verify that we can drop columns +# +ALTER TABLE grad_degree DROP COLUMN deg_start_term; + +SHOW CREATE TABLE grad_degree; + +DROP TABLE grad_degree; + +# +# Verify after dropping virtual columns +# +CREATE TABLE IF NOT EXISTS grad_degree ( + student_id int(8) UNSIGNED NOT NULL, + plan varchar(10) NOT NULL, + admit_term char(4) NOT NULL, + wdraw_rsn varchar(4) NOT NULL DEFAULT '', + ofis_deg_status varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed' + ELSE 'Not Completed' + END) VIRTUAL, + ofis_deg_status2 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress2' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed2' + ELSE 'Not Completed2' + END) VIRTUAL, + ofis_deg_status3 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress3' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed3' + ELSE 'Not Completed3' + END) VIRTUAL, + ofis_deg_status4 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress4' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed4' + ELSE 'Not Completed4' + END) VIRTUAL, + ofis_deg_status5 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress5' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed5' + ELSE 'Not Completed5' + END) VIRTUAL, + ofis_deg_status6 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress6' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed6' + ELSE 'Not Completed6' + END) VIRTUAL, + ofis_deg_status7 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress7' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed7' + ELSE 'Not Completed7' + END) VIRTUAL, + ofis_deg_status8 varchar(15) AS ( + CASE + WHEN wdraw_rsn = '' THEN 'In progress8' + WHEN wdraw_rsn = 'DCMP' OR wdraw_rsn = 'TRDC' THEN 'Completed8' + ELSE 'Not Completed8' + END) VIRTUAL, + deg_start_term char(4) NOT NULL DEFAULT '' COMMENT 'Educated guess at the beginning of the data', + deg_as_of_term char(4) NOT NULL COMMENT 'In most cases also end term', + CONSTRAINT grad_degree_stu_plan_admit_pky PRIMARY KEY (student_id, plan, admit_term) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE INDEX grad_degree_wdraw_rsn_ndx ON grad_degree (wdraw_rsn); + +ALTER TABLE grad_degree DROP COLUMN ofis_deg_status2, DROP COLUMN ofis_deg_status3, +DROP COLUMN ofis_deg_status4, DROP COLUMN ofis_deg_status5, DROP COLUMN ofis_deg_status6, +DROP COLUMN ofis_deg_status7, DROP COLUMN ofis_deg_status8; + +CREATE INDEX grad_degree_as_of_term_ndx ON grad_degree (deg_as_of_term); + +INSERT IGNORE grad_degree ( + student_id, + plan, + admit_term, + wdraw_rsn, + deg_start_term, + deg_as_of_term +) +SELECT + ggs.uw_id AS c_student_id, + ggs.plan, + ggs.admit_term, + ggs.wdraw_rsn, + IF( (SELECT COUNT(*) FROM grad_degree AS gd WHERE gd.student_id = ggs.uw_id AND gd.admit_term = ggs.admit_term) > 0, ggs.term, ggs.admit_term ) AS c_deg_start_term, + ggs.term AS c_as_of_term +FROM gso_grad_supr AS ggs +LEFT OUTER JOIN + grad_degree AS gd + ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term ) +WHERE + ggs.term = 1031 AND + gd.student_id IS NULL +; + +UPDATE grad_degree AS gd +INNER JOIN + gso_grad_supr AS ggs + ON ( gd.student_id = ggs.uw_id AND gd.plan = ggs.plan AND gd.admit_term = ggs.admit_term ) +SET + gd.wdraw_rsn = ggs.wdraw_rsn, + gd.deg_as_of_term = 1035 +WHERE + gd.wdraw_rsn NOT IN ('DCMP', 'TRDC') AND + ggs.term = 1035 +; + +select * from grad_degree; +select * from gso_grad_supr; + +drop table grad_degree; +drop table gso_grad_supr; diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 7c3c4e824d5..c87ecfe8fa6 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -648,6 +648,40 @@ dict_table_get_col_name( return(s); } +/**********************************************************************//** +Returns a column's name. +@return column name. NOTE: not guaranteed to stay valid if table is +modified in any way (columns added, etc.). */ +UNIV_INTERN +const char* +dict_table_get_col_name_for_mysql( +/*==============================*/ + const dict_table_t* table, /*!< in: table */ + const char* col_name)/*! in: MySQL table column name */ +{ + ulint i; + const char* s; + + ut_ad(table); + ut_ad(col_name); + ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); + + s = table->col_names; + if (s) { + /* If we have many virtual columns MySQL key_part->fieldnr + could be larger than number of columns in InnoDB table + when creating new indexes. */ + for (i = 0; i < table->n_def; i++) { + + if (!innobase_strcasecmp(s, col_name)) { + break; /* Found */ + } + s += strlen(s) + 1; + } + } + + return(s); +} #ifndef UNIV_HOTBACKUP /********************************************************************//** Acquire the autoinc lock. */ diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index fde94a15a28..e86949198f8 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -4785,6 +4785,8 @@ innobase_match_index_columns( if (innodb_idx_fld >= innodb_idx_fld_end) { DBUG_RETURN(FALSE); } + + mtype = innodb_idx_fld->col->mtype; } // MariaDB-5.5 compatibility diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 76d68bb9676..3f393d9d431 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -1441,8 +1441,9 @@ innobase_create_index_field_def( if a new clustered index is not being created */ const KEY_PART_INFO* key_part, /*!< in: MySQL key definition */ - index_field_t* index_field) /*!< out: index field + index_field_t* index_field, /*!< out: index field definition for key_part */ + const Field** fields) /*!< in: MySQL table fields */ { const Field* field; ibool is_unsigned; @@ -1459,6 +1460,7 @@ innobase_create_index_field_def( ut_a(field); index_field->col_no = key_part->fieldnr; + index_field->col_name = altered_table ? field->field_name : fields[key_part->fieldnr]->field_name; col_type = get_innobase_type_from_mysql_type(&is_unsigned, field); @@ -1493,8 +1495,9 @@ innobase_create_index_def( bool key_clustered, /*!< in: true if this is the new clustered index */ index_def_t* index, /*!< out: index definition */ - mem_heap_t* heap) /*!< in: heap where memory + mem_heap_t* heap, /*!< in: heap where memory is allocated */ + const Field** fields) /*!z in: MySQL table fields */ { const KEY* key = &keys[key_number]; ulint i; @@ -1507,6 +1510,7 @@ innobase_create_index_def( index->fields = static_cast( mem_heap_alloc(heap, n_fields * sizeof *index->fields)); + memset(index->fields, 0, n_fields * sizeof *index->fields); index->ind_type = 0; index->key_number = key_number; @@ -1544,7 +1548,7 @@ innobase_create_index_def( for (i = 0; i < n_fields; i++) { innobase_create_index_field_def( - altered_table, &key->key_part[i], &index->fields[i]); + altered_table, &key->key_part[i], &index->fields[i], fields); } DBUG_VOID_RETURN; @@ -1875,7 +1879,7 @@ innobase_create_key_defs( /* Create the PRIMARY key index definition */ innobase_create_index_def( altered_table, key_info, primary_key_number, - TRUE, TRUE, indexdef++, heap); + TRUE, TRUE, indexdef++, heap, (const Field **)altered_table->field); created_clustered: n_add = 1; @@ -1887,7 +1891,7 @@ created_clustered: /* Copy the index definitions. */ innobase_create_index_def( altered_table, key_info, i, TRUE, FALSE, - indexdef, heap); + indexdef, heap, (const Field **)altered_table->field); if (indexdef->ind_type & DICT_FTS) { n_fts_add++; @@ -1932,7 +1936,7 @@ created_clustered: for (ulint i = 0; i < n_add; i++) { innobase_create_index_def( altered_table, key_info, add[i], FALSE, FALSE, - indexdef, heap); + indexdef, heap, (const Field **)altered_table->field); if (indexdef->ind_type & DICT_FTS) { n_fts_add++; @@ -1949,6 +1953,7 @@ created_clustered: index->fields = static_cast( mem_heap_alloc(heap, sizeof *index->fields)); + memset(index->fields, 0, sizeof *index->fields); index->n_fields = 1; index->fields->col_no = fts_doc_id_col; index->fields->prefix_len = 0; diff --git a/storage/innobase/include/dict0dict.h b/storage/innobase/include/dict0dict.h index d2514ea78b6..9e007809471 100644 --- a/storage/innobase/include/dict0dict.h +++ b/storage/innobase/include/dict0dict.h @@ -597,6 +597,17 @@ dict_table_get_col_name( ulint col_nr) /*!< in: column number */ __attribute__((nonnull, warn_unused_result)); /**********************************************************************//** +Returns a column's name. +@return column name. NOTE: not guaranteed to stay valid if table is +modified in any way (columns added, etc.). */ +UNIV_INTERN +const char* +dict_table_get_col_name_for_mysql( +/*==============================*/ + const dict_table_t* table, /*!< in: table */ + const char* col_name)/*!< in: MySQL table column name */ + __attribute__((nonnull, warn_unused_result)); +/**********************************************************************//** Prints a table data. */ UNIV_INTERN void diff --git a/storage/innobase/include/row0merge.h b/storage/innobase/include/row0merge.h index 2b9e9f7711c..de353d46202 100644 --- a/storage/innobase/include/row0merge.h +++ b/storage/innobase/include/row0merge.h @@ -95,6 +95,7 @@ struct index_field_t { ulint col_no; /*!< column offset */ ulint prefix_len; /*!< column prefix length, or 0 if indexing the whole column */ + const char* col_name; /*!< column name or NULL */ }; /** Definition of an index being created */ diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index 1c8b65a5696..806f5b977d4 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -3336,9 +3336,13 @@ row_merge_create_index( for (i = 0; i < n_fields; i++) { index_field_t* ifield = &index_def->fields[i]; + const char * col_name = ifield->col_name ? + dict_table_get_col_name_for_mysql(table, ifield->col_name) : + dict_table_get_col_name(table, ifield->col_no); dict_mem_index_add_field( - index, dict_table_get_col_name(table, ifield->col_no), + index, + col_name, ifield->prefix_len); } diff --git a/storage/xtradb/dict/dict0dict.cc b/storage/xtradb/dict/dict0dict.cc index 6b628198275..cd0f3ef57d1 100644 --- a/storage/xtradb/dict/dict0dict.cc +++ b/storage/xtradb/dict/dict0dict.cc @@ -648,6 +648,40 @@ dict_table_get_col_name( return(s); } +/**********************************************************************//** +Returns a column's name. +@return column name. NOTE: not guaranteed to stay valid if table is +modified in any way (columns added, etc.). */ +UNIV_INTERN +const char* +dict_table_get_col_name_for_mysql( +/*==============================*/ + const dict_table_t* table, /*!< in: table */ + const char* col_name)/*! in: MySQL table column name */ +{ + ulint i; + const char* s; + + ut_ad(table); + ut_ad(col_name); + ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); + + s = table->col_names; + if (s) { + /* If we have many virtual columns MySQL key_part->fieldnr + could be larger than number of columns in InnoDB table + when creating new indexes. */ + for (i = 0; i < table->n_def; i++) { + + if (!innobase_strcasecmp(s, col_name)) { + break; /* Found */ + } + s += strlen(s) + 1; + } + } + + return(s); +} #ifndef UNIV_HOTBACKUP /********************************************************************//** Acquire the autoinc lock. */ diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index aaeebf91e24..88ecb584475 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -5333,6 +5333,8 @@ innobase_match_index_columns( if (innodb_idx_fld >= innodb_idx_fld_end) { DBUG_RETURN(FALSE); } + + mtype = innodb_idx_fld->col->mtype; } if (col_type != mtype) { diff --git a/storage/xtradb/handler/handler0alter.cc b/storage/xtradb/handler/handler0alter.cc index bb58a92ed1a..b3a41ae70da 100644 --- a/storage/xtradb/handler/handler0alter.cc +++ b/storage/xtradb/handler/handler0alter.cc @@ -1442,8 +1442,9 @@ innobase_create_index_field_def( if a new clustered index is not being created */ const KEY_PART_INFO* key_part, /*!< in: MySQL key definition */ - index_field_t* index_field) /*!< out: index field + index_field_t* index_field, /*!< out: index field definition for key_part */ + const Field** fields) /*!< in: MySQL table fields */ { const Field* field; ibool is_unsigned; @@ -1460,6 +1461,7 @@ innobase_create_index_field_def( ut_a(field); index_field->col_no = key_part->fieldnr; + index_field->col_name = altered_table ? field->field_name : fields[key_part->fieldnr]->field_name; col_type = get_innobase_type_from_mysql_type(&is_unsigned, field); @@ -1494,8 +1496,9 @@ innobase_create_index_def( bool key_clustered, /*!< in: true if this is the new clustered index */ index_def_t* index, /*!< out: index definition */ - mem_heap_t* heap) /*!< in: heap where memory + mem_heap_t* heap, /*!< in: heap where memory is allocated */ + const Field** fields) /*!z in: MySQL table fields */ { const KEY* key = &keys[key_number]; ulint i; @@ -1509,6 +1512,8 @@ innobase_create_index_def( index->fields = static_cast( mem_heap_alloc(heap, n_fields * sizeof *index->fields)); + memset(index->fields, 0, n_fields * sizeof *index->fields); + index->ind_type = 0; index->key_number = key_number; index->n_fields = n_fields; @@ -1545,7 +1550,7 @@ innobase_create_index_def( for (i = 0; i < n_fields; i++) { innobase_create_index_field_def( - altered_table, &key->key_part[i], &index->fields[i]); + altered_table, &key->key_part[i], &index->fields[i], fields); } DBUG_VOID_RETURN; @@ -1876,7 +1881,7 @@ innobase_create_key_defs( /* Create the PRIMARY key index definition */ innobase_create_index_def( altered_table, key_info, primary_key_number, - TRUE, TRUE, indexdef++, heap); + TRUE, TRUE, indexdef++, heap, (const Field **)altered_table->field); created_clustered: n_add = 1; @@ -1888,7 +1893,7 @@ created_clustered: /* Copy the index definitions. */ innobase_create_index_def( altered_table, key_info, i, TRUE, FALSE, - indexdef, heap); + indexdef, heap, (const Field **)altered_table->field); if (indexdef->ind_type & DICT_FTS) { n_fts_add++; @@ -1933,7 +1938,7 @@ created_clustered: for (ulint i = 0; i < n_add; i++) { innobase_create_index_def( altered_table, key_info, add[i], FALSE, FALSE, - indexdef, heap); + indexdef, heap, (const Field **)altered_table->field); if (indexdef->ind_type & DICT_FTS) { n_fts_add++; @@ -1950,6 +1955,7 @@ created_clustered: index->fields = static_cast( mem_heap_alloc(heap, sizeof *index->fields)); + memset(index->fields, 0, sizeof *index->fields); index->n_fields = 1; index->fields->col_no = fts_doc_id_col; index->fields->prefix_len = 0; diff --git a/storage/xtradb/include/dict0dict.h b/storage/xtradb/include/dict0dict.h index 88203595108..def7b246ead 100644 --- a/storage/xtradb/include/dict0dict.h +++ b/storage/xtradb/include/dict0dict.h @@ -597,6 +597,17 @@ dict_table_get_col_name( ulint col_nr) /*!< in: column number */ __attribute__((nonnull, warn_unused_result)); /**********************************************************************//** +Returns a column's name. +@return column name. NOTE: not guaranteed to stay valid if table is +modified in any way (columns added, etc.). */ +UNIV_INTERN +const char* +dict_table_get_col_name_for_mysql( +/*==============================*/ + const dict_table_t* table, /*!< in: table */ + const char* col_name)/*!< in: MySQL table column name */ + __attribute__((nonnull, warn_unused_result)); +/**********************************************************************//** Prints a table data. */ UNIV_INTERN void diff --git a/storage/xtradb/include/row0merge.h b/storage/xtradb/include/row0merge.h index 390c0ce038b..57b93b307cd 100644 --- a/storage/xtradb/include/row0merge.h +++ b/storage/xtradb/include/row0merge.h @@ -95,6 +95,7 @@ struct index_field_t { ulint col_no; /*!< column offset */ ulint prefix_len; /*!< column prefix length, or 0 if indexing the whole column */ + const char* col_name; /*!< column name or NULL */ }; /** Definition of an index being created */ diff --git a/storage/xtradb/row/row0merge.cc b/storage/xtradb/row/row0merge.cc index 5d88d750478..ecbea7fcb87 100644 --- a/storage/xtradb/row/row0merge.cc +++ b/storage/xtradb/row/row0merge.cc @@ -3342,9 +3342,13 @@ row_merge_create_index( for (i = 0; i < n_fields; i++) { index_field_t* ifield = &index_def->fields[i]; + const char * col_name = ifield->col_name ? + dict_table_get_col_name_for_mysql(table, ifield->col_name) : + dict_table_get_col_name(table, ifield->col_no); dict_mem_index_add_field( - index, dict_table_get_col_name(table, ifield->col_no), + index, + col_name, ifield->prefix_len); } From e9c10f9916594eb0718710573b1740d4b87c1879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 6 Apr 2015 17:38:51 +0300 Subject: [PATCH 11/13] MDEV-7908: assertion in innobase_release_savepoint Problem was that in XA prepared state we should still be able to release a savepoint, but assertions were too strict. --- mysql-test/suite/innodb/r/innodb-xa.result | 17 +++++++++++++++++ mysql-test/suite/innodb/t/innodb-xa.test | 17 +++++++++++++++++ storage/innobase/handler/ha_innodb.cc | 5 ++++- storage/innobase/trx/trx0roll.cc | 2 +- storage/xtradb/handler/ha_innodb.cc | 5 ++++- storage/xtradb/trx/trx0roll.cc | 2 +- 6 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 mysql-test/suite/innodb/r/innodb-xa.result create mode 100644 mysql-test/suite/innodb/t/innodb-xa.test diff --git a/mysql-test/suite/innodb/r/innodb-xa.result b/mysql-test/suite/innodb/r/innodb-xa.result new file mode 100644 index 00000000000..6eae842b14c --- /dev/null +++ b/mysql-test/suite/innodb/r/innodb-xa.result @@ -0,0 +1,17 @@ +xa rollback 'xid2'; +ERROR XAE04: XAER_NOTA: Unknown XID +drop table if exists t1; +Warnings: +Note 1051 Unknown table 'test.t1' +create table t1(a int)engine=innodb; +rollback; +xa start 'xid2'; +insert into `t1` values (1); +savepoint `sv1`; +xa end 'xid2'; +start transaction; +ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the IDLE state +xa prepare 'xid2'; +release savepoint `sv1`; +xa commit 'xid2'; +drop table t1; diff --git a/mysql-test/suite/innodb/t/innodb-xa.test b/mysql-test/suite/innodb/t/innodb-xa.test new file mode 100644 index 00000000000..d94cd75aa14 --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb-xa.test @@ -0,0 +1,17 @@ +--source include/have_innodb.inc + +--disable_abort_on_error +xa rollback 'xid2'; +drop table if exists t1; +create table t1(a int)engine=innodb; +rollback; +xa start 'xid2'; +insert into `t1` values (1); +savepoint `sv1`; +xa end 'xid2'; +start transaction; +xa prepare 'xid2'; +release savepoint `sv1`; +xa commit 'xid2'; +drop table t1; + diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index e86949198f8..de78a39f154 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -4116,7 +4116,10 @@ innobase_release_savepoint( DBUG_ASSERT(hton == innodb_hton_ptr); trx = check_trx_exists(thd); - trx_start_if_not_started(trx); + + if (trx->state == TRX_STATE_NOT_STARTED) { + trx_start_if_not_started(trx); + } /* TODO: use provided savepoint data area to store savepoint data */ diff --git a/storage/innobase/trx/trx0roll.cc b/storage/innobase/trx/trx0roll.cc index bc11f1d76bd..e2c3c0b949c 100644 --- a/storage/innobase/trx/trx0roll.cc +++ b/storage/innobase/trx/trx0roll.cc @@ -495,7 +495,7 @@ trx_release_savepoint_for_mysql( { trx_named_savept_t* savep; - ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE)); + ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE) || trx_state_eq(trx, TRX_STATE_PREPARED)); ut_ad(trx->in_mysql_trx_list); savep = trx_savepoint_find(trx, savepoint_name); diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index 88ecb584475..ecc3d1c17eb 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -4679,7 +4679,10 @@ innobase_release_savepoint( DBUG_ASSERT(hton == innodb_hton_ptr); trx = check_trx_exists(thd); - trx_start_if_not_started(trx); + + if (trx->state == TRX_STATE_NOT_STARTED) { + trx_start_if_not_started(trx); + } /* TODO: use provided savepoint data area to store savepoint data */ diff --git a/storage/xtradb/trx/trx0roll.cc b/storage/xtradb/trx/trx0roll.cc index a64367c4ba7..79379741493 100644 --- a/storage/xtradb/trx/trx0roll.cc +++ b/storage/xtradb/trx/trx0roll.cc @@ -492,7 +492,7 @@ trx_release_savepoint_for_mysql( { trx_named_savept_t* savep; - ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE)); + ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE) || trx_state_eq(trx, TRX_STATE_PREPARED)); ut_ad(trx->in_mysql_trx_list); savep = trx_savepoint_find(trx, savepoint_name); From 87d543831d2d1f89fd5b122de24591f9d9b91d13 Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Mon, 20 Apr 2015 02:43:26 +0300 Subject: [PATCH 12/13] Increase the version number --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 7c9ccd7a423..c5742a56786 100644 --- a/VERSION +++ b/VERSION @@ -1,3 +1,3 @@ MYSQL_VERSION_MAJOR=10 MYSQL_VERSION_MINOR=0 -MYSQL_VERSION_PATCH=17 +MYSQL_VERSION_PATCH=18 From 519ad0f7e35ff4dd13aac3c13da44c649f724352 Mon Sep 17 00:00:00 2001 From: Kristian Nielsen Date: Mon, 20 Apr 2015 12:59:46 +0200 Subject: [PATCH 13/13] MDEV-8016: Replication aborts on DROP /*!40005 TEMPORARY */ TABLE IF EXISTS This was a regression from the patch for MDEV-7668. A test was incorrect, so the slave would not properly handle re-using temporary tables, which lead to replication failure in this case. --- mysql-test/suite/rpl/r/rpl_temp_table.result | 5 +++++ mysql-test/suite/rpl/t/rpl_temp_table.test | 16 ++++++++++++++++ sql/sql_base.cc | 7 +++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_temp_table.result b/mysql-test/suite/rpl/r/rpl_temp_table.result index 504b0471748..08504ce175d 100644 --- a/mysql-test/suite/rpl/r/rpl_temp_table.result +++ b/mysql-test/suite/rpl/r/rpl_temp_table.result @@ -39,7 +39,12 @@ sum(n) show status like 'Slave_open_temp_tables'; Variable_name Value Slave_open_temp_tables 0 +*** MDEV-8016: Replication aborts on DROP /*!40005 TEMPORARY */ TABLE IF EXISTS *** +INSERT INTO t2 VALUES (2000), (2001); +CREATE FUNCTION f() RETURNS INTEGER RETURN 1; +CREATE TEMPORARY TABLE t3 AS SELECT f() AS col FROM t2; drop table if exists t1,t2; Warnings: Note 1051 Unknown table 'test.t1' +drop function f; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_temp_table.test b/mysql-test/suite/rpl/t/rpl_temp_table.test index 92f8cef9c10..8b3af5d51cd 100644 --- a/mysql-test/suite/rpl/t/rpl_temp_table.test +++ b/mysql-test/suite/rpl/t/rpl_temp_table.test @@ -57,12 +57,28 @@ select count(*) from t2; select sum(n) from t2; show status like 'Slave_open_temp_tables'; +--echo *** MDEV-8016: Replication aborts on DROP /*!40005 TEMPORARY */ TABLE IF EXISTS *** +connect (master2,localhost,root,,); +INSERT INTO t2 VALUES (2000), (2001); +CREATE FUNCTION f() RETURNS INTEGER RETURN 1; +CREATE TEMPORARY TABLE t3 AS SELECT f() AS col FROM t2; +--let $gtid=`SELECT @@gtid_binlog_pos` +--disconnect master2 +--connection default +# Wait for implicit DROP TEMPORARY TABLE tmp to be binlogged. +--let $wait_condition= SELECT @@gtid_binlog_pos != '$gtid' +--source include/wait_condition.inc + +--sync_slave_with_master + + # # Clean up # connect (master2,localhost,root,,); connection master2; drop table if exists t1,t2; +drop function f; sync_slave_with_master; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 244791da23f..f337b3b6283 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -653,6 +653,7 @@ bool close_cached_connection_tables(THD *thd, LEX_STRING *connection) static void mark_temp_tables_as_free_for_reuse(THD *thd) { + rpl_group_info *rgi_slave; DBUG_ENTER("mark_temp_tables_as_free_for_reuse"); if (thd->query_id == 0) @@ -661,7 +662,9 @@ static void mark_temp_tables_as_free_for_reuse(THD *thd) DBUG_VOID_RETURN; } - if (thd->temporary_tables) + rgi_slave=thd->rgi_slave; + if ((!rgi_slave && thd->temporary_tables) || + (rgi_slave && unlikely(rgi_slave->rli->save_temporary_tables))) { thd->lock_temporary_tables(); for (TABLE *table= thd->temporary_tables ; table ; table= table->next) @@ -670,7 +673,7 @@ static void mark_temp_tables_as_free_for_reuse(THD *thd) mark_tmp_table_for_reuse(table); } thd->unlock_temporary_tables(); - if (thd->rgi_slave) + if (rgi_slave) { /* Temporary tables are shared with other by sql execution threads.