Commit fc75518a authored by unknown's avatar unknown

fixed unlocking tables during subquery execution (BUG#2048)


mysql-test/r/subselect_innodb.result:
  bug 2048 test
mysql-test/t/subselect_innodb.test:
  bug 2048 test
sql/item_subselect.cc:
  do not unlock tables for subqueries
sql/sql_derived.cc:
  derived table tables can be unlocked
sql/sql_lex.h:
  new interface to pass additional options
sql/sql_union.cc:
  new interface to pass additional options
  do not unlock tables for UNION
parent e0daf112
...@@ -63,3 +63,23 @@ processor_id (SELECT y.yod_id FROM t1 p2, t2 y WHERE p2.processor_id = p1.proces ...@@ -63,3 +63,23 @@ processor_id (SELECT y.yod_id FROM t1 p2, t2 y WHERE p2.processor_id = p1.proces
2 1 2 1
3 1 3 1
drop table t1,t2,t3; drop table t1,t2,t3;
CREATE TABLE t1 (
id int(11) NOT NULL default '0',
b int(11) default NULL,
c char(3) default NULL,
PRIMARY KEY (id),
KEY t2i1 (b)
) TYPE=innodb DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES (0,0,'GPL'),(1,0,'GPL'),(2,1,'GPL'),(3,2,'GPL');
CREATE TABLE t2 (
id int(11) NOT NULL default '0',
b int(11) default NULL,
c char(3) default NULL,
PRIMARY KEY (id),
KEY t2i (b)
) TYPE=innodb DEFAULT CHARSET=latin1;
INSERT INTO t2 VALUES (0,0,'GPL'),(1,0,'GPL'),(2,1,'GPL'),(3,2,'GPL');
select (select max(id) from t2 where b=1 group by b) as x,b from t1 where b=1;
x b
2 1
drop table t1,t2;
...@@ -68,3 +68,25 @@ INSERT INTO t3 VALUES (1,1),(2,2),(3,3); ...@@ -68,3 +68,25 @@ INSERT INTO t3 VALUES (1,1),(2,2),(3,3);
INSERT INTO t2 VALUES (1,1),(2,2),(3,3); INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
SELECT distinct p1.processor_id, (SELECT y.yod_id FROM t1 p2, t2 y WHERE p2.processor_id = p1.processor_id and p2.processor_id = y.processor_id) FROM t1 p1; SELECT distinct p1.processor_id, (SELECT y.yod_id FROM t1 p2, t2 y WHERE p2.processor_id = p1.processor_id and p2.processor_id = y.processor_id) FROM t1 p1;
drop table t1,t2,t3; drop table t1,t2,t3;
#
# innodb locking
#
CREATE TABLE t1 (
id int(11) NOT NULL default '0',
b int(11) default NULL,
c char(3) default NULL,
PRIMARY KEY (id),
KEY t2i1 (b)
) TYPE=innodb DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES (0,0,'GPL'),(1,0,'GPL'),(2,1,'GPL'),(3,2,'GPL');
CREATE TABLE t2 (
id int(11) NOT NULL default '0',
b int(11) default NULL,
c char(3) default NULL,
PRIMARY KEY (id),
KEY t2i (b)
) TYPE=innodb DEFAULT CHARSET=latin1;
INSERT INTO t2 VALUES (0,0,'GPL'),(1,0,'GPL'),(2,1,'GPL'),(3,2,'GPL');
select (select max(id) from t2 where b=1 group by b) as x,b from t1 where b=1;
drop table t1,t2;
...@@ -906,7 +906,8 @@ int subselect_single_select_engine::prepare() ...@@ -906,7 +906,8 @@ int subselect_single_select_engine::prepare()
{ {
if (prepared) if (prepared)
return 0; return 0;
join= new JOIN(thd, select_lex->item_list, select_lex->options, result); join= new JOIN(thd, select_lex->item_list,
select_lex->options | SELECT_NO_UNLOCK, result);
if (!join || !result) if (!join || !result)
{ {
thd->fatal_error(); //out of memory thd->fatal_error(); //out of memory
...@@ -933,7 +934,7 @@ int subselect_single_select_engine::prepare() ...@@ -933,7 +934,7 @@ int subselect_single_select_engine::prepare()
int subselect_union_engine::prepare() int subselect_union_engine::prepare()
{ {
return unit->prepare(thd, result); return unit->prepare(thd, result, SELECT_NO_UNLOCK);
} }
int subselect_uniquesubquery_engine::prepare() int subselect_uniquesubquery_engine::prepare()
......
...@@ -114,7 +114,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, ...@@ -114,7 +114,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit,
DBUG_RETURN(1); // out of memory DBUG_RETURN(1); // out of memory
// st_select_lex_unit::prepare correctly work for single select // st_select_lex_unit::prepare correctly work for single select
if ((res= unit->prepare(thd, derived_result))) if ((res= unit->prepare(thd, derived_result, 0)))
goto exit; goto exit;
/* /*
......
...@@ -351,7 +351,7 @@ public: ...@@ -351,7 +351,7 @@ public:
void exclude_tree(); void exclude_tree();
/* UNION methods */ /* UNION methods */
int prepare(THD *thd, select_result *result); int prepare(THD *thd, select_result *result, ulong additional_options);
int exec(); int exec();
int cleanup(); int cleanup();
......
...@@ -29,7 +29,7 @@ int mysql_union(THD *thd, LEX *lex, select_result *result, ...@@ -29,7 +29,7 @@ int mysql_union(THD *thd, LEX *lex, select_result *result,
{ {
DBUG_ENTER("mysql_union"); DBUG_ENTER("mysql_union");
int res= 0; int res= 0;
if (!(res= unit->prepare(thd, result))) if (!(res= unit->prepare(thd, result, SELECT_NO_UNLOCK)))
res= unit->exec(); res= unit->exec();
res|= unit->cleanup(); res|= unit->cleanup();
DBUG_RETURN(res); DBUG_RETURN(res);
...@@ -106,7 +106,8 @@ bool select_union::flush() ...@@ -106,7 +106,8 @@ bool select_union::flush()
} }
int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result) int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
ulong additional_options)
{ {
SELECT_LEX *lex_select_save= thd_arg->lex.current_select; SELECT_LEX *lex_select_save= thd_arg->lex.current_select;
SELECT_LEX *sl, *first_select; SELECT_LEX *sl, *first_select;
...@@ -146,7 +147,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result) ...@@ -146,7 +147,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result)
for (;sl; sl= sl->next_select()) for (;sl; sl= sl->next_select())
{ {
JOIN *join= new JOIN(thd_arg, sl->item_list, JOIN *join= new JOIN(thd_arg, sl->item_list,
sl->options | thd_arg->options | SELECT_NO_UNLOCK, sl->options | thd_arg->options | additional_options,
tmp_result); tmp_result);
thd_arg->lex.current_select= sl; thd_arg->lex.current_select= sl;
offset_limit_cnt= sl->offset_limit; offset_limit_cnt= sl->offset_limit;
......
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