Skip to content

Commit

Permalink
Merge 10.2 into 10.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed Jul 23, 2018
2 parents b9865b2 + 9d1f3bf commit f418661
Show file tree
Hide file tree
Showing 27 changed files with 236 additions and 82 deletions.
4 changes: 4 additions & 0 deletions mysql-test/main/create_replace_tmp.result
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 4 additions & 0 deletions mysql-test/main/create_replace_tmp.test
Original file line number Diff line number Diff line change
@@ -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;
23 changes: 23 additions & 0 deletions mysql-test/main/cte_recursive_not_embedded.result
Original file line number Diff line number Diff line change
@@ -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;
42 changes: 42 additions & 0 deletions mysql-test/main/cte_recursive_not_embedded.test
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 9 additions & 0 deletions mysql-test/suite/rpl/r/rpl_15867.result
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions mysql-test/suite/rpl/t/rpl_15867.test
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions sql/sql_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions sql/sql_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 13 additions & 14 deletions storage/innobase/btr/btr0sea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
17 changes: 9 additions & 8 deletions storage/innobase/buf/buf0buf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions storage/innobase/buf/buf0lru.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}

Expand Down
5 changes: 2 additions & 3 deletions storage/innobase/gis/gis0sea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 0 additions & 3 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions storage/innobase/include/btr0sea.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
12 changes: 12 additions & 0 deletions storage/innobase/include/btr0sea.ic
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 3 additions & 5 deletions storage/innobase/include/ha0ha.ic
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit f418661

Please sign in to comment.