Skip to content

Commit 0dd6a42

Browse files
author
Chaithra Gopalareddy
committed
Merge branch 'mysql-5.6' into mysql-5.7
2 parents 2b74a6c + cb15cc6 commit 0dd6a42

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

mysql-test/r/explain.result

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,3 +749,22 @@ ERROR 22007: Truncated incorrect INTEGER value: 'a'
749749
DROP TABLE t1;
750750
# End of test Bug#21139522
751751
End of 6.0 tests.
752+
#
753+
# Bug #18899860: EXPLAIN .. SELECT .. FOR UPDATE TAKES LOCKS
754+
#
755+
CREATE TABLE t1(c1 INT PRIMARY KEY) ENGINE=INNODB;
756+
INSERT INTO t1 VALUES (1),(2),(3);
757+
START TRANSACTION;
758+
EXPLAIN SELECT * FROM t1 WHERE c1 = 1 FOR UPDATE;
759+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
760+
1 SIMPLE t1 NULL const PRIMARY PRIMARY 4 const 1 100.00 Using index
761+
Warnings:
762+
Note 1003 /* select#1 */ select '1' AS `c1` from `test`.`t1` where 1
763+
START TRANSACTION;
764+
EXPLAIN SELECT * FROM t1 WHERE c1 = 1 FOR UPDATE;
765+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
766+
1 SIMPLE t1 NULL const PRIMARY PRIMARY 4 const 1 100.00 Using index
767+
Warnings:
768+
Note 1003 /* select#1 */ select '1' AS `c1` from `test`.`t1` where 1
769+
DROP TABLE t1;
770+
# End of test for Bug#18899860

mysql-test/t/explain.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,25 @@ DROP TABLE t1;
426426

427427
--echo # End of test Bug#21139522
428428
--echo End of 6.0 tests.
429+
430+
--echo #
431+
--echo # Bug #18899860: EXPLAIN .. SELECT .. FOR UPDATE TAKES LOCKS
432+
--echo #
433+
434+
CREATE TABLE t1(c1 INT PRIMARY KEY) ENGINE=INNODB;
435+
INSERT INTO t1 VALUES (1),(2),(3);
436+
CONNECT (c1,localhost,root,,);
437+
CONNECT (c2,localhost,root,,);
438+
CONNECTION c1;
439+
START TRANSACTION;
440+
EXPLAIN SELECT * FROM t1 WHERE c1 = 1 FOR UPDATE;
441+
CONNECTION c2;
442+
START TRANSACTION;
443+
EXPLAIN SELECT * FROM t1 WHERE c1 = 1 FOR UPDATE;
444+
CONNECTION default;
445+
DISCONNECT c1;
446+
DISCONNECT c2;
447+
DROP TABLE t1;
448+
449+
--echo # End of test for Bug#18899860
450+

sql/parse_tree_nodes.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,12 @@ class PT_table_expression : public Parse_tree_node
683683
opt_procedure_analyse->contextualize(pc)))
684684
return true;
685685

686-
if (opt_select_lock_type.is_set)
686+
/*
687+
@todo: explain should not affect how we construct the query data
688+
structure. Instead, consider to let lock_tables() adjust lock
689+
requests according to the explain flag.
690+
*/
691+
if (opt_select_lock_type.is_set && !pc->thd->lex->is_explain())
687692
{
688693
pc->select->set_lock_for_tables(opt_select_lock_type.lock_type);
689694
pc->thd->lex->safe_to_cache_query=
@@ -2256,7 +2261,12 @@ class PT_select_part2 : public Parse_tree_node
22562261
DBUG_ASSERT(opt_procedure_analyse_clause == NULL ||
22572262
(opt_into1 == NULL && opt_into2 == NULL));
22582263

2259-
if (opt_select_lock_type.is_set)
2264+
/*
2265+
@todo: explain should not affect how we construct the query data
2266+
structure. Instead, consider to let lock_tables() adjust lock
2267+
requests according to the explain flag.
2268+
*/
2269+
if (opt_select_lock_type.is_set && !pc->thd->lex->is_explain())
22602270
{
22612271
pc->select->set_lock_for_tables(opt_select_lock_type.lock_type);
22622272
pc->thd->lex->safe_to_cache_query=

sql/sql_lex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2997,7 +2997,7 @@ struct LEX: public Query_tables_list
29972997
m_current_select= select;
29982998
}
29992999
/// @return true if this is an EXPLAIN statement
3000-
bool is_explain() const { return describe; }
3000+
bool is_explain() const { return (describe & DESCRIBE_NORMAL); }
30013001
char *length,*dec,*change;
30023002
LEX_STRING name;
30033003
char *help_arg;

0 commit comments

Comments
 (0)