From: Date: April 22 2005 10:13pm Subject: bk commit into 5.0 tree (sergefp:1.1863) BUG#8490 List-Archive: http://lists.mysql.com/internals/24240 X-Bug: 8490 Message-Id: <20050422201351.203A637AC8@newbox.mylan> Below is the list of changes that have just been committed into a local 5.0 repository of psergey. When psergey does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.1863 05/04/23 00:13:46 sergefp@stripped +3 -0 Fix for BUG#8490: In mysql_make_view for join algorithm views we need to insert view's subqueries into select_lex->slave(->next)* chain. In case a join has several such views, don't add the same subqueries several times (this forms a loop on the above chain which breaks many parts of the code) sql/sql_view.cc 1.42 05/04/23 00:13:42 sergefp@stripped +11 -3 Fix for BUG#8490: In mysql_make_view for join algorithm views we need to insert view's subqueries into select_lex->slave(->next)* chain. In case a join has several such views, don't add the same subqueries several times (this forms a loop on the above chain which breaks many parts of the code) mysql-test/t/view.test 1.67 05/04/23 00:13:42 sergefp@stripped +14 -0 Testcase for BUG#8490 mysql-test/r/view.result 1.78 05/04/23 00:13:42 sergefp@stripped +18 -0 Testcase for BUG#8490 # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: sergefp # Host: newbox.mylan # Root: /home/psergey/mysql-5.0-bug8490-2 --- 1.77/mysql-test/r/view.result 2005-04-19 01:43:23 +04:00 +++ 1.78/mysql-test/r/view.result 2005-04-23 00:13:42 +04:00 @@ -1694,3 +1694,21 @@ 5 david NULL NULL DROP VIEW v1,v2,v3; DROP TABLE t1,t2; +create table t1 as select 1 A union select 2 union select 3; +create table t2 as select * from t1; +create view v1 as select * from t1 where a in (select * from t2); +select * from v1 A, v1 B where A.a = B.a; +A A +1 1 +2 2 +3 3 +create table t3 as select a a,a b from t2; +create view v2 as select * from t3 where +a in (select * from t1) or b in (select * from t2); +select * from v2 A, v2 B where A.a = B.b; +a b a b +1 1 1 1 +2 2 2 2 +3 3 3 3 +drop view v1, v2; +drop table t1, t2, t3; --- 1.66/mysql-test/t/view.test 2005-04-14 10:01:24 +04:00 +++ 1.67/mysql-test/t/view.test 2005-04-23 00:13:42 +04:00 @@ -1519,3 +1519,17 @@ DROP VIEW v1,v2,v3; DROP TABLE t1,t2; + +# BUG#8490 Select from views containing subqueries causes server to hang +# forever. +create table t1 as select 1 A union select 2 union select 3; +create table t2 as select * from t1; +create view v1 as select * from t1 where a in (select * from t2); +select * from v1 A, v1 B where A.a = B.a; +create table t3 as select a a,a b from t2; +create view v2 as select * from t3 where + a in (select * from t1) or b in (select * from t2); +select * from v2 A, v2 B where A.a = B.b; +drop view v1, v2; +drop table t1, t2, t3; + --- 1.41/sql/sql_view.cc 2005-04-03 16:30:12 +04:00 +++ 1.42/sql/sql_view.cc 2005-04-23 00:13:42 +04:00 @@ -796,17 +796,25 @@ /* Store WHERE clause for post-processing in setup_ancestor */ table->where= view_select->where; - /* - Add subqueries units to SELECT in which we merging current view. - + Add subqueries units to SELECT into which we merging current view. + + unit(->next)* chain starts with subqueries that are used by this + view and continues with subqueries that are used by other views. + We must not add any subquery twice (otherwise we'll form a loop), + to do this we remember in end_unit the first subquery that has + been already added. + NOTE: we do not support UNION here, so we take only one select */ + SELECT_LEX_NODE *end_unit= table->select_lex->slave; for (SELECT_LEX_UNIT *unit= lex->select_lex.first_inner_unit(); unit; unit= unit->next_unit()) { SELECT_LEX_NODE *save_slave= unit->slave; + if (unit == end_unit) + break; unit->include_down(table->select_lex); unit->slave= save_slave; // fix include_down initialisation }