Skip to content
This repository was archived by the owner on Oct 5, 2021. It is now read-only.

Commit cb15cc6

Browse files
author
Chaithra Gopalareddy
committed
Bug #18899860: EXPLAIN .. SELECT .. FOR UPDATE TAKES LOCKS
Problem: Explain for a statement with "For update" takes locks. Flags to take the lock are set while parsing itself for a "SELECT ..FOR UPDATE" statement. Solution: Do not set the flag for explain in parser. We do this by checking the lex->describe flag.
1 parent 1661320 commit cb15cc6

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

mysql-test/r/explain.result

+15
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,18 @@ NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL Using temporary
554554
DROP TABLE t1, t2;
555555
# End WL#4897
556556
End of 6.0 tests.
557+
#
558+
# Bug #18899860: EXPLAIN .. SELECT .. FOR UPDATE TAKES LOCKS
559+
#
560+
CREATE TABLE t1(c1 INT PRIMARY KEY) ENGINE=INNODB;
561+
INSERT INTO t1 VALUES (1),(2),(3);
562+
START TRANSACTION;
563+
EXPLAIN SELECT * FROM t1 WHERE c1 = 1 FOR UPDATE;
564+
id select_type table type possible_keys key key_len ref rows Extra
565+
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index
566+
START TRANSACTION;
567+
EXPLAIN SELECT * FROM t1 WHERE c1 = 1 FOR UPDATE;
568+
id select_type table type possible_keys key key_len ref rows Extra
569+
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index
570+
DROP TABLE t1;
571+
# End of test for Bug#18899860

mysql-test/t/explain.test

+22
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,25 @@ DROP TABLE t1, t2;
400400
--echo # End WL#4897
401401

402402
--echo End of 6.0 tests.
403+
404+
--echo #
405+
--echo # Bug #18899860: EXPLAIN .. SELECT .. FOR UPDATE TAKES LOCKS
406+
--echo #
407+
408+
CREATE TABLE t1(c1 INT PRIMARY KEY) ENGINE=INNODB;
409+
INSERT INTO t1 VALUES (1),(2),(3);
410+
CONNECT (c1,localhost,root,,);
411+
CONNECT (c2,localhost,root,,);
412+
CONNECTION c1;
413+
START TRANSACTION;
414+
EXPLAIN SELECT * FROM t1 WHERE c1 = 1 FOR UPDATE;
415+
CONNECTION c2;
416+
START TRANSACTION;
417+
EXPLAIN SELECT * FROM t1 WHERE c1 = 1 FOR UPDATE;
418+
CONNECTION default;
419+
DISCONNECT c1;
420+
DISCONNECT c2;
421+
DROP TABLE t1;
422+
423+
--echo # End of test for Bug#18899860
424+

sql/sql_yacc.yy

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
33

44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -8775,15 +8775,21 @@ select_lock_type:
87758775
| FOR_SYM UPDATE_SYM
87768776
{
87778777
LEX *lex=Lex;
8778-
lex->current_select->set_lock_for_tables(TL_WRITE);
8779-
lex->safe_to_cache_query=0;
8778+
if (!lex->describe)
8779+
{
8780+
lex->current_select->set_lock_for_tables(TL_WRITE);
8781+
lex->safe_to_cache_query=0;
8782+
}
87808783
}
87818784
| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
87828785
{
87838786
LEX *lex=Lex;
8784-
lex->current_select->
8785-
set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
8786-
lex->safe_to_cache_query=0;
8787+
if (!lex->describe)
8788+
{
8789+
lex->current_select->
8790+
set_lock_for_tables(TL_READ_WITH_SHARED_LOCKS);
8791+
lex->safe_to_cache_query=0;
8792+
}
87878793
}
87888794
;
87898795

0 commit comments

Comments
 (0)