diff --git a/mysql-test/main/create_replace_tmp.result b/mysql-test/main/create_replace_tmp.result new file mode 100644 index 0000000000000..0239f4d481741 --- /dev/null +++ b/mysql-test/main/create_replace_tmp.result @@ -0,0 +1,4 @@ +CREATE TEMPORARY TABLE t (i INT); +CREATE or replace TABLE t AS SELECT * FROM t; +DROP TEMPORARY TABLE t; +DROP TABLE t; diff --git a/mysql-test/main/create_replace_tmp.test b/mysql-test/main/create_replace_tmp.test new file mode 100644 index 0000000000000..0239f4d481741 --- /dev/null +++ b/mysql-test/main/create_replace_tmp.test @@ -0,0 +1,4 @@ +CREATE TEMPORARY TABLE t (i INT); +CREATE or replace TABLE t AS SELECT * FROM t; +DROP TEMPORARY TABLE t; +DROP TABLE t; diff --git a/mysql-test/main/cte_recursive_not_embedded.result b/mysql-test/main/cte_recursive_not_embedded.result new file mode 100644 index 0000000000000..202864be15949 --- /dev/null +++ b/mysql-test/main/cte_recursive_not_embedded.result @@ -0,0 +1,23 @@ +# +# MDEV-15151: function with recursive CTE using no base tables +# (duplicate of MDEV-16661) +# +connection default; +CREATE TABLE t1 (id int KEY); +INSERT INTO t1 VALUES (0), (1),(2); +CREATE OR REPLACE FUNCTION func() RETURNS int +RETURN +( +WITH recursive cte AS +(SELECT 1 a UNION SELECT cte.* FROM cte natural join t1) +SELECT * FROM cte limit 1 +); +connect con1,localhost,root,,test; +SELECT func(); +connect con2,localhost,root,,test; +disconnect con2; +connection con1; +disconnect con1; +connection default; +DROP FUNCTION func; +DROP TABLE t1; diff --git a/mysql-test/main/cte_recursive_not_embedded.test b/mysql-test/main/cte_recursive_not_embedded.test new file mode 100644 index 0000000000000..4dadf400681bc --- /dev/null +++ b/mysql-test/main/cte_recursive_not_embedded.test @@ -0,0 +1,42 @@ +--source include/not_embedded.inc + +--echo # +--echo # MDEV-15151: function with recursive CTE using no base tables +--echo # (duplicate of MDEV-16661) +--echo # + +--connection default + +CREATE TABLE t1 (id int KEY); +INSERT INTO t1 VALUES (0), (1),(2); + +CREATE OR REPLACE FUNCTION func() RETURNS int +RETURN +( + WITH recursive cte AS + (SELECT 1 a UNION SELECT cte.* FROM cte natural join t1) + SELECT * FROM cte limit 1 +); + +--connect (con1,localhost,root,,test) + +--let $conid= `SELECT CONNECTION_ID()` +--send SELECT func() + +--connect (con2,localhost,root,,test) +--disable_query_log +--eval KILL QUERY $conid +--enable_query_log +--disconnect con2 + +--disable_result_log +--connection con1 +--error 0,ER_QUERY_INTERRUPTED +--reap +--disconnect con1 +--enable_result_log + +--connection default + +DROP FUNCTION func; +DROP TABLE t1; diff --git a/mysql-test/suite/rpl/r/rpl_15867.result b/mysql-test/suite/rpl/r/rpl_15867.result new file mode 100644 index 0000000000000..9cb63266a292f --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_15867.result @@ -0,0 +1,9 @@ +include/master-slave.inc +[connection master] +CREATE TEMPORARY TABLE t (i INT); +CREATE TABLE t AS SELECT * FROM t; +connection slave; +connection master; +DROP TEMPORARY TABLE t; +DROP TABLE t; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_15867.test b/mysql-test/suite/rpl/t/rpl_15867.test new file mode 100644 index 0000000000000..6de39041bb120 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_15867.test @@ -0,0 +1,11 @@ +--source include/master-slave.inc +CREATE TEMPORARY TABLE t (i INT); +CREATE TABLE t AS SELECT * FROM t; + +--sync_slave_with_master + +# Cleanup +--connection master +DROP TEMPORARY TABLE t; +DROP TABLE t; +--source include/rpl_end.inc diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 490f21aa9509c..943d66d55f210 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1039,6 +1039,12 @@ TABLE_LIST* find_dup_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list, if (res->table && (res->table == table->table)) continue; + /* Skip if table is tmp table */ + if (check_flag & CHECK_DUP_SKIP_TEMP_TABLE && + res->table && res->table->s->tmp_table != NO_TMP_TABLE) + { + continue; + } if (check_flag & CHECK_DUP_FOR_CREATE) DBUG_RETURN(res); diff --git a/sql/sql_base.h b/sql/sql_base.h index 01892c0b93896..be93566be09dd 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -64,6 +64,7 @@ enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND, /* Flag bits for unique_table() */ #define CHECK_DUP_ALLOW_DIFFERENT_ALIAS 1 #define CHECK_DUP_FOR_CREATE 2 +#define CHECK_DUP_SKIP_TEMP_TABLE 4 uint get_table_def_key(const TABLE_LIST *table_list, const char **key); TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update, diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index a1cacbd35a2ed..d8f4f492903b9 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4196,7 +4196,8 @@ mysql_execute_command(THD *thd) TABLE_LIST *duplicate; if (unlikely((duplicate= unique_table(thd, lex->query_tables, lex->query_tables->next_global, - CHECK_DUP_FOR_CREATE)))) + CHECK_DUP_FOR_CREATE | + CHECK_DUP_SKIP_TEMP_TABLE)))) { update_non_unique_table_error(lex->query_tables, "CREATE", duplicate); diff --git a/storage/innobase/btr/btr0sea.cc b/storage/innobase/btr/btr0sea.cc index c3b30e4d033f6..db9e028b8f369 100644 --- a/storage/innobase/btr/btr0sea.cc +++ b/storage/innobase/btr/btr0sea.cc @@ -570,10 +570,9 @@ static bool btr_search_update_block_hash_info(btr_search_t* info, buf_block_t* block) { - ut_ad(!btr_search_own_any(RW_LOCK_S)); - ut_ad(!btr_search_own_any(RW_LOCK_X)); - ut_ad(rw_lock_own(&block->lock, RW_LOCK_S) - || rw_lock_own(&block->lock, RW_LOCK_X)); + ut_ad(!btr_search_own_any()); + ut_ad(rw_lock_own_flagged(&block->lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); info->last_hash_succ = FALSE; @@ -648,8 +647,8 @@ btr_search_update_hash_ref( ut_ad(cursor->flag == BTR_CUR_HASH_FAIL); ut_ad(rw_lock_own(btr_get_search_latch(cursor->index), RW_LOCK_X)); - ut_ad(rw_lock_own(&(block->lock), RW_LOCK_S) - || rw_lock_own(&(block->lock), RW_LOCK_X)); + ut_ad(rw_lock_own_flagged(&block->lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); ut_ad(page_align(btr_cur_get_rec(cursor)) == block->frame); ut_ad(page_is_leaf(block->frame)); assert_block_ahi_valid(block); @@ -887,8 +886,8 @@ btr_search_guess_on_hash( btr_cur_t cursor2; btr_pcur_t pcur; #endif - ut_ad(!ahi_latch || rw_lock_own(ahi_latch, RW_LOCK_S) - || rw_lock_own(ahi_latch, RW_LOCK_X)); + ut_ad(!ahi_latch || rw_lock_own_flagged( + ahi_latch, RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); if (!btr_search_enabled) { return(FALSE); @@ -1109,8 +1108,8 @@ void btr_search_drop_page_hash_index(buf_block_t* block) ut_ad(block->page.buf_fix_count == 0 || buf_block_get_state(block) == BUF_BLOCK_REMOVE_HASH - || rw_lock_own(&block->lock, RW_LOCK_S) - || rw_lock_own(&block->lock, RW_LOCK_X)); + || rw_lock_own_flagged(&block->lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); ut_ad(page_is_leaf(block->frame)); /* We must not dereference index here, because it could be freed @@ -1363,8 +1362,8 @@ btr_search_build_page_hash_index( ut_a(!dict_index_is_ibuf(index)); ut_ad(page_is_leaf(block->frame)); - ut_ad(rw_lock_own(&(block->lock), RW_LOCK_S) - || rw_lock_own(&(block->lock), RW_LOCK_X)); + ut_ad(rw_lock_own_flagged(&block->lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); rw_lock_s_lock(ahi_latch); @@ -1531,8 +1530,8 @@ btr_search_info_update_slow(btr_search_t* info, btr_cur_t* cursor) { rw_lock_t* ahi_latch = btr_get_search_latch(cursor->index); - ut_ad(!rw_lock_own(ahi_latch, RW_LOCK_S)); - ut_ad(!rw_lock_own(ahi_latch, RW_LOCK_X)); + ut_ad(!rw_lock_own_flagged(ahi_latch, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); buf_block_t* block = btr_cur_get_block(cursor); diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 6e88e0f72eebe..f053c170c0e77 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -4498,8 +4498,9 @@ buf_page_get_gen( case BUF_GET_IF_IN_POOL_OR_WATCH: case BUF_PEEK_IF_IN_POOL: case BUF_EVICT_IF_IN_POOL: - ut_ad(!rw_lock_own(hash_lock, RW_LOCK_X)); - ut_ad(!rw_lock_own(hash_lock, RW_LOCK_S)); + ut_ad(!rw_lock_own_flagged( + hash_lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); return(NULL); } @@ -4840,8 +4841,8 @@ buf_page_get_gen( ut_ad(block == fix_block); ut_ad(fix_block->page.buf_fix_count > 0); - ut_ad(!rw_lock_own(hash_lock, RW_LOCK_X)); - ut_ad(!rw_lock_own(hash_lock, RW_LOCK_S)); + ut_ad(!rw_lock_own_flagged(hash_lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); ut_ad(buf_block_get_state(fix_block) == BUF_BLOCK_FILE_PAGE); @@ -5015,8 +5016,8 @@ buf_page_get_gen( ut_a(ibuf_count_get(fix_block->page.id) == 0); #endif - ut_ad(!rw_lock_own(hash_lock, RW_LOCK_X)); - ut_ad(!rw_lock_own(hash_lock, RW_LOCK_S)); + ut_ad(!rw_lock_own_flagged(hash_lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); return(fix_block); } @@ -5688,8 +5689,8 @@ buf_page_init_for_read( ibuf_mtr_commit(&mtr); } - ut_ad(!rw_lock_own(hash_lock, RW_LOCK_X)); - ut_ad(!rw_lock_own(hash_lock, RW_LOCK_S)); + ut_ad(!rw_lock_own_flagged(hash_lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); ut_ad(!bpage || buf_page_in_file(bpage)); return(bpage); diff --git a/storage/innobase/buf/buf0lru.cc b/storage/innobase/buf/buf0lru.cc index bf0891840f8a3..ebd5c2a828b52 100644 --- a/storage/innobase/buf/buf0lru.cc +++ b/storage/innobase/buf/buf0lru.cc @@ -1629,8 +1629,8 @@ buf_LRU_free_page( } /* buf_LRU_block_remove_hashed() releases the hash_lock */ - ut_ad(!rw_lock_own(hash_lock, RW_LOCK_X) - && !rw_lock_own(hash_lock, RW_LOCK_S)); + ut_ad(!rw_lock_own_flagged(hash_lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); /* We have just freed a BUF_BLOCK_FILE_PAGE. If b != NULL then it was a compressed page with an uncompressed frame and @@ -2183,9 +2183,8 @@ buf_LRU_free_one_page( } /* buf_LRU_block_remove_hashed() releases hash_lock and block_mutex */ - ut_ad(!rw_lock_own(hash_lock, RW_LOCK_X) - && !rw_lock_own(hash_lock, RW_LOCK_S)); - + ut_ad(!rw_lock_own_flagged(hash_lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); ut_ad(!mutex_own(block_mutex)); } diff --git a/storage/innobase/gis/gis0sea.cc b/storage/innobase/gis/gis0sea.cc index 4f24f29819643..67b2feb7af6b8 100644 --- a/storage/innobase/gis/gis0sea.cc +++ b/storage/innobase/gis/gis0sea.cc @@ -257,9 +257,8 @@ rtr_pcur_getnext_from_path( rtr_info->tree_savepoints[tree_idx] = mtr_set_savepoint(mtr); #ifdef UNIV_RTR_DEBUG - ut_ad(!(rw_lock_own(&btr_cur->page_cur.block->lock, RW_LOCK_X) - || - rw_lock_own(&btr_cur->page_cur.block->lock, RW_LOCK_S)) + ut_ad(!(rw_lock_own_flagged(&btr_cur->page_cur.block->lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)) || my_latch_mode == BTR_MODIFY_TREE || my_latch_mode == BTR_CONT_MODIFY_TREE || !page_is_leaf(buf_block_get_frame( diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index db755077e0be5..eee5d6f5e41b7 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -20680,7 +20680,6 @@ static TABLE* innodb_acquire_mdl(THD* thd, dict_table_t* table) if (!table_name_parse(table->name, db_buf, tbl_buf, db_buf_len, tbl_buf_len)) { - ut_ad(!"invalid table name"); return NULL; } @@ -20716,7 +20715,6 @@ static TABLE* innodb_acquire_mdl(THD* thd, dict_table_t* table) if (!table_name_parse(table->name, db_buf1, tbl_buf1, db_buf1_len, tbl_buf1_len)) { - ut_ad(!"invalid table name"); goto release_fail; } @@ -20764,7 +20762,6 @@ static TABLE* innodb_find_table_for_vc(THD* thd, dict_table_t* table) if (!table_name_parse(table->name, db_buf, tbl_buf, db_buf_len, tbl_buf_len)) { - ut_ad(!"invalid table name"); return NULL; } diff --git a/storage/innobase/include/btr0sea.h b/storage/innobase/include/btr0sea.h index de45bc7b39fdb..4aaf3fb835e3d 100644 --- a/storage/innobase/include/btr0sea.h +++ b/storage/innobase/include/btr0sea.h @@ -171,6 +171,9 @@ static inline bool btr_search_own_all(ulint mode); @retval true if owns any of them @retval false if owns no search latch */ static inline bool btr_search_own_any(ulint mode); + +/** @return whether this thread holds any of the search latches */ +static inline bool btr_search_own_any(); #endif /* UNIV_DEBUG */ /** Unlock all search latches from shared mode. */ diff --git a/storage/innobase/include/btr0sea.ic b/storage/innobase/include/btr0sea.ic index efa3667d229db..716410e35579f 100644 --- a/storage/innobase/include/btr0sea.ic +++ b/storage/innobase/include/btr0sea.ic @@ -144,6 +144,18 @@ static inline bool btr_search_own_any(ulint mode) } return(false); } + +/** @return whether this thread holds any of the search latches */ +static inline bool btr_search_own_any() +{ + for (ulint i = btr_ahi_parts; i--; ) { + if (rw_lock_own_flagged(btr_search_latches[i], + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)) { + return true; + } + } + return false; +} #endif /* UNIV_DEBUG */ /** Get the adaptive hash search index latch for a b-tree. diff --git a/storage/innobase/include/ha0ha.ic b/storage/innobase/include/ha0ha.ic index 1513df209adc1..3c699ab9b0cd8 100644 --- a/storage/innobase/include/ha0ha.ic +++ b/storage/innobase/include/ha0ha.ic @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 1994, 2015, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2018, MariaDB Corporation. 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 the Free Software @@ -137,11 +138,8 @@ hash_assert_can_search( if (table->type == HASH_TABLE_SYNC_MUTEX) { ut_ad(mutex_own(hash_get_mutex(table, fold))); } else if (table->type == HASH_TABLE_SYNC_RW_LOCK) { -# ifdef UNIV_DEBUG - rw_lock_t* lock = hash_get_lock(table, fold); - ut_ad(rw_lock_own(lock, RW_LOCK_X) - || rw_lock_own(lock, RW_LOCK_S)); -# endif + ut_ad(rw_lock_own_flagged(hash_get_lock(table, fold), + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); } else { ut_ad(table->type == HASH_TABLE_SYNC_NONE); } diff --git a/storage/innobase/include/row0types.h b/storage/innobase/include/row0types.h index 1bff37672530e..d2aef89f69598 100644 --- a/storage/innobase/include/row0types.h +++ b/storage/innobase/include/row0types.h @@ -56,6 +56,7 @@ struct TABLE; /** Purge virtual column node information. */ struct purge_vcol_info_t { +private: /** Is there a possible need to evaluate virtual columns? */ bool requested; /** Do we have to evaluate virtual columns (using mariadb_table)? */ @@ -67,6 +68,7 @@ struct purge_vcol_info_t /** MariaDB table opened for virtual column computation. */ TABLE* mariadb_table; +public: /** Reset the state. */ void reset() { @@ -81,6 +83,29 @@ struct purge_vcol_info_t or doesn't try to calculate virtual column. */ bool validate() const { return !used || mariadb_table; } + /** @return the table handle for evaluating virtual columns */ + TABLE* table() const { return mariadb_table; } + + /** Set the table handle for evaluating virtual columns. + @param[in] table table handle */ + void set_table(TABLE* table) + { + ut_ad(!table || is_first_fetch()); + mariadb_table = table; + } + + /** Note that virtual column information may be needed. */ + void set_requested() + { + ut_ad(!used); + ut_ad(!first_use); + ut_ad(!mariadb_table); + requested = true; + } + + /** @return whether the virtual column information may be needed */ + bool is_requested() const { return requested; } + /** Note that the virtual column information is needed. */ void set_used() { @@ -92,7 +117,18 @@ struct purge_vcol_info_t return; } - first_use = used = true; + if (!used) { + first_use = used = true; + } + } + + /** @return whether the virtual column information is needed */ + bool is_used() const + { + ut_ad(!first_use || used); + ut_ad(!used || requested); + ut_ad(used || !mariadb_table); + return used; } /** Check whether it fetches mariadb table for the first time. @@ -100,6 +136,8 @@ struct purge_vcol_info_t bool is_first_fetch() const { ut_ad(!first_use || used); + ut_ad(!used || requested); + ut_ad(used || !mariadb_table); return first_use; } }; diff --git a/storage/innobase/include/sync0rw.ic b/storage/innobase/include/sync0rw.ic index 5c7a73b490dbd..f0c33ecbeda8a 100644 --- a/storage/innobase/include/sync0rw.ic +++ b/storage/innobase/include/sync0rw.ic @@ -279,8 +279,7 @@ rw_lock_s_lock_func( the threads which have s-locked a latch. This would use some CPU time. */ - ut_ad(!rw_lock_own(lock, RW_LOCK_S)); /* see NOTE above */ - ut_ad(!rw_lock_own(lock, RW_LOCK_X)); + ut_ad(!rw_lock_own_flagged(lock, RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); if (!rw_lock_s_lock_low(lock, pass, file_name, line)) { diff --git a/storage/innobase/row/row0log.cc b/storage/innobase/row/row0log.cc index 7347f4f04c600..db33910c6f27c 100644 --- a/storage/innobase/row/row0log.cc +++ b/storage/innobase/row/row0log.cc @@ -329,8 +329,8 @@ row_log_online_op( ut_ad(dtuple_validate(tuple)); ut_ad(dtuple_get_n_fields(tuple) == dict_index_get_n_fields(index)); - ut_ad(rw_lock_own(dict_index_get_lock(index), RW_LOCK_S) - || rw_lock_own(dict_index_get_lock(index), RW_LOCK_X)); + ut_ad(rw_lock_own_flagged(&index->lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); if (index->is_corrupted()) { return; diff --git a/storage/innobase/row/row0purge.cc b/storage/innobase/row/row0purge.cc index ac2309afd99a6..79ce3057cd7ae 100644 --- a/storage/innobase/row/row0purge.cc +++ b/storage/innobase/row/row0purge.cc @@ -137,7 +137,7 @@ row_purge_remove_clust_if_poss_low( rec_offs_init(offsets_); ut_ad(rw_lock_own(dict_operation_lock, RW_LOCK_S) - || node->vcol_info.used); + || node->vcol_info.is_used()); index = dict_table_get_first_index(node->table); @@ -250,7 +250,7 @@ static void row_purge_store_vsec_cur( return; } - node->vcol_info.requested = true; + node->vcol_info.set_requested(); btr_pcur_store_position(sec_pcur, sec_mtr); @@ -318,16 +318,18 @@ row_purge_poss_sec( ut_ad(!dict_index_is_clust(index)); - const bool store_cur = sec_mtr && !node->vcol_info.used + const bool store_cur = sec_mtr && !node->vcol_info.is_used() && dict_index_has_virtual(index); if (store_cur) { row_purge_store_vsec_cur(node, index, sec_pcur, sec_mtr); + ut_ad(sec_mtr->has_committed() + == node->vcol_info.is_requested()); /* The PRIMARY KEY value was not found in the clustered index. The secondary index record found. We can purge the secondary index record. */ - if (!node->vcol_info.requested) { + if (!node->vcol_info.is_requested()) { ut_ad(!node->found_clust); return true; } @@ -344,7 +346,18 @@ row_purge_poss_sec( &node->vcol_info); if (node->vcol_info.is_first_fetch()) { - if (node->vcol_info.mariadb_table) { + ut_ad(store_cur); + + const TABLE* t= node->vcol_info.table(); + DBUG_LOG("purge", "retry " << t + << (is_tree ? " tree" : " leaf") + << index->name << "," << index->table->name + << ": " << rec_printer(entry).str()); + + ut_ad(mtr.has_committed()); + + if (t) { + node->vcol_info.set_used(); goto retry_purge_sec; } @@ -357,9 +370,11 @@ row_purge_poss_sec( if (node->found_clust) { btr_pcur_commit_specify_mtr(&node->pcur, &mtr); } else { - mtr_commit(&mtr); + mtr.commit(); } + ut_ad(mtr.has_committed()); + if (store_cur && !row_purge_restore_vsec_cur( node, index, sec_pcur, sec_mtr, is_tree)) { return false; @@ -791,7 +806,7 @@ whose old history can no longer be observed. static void row_purge_reset_trx_id(purge_node_t* node, mtr_t* mtr) { ut_ad(rw_lock_own(dict_operation_lock, RW_LOCK_S) - || node->vcol_info.used); + || node->vcol_info.is_used()); /* Reset DB_TRX_ID, DB_ROLL_PTR for old records. */ mtr->start(); @@ -867,7 +882,7 @@ row_purge_upd_exist_or_extern_func( mem_heap_t* heap; ut_ad(rw_lock_own(dict_operation_lock, RW_LOCK_S) - || node->vcol_info.used); + || node->vcol_info.is_used()); ut_ad(!node->table->skip_alter_undo); if (node->rec_type == TRX_UNDO_UPD_DEL_REC @@ -1228,7 +1243,7 @@ row_purge( bool purged = row_purge_record( node, undo_rec, thr, updated_extern); - if (!node->vcol_info.used) { + if (!node->vcol_info.is_used()) { rw_lock_s_unlock(dict_operation_lock); } diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index 67fc30d526ecb..b68efbfa7bea6 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -1100,8 +1100,8 @@ sel_set_rtr_rec_lock( rw_lock_x_lock(&(match->block.lock)); retry: cur_block = btr_pcur_get_block(pcur); - ut_ad(rw_lock_own(&(match->block.lock), RW_LOCK_X) - || rw_lock_own(&(match->block.lock), RW_LOCK_S)); + ut_ad(rw_lock_own_flagged(&match->block.lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); ut_ad(page_is_leaf(buf_block_get_frame(cur_block))); err = lock_sec_rec_read_check_and_lock( diff --git a/storage/innobase/row/row0umod.cc b/storage/innobase/row/row0umod.cc index fe39d918b5c58..64d771d7d9452 100644 --- a/storage/innobase/row/row0umod.cc +++ b/storage/innobase/row/row0umod.cc @@ -222,8 +222,8 @@ row_undo_mod_clust( ut_ad(thr_get_trx(thr) == node->trx); ut_ad(node->trx->dict_operation_lock_mode); ut_ad(node->trx->in_rollback); - ut_ad(rw_lock_own(dict_operation_lock, RW_LOCK_S) - || rw_lock_own(dict_operation_lock, RW_LOCK_X)); + ut_ad(rw_lock_own_flagged(dict_operation_lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); log_free_check(); pcur = &node->pcur; diff --git a/storage/innobase/row/row0vers.cc b/storage/innobase/row/row0vers.cc index 5bebdd82f8139..1008e2d13fa93 100644 --- a/storage/innobase/row/row0vers.cc +++ b/storage/innobase/row/row0vers.cc @@ -453,7 +453,7 @@ row_vers_build_clust_v_col( if (vcol_info != NULL) { vcol_info->set_used(); - maria_table = vcol_info->mariadb_table; + maria_table = vcol_info->table(); } innobase_allocate_row_for_vcol(thd, index, @@ -462,9 +462,8 @@ row_vers_build_clust_v_col( &record, &vcol_storage); - if (vcol_info && !vcol_info->mariadb_table) { - vcol_info->mariadb_table = maria_table; - ut_ad(!maria_table || vcol_info->is_first_fetch()); + if (vcol_info && !vcol_info->table()) { + vcol_info->set_table(maria_table); goto func_exit; } @@ -828,7 +827,7 @@ row_vers_build_cur_vrow( rec, *clust_offsets, NULL, NULL, NULL, NULL, heap); - if (vcol_info && !vcol_info->used) { + if (vcol_info && !vcol_info->is_used()) { mtr->commit(); } @@ -949,7 +948,7 @@ row_vers_old_has_index_entry( if (trx_undo_roll_ptr_is_insert(t_roll_ptr) || dbug_v_purge) { - if (vcol_info && !vcol_info->used) { + if (vcol_info && !vcol_info->is_used()) { mtr->commit(); } diff --git a/storage/innobase/sync/sync0rw.cc b/storage/innobase/sync/sync0rw.cc index 528b15f4e7962..ab4814f317794 100644 --- a/storage/innobase/sync/sync0rw.cc +++ b/storage/innobase/sync/sync0rw.cc @@ -2,7 +2,7 @@ Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. -Copyright (c) 2017, MariaDB Corporation. +Copyright (c) 2017, 2018, MariaDB Corporation. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -1092,12 +1092,12 @@ rw_lock_own_flagged( const rw_lock_debug_t* info = *it; - ut_ad(os_thread_eq(info->thread_id, os_thread_get_curr_id())); - - if (info->pass != 0) { + if (info->pass) { continue; } + ut_ad(os_thread_eq(info->thread_id, os_thread_get_curr_id())); + switch (info->lock_type) { case RW_LOCK_S: diff --git a/storage/innobase/trx/trx0i_s.cc b/storage/innobase/trx/trx0i_s.cc index fc142b623f034..663f39d8b7ed0 100644 --- a/storage/innobase/trx/trx0i_s.cc +++ b/storage/innobase/trx/trx0i_s.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2007, 2015, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, MariaDB Corporation. +Copyright (c) 2017, 2018, MariaDB Corporation. 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 the Free Software @@ -1468,26 +1468,20 @@ cache_select_table( trx_i_s_cache_t* cache, /*!< in: whole cache */ enum i_s_table table) /*!< in: which table */ { - i_s_table_cache_t* table_cache; - - ut_ad(rw_lock_own(cache->rw_lock, RW_LOCK_S) - || rw_lock_own(cache->rw_lock, RW_LOCK_X)); + ut_ad(rw_lock_own_flagged(cache->rw_lock, + RW_LOCK_FLAG_X | RW_LOCK_FLAG_S)); switch (table) { case I_S_INNODB_TRX: - table_cache = &cache->innodb_trx; - break; + return &cache->innodb_trx; case I_S_INNODB_LOCKS: - table_cache = &cache->innodb_locks; - break; + return &cache->innodb_locks; case I_S_INNODB_LOCK_WAITS: - table_cache = &cache->innodb_lock_waits; - break; - default: - ut_error; + return &cache->innodb_lock_waits; } - return(table_cache); + ut_error; + return NULL; } /*******************************************************************//** diff --git a/storage/innobase/ut/ut0ut.cc b/storage/innobase/ut/ut0ut.cc index c2a103313d74e..39fb037aa28c6 100644 --- a/storage/innobase/ut/ut0ut.cc +++ b/storage/innobase/ut/ut0ut.cc @@ -358,7 +358,7 @@ ut_print_buf_hex( for (data = static_cast(buf), i = 0; i < len; i++) { byte b = *data++; - o << hexdigit[(int) b >> 16] << hexdigit[b & 15]; + o << hexdigit[int(b) >> 4] << hexdigit[b & 15]; } o << ")";