Commit c77336c2 authored by kroki@mysql.com's avatar kroki@mysql.com

Bug#16501: IS_USED_LOCK does not appear to work

Update User_level_lock::thread_id on acquiring an existing lock,
and reset it on lock release.
parent afeb3c06
...@@ -57,3 +57,39 @@ t1 CREATE TABLE `t1` ( ...@@ -57,3 +57,39 @@ t1 CREATE TABLE `t1` (
`length(uuid())` int(10) NOT NULL default '0' `length(uuid())` int(10) NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1; drop table t1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (conn CHAR(7), connection_id INT);
INSERT INTO t1 VALUES ('default', CONNECTION_ID());
SELECT GET_LOCK('bug16501',600);
GET_LOCK('bug16501',600)
1
INSERT INTO t1 VALUES ('con1', CONNECTION_ID());
SELECT IS_USED_LOCK('bug16501') = connection_id
FROM t1
WHERE conn = 'default';
IS_USED_LOCK('bug16501') = connection_id
1
SELECT GET_LOCK('bug16501',600);
SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID();
IS_USED_LOCK('bug16501') = CONNECTION_ID()
1
SELECT RELEASE_LOCK('bug16501');
RELEASE_LOCK('bug16501')
1
SELECT IS_USED_LOCK('bug16501') = connection_id
FROM t1
WHERE conn = 'con1';
IS_USED_LOCK('bug16501') = connection_id
1
GET_LOCK('bug16501',600)
1
SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID();
IS_USED_LOCK('bug16501') = CONNECTION_ID()
1
SELECT RELEASE_LOCK('bug16501');
RELEASE_LOCK('bug16501')
1
SELECT IS_USED_LOCK('bug16501');
IS_USED_LOCK('bug16501')
NULL
DROP TABLE t1;
...@@ -43,4 +43,42 @@ create table t1 as select uuid(), length(uuid()); ...@@ -43,4 +43,42 @@ create table t1 as select uuid(), length(uuid());
show create table t1; show create table t1;
drop table t1; drop table t1;
#
# Bug#16501: IS_USED_LOCK does not appear to work
#
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (conn CHAR(7), connection_id INT);
INSERT INTO t1 VALUES ('default', CONNECTION_ID());
SELECT GET_LOCK('bug16501',600);
connect (con1,localhost,root,,);
INSERT INTO t1 VALUES ('con1', CONNECTION_ID());
SELECT IS_USED_LOCK('bug16501') = connection_id
FROM t1
WHERE conn = 'default';
send SELECT GET_LOCK('bug16501',600);
connection default;
SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID();
SELECT RELEASE_LOCK('bug16501');
SELECT IS_USED_LOCK('bug16501') = connection_id
FROM t1
WHERE conn = 'con1';
connection con1;
reap;
SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID();
SELECT RELEASE_LOCK('bug16501');
SELECT IS_USED_LOCK('bug16501');
disconnect con1;
connection default;
DROP TABLE t1;
# End of 4.1 tests # End of 4.1 tests
...@@ -1972,6 +1972,7 @@ void item_user_lock_free(void) ...@@ -1972,6 +1972,7 @@ void item_user_lock_free(void)
void item_user_lock_release(User_level_lock *ull) void item_user_lock_release(User_level_lock *ull)
{ {
ull->locked=0; ull->locked=0;
ull->thread_id= 0;
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
char buf[256]; char buf[256];
...@@ -2170,6 +2171,7 @@ longlong Item_func_get_lock::val_int() ...@@ -2170,6 +2171,7 @@ longlong Item_func_get_lock::val_int()
{ {
ull->locked=1; ull->locked=1;
ull->thread=thd->real_id; ull->thread=thd->real_id;
ull->thread_id= thd->thread_id;
thd->ull=ull; thd->ull=ull;
error=0; error=0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment