From: Ole John Aske Date: November 25 2010 2:13pm Subject: bzr push into mysql-5.1-telco-7.0-spj-scan-vs-scan branch (ole.john.aske:3377 to 3378) Bug#58490 List-Archive: http://lists.mysql.com/commits/125031 X-Bug: 58490 Message-Id: <20101125141400.D66C6222@fimafeng09.norway.sun.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3378 Ole John Aske 2010-11-25 SPJ-scan-scan: Cherry picked fix for bug#58490 into SPJ branch modified: mysql-test/r/join_outer.result mysql-test/t/join_outer.test sql/sql_select.cc 3377 Jan Wedvik 2010-11-23 This commit adds code to handle various memory allocation errors (i.e. code to correctly handle cases where 'new' returns a null pointer). modified: sql/ha_ndbcluster.cc storage/ndb/include/ndbapi/NdbQueryBuilder.hpp storage/ndb/include/ndbapi/NdbQueryOperation.hpp storage/ndb/ndbapi-examples/ndbapi_multi_cursor/main.cpp storage/ndb/src/ndbapi/NdbQueryBuilder.cpp storage/ndb/src/ndbapi/NdbQueryBuilderImpl.hpp storage/ndb/src/ndbapi/NdbQueryOperation.cpp storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp storage/ndb/test/src/HugoQueryBuilder.cpp storage/ndb/test/tools/spj_performance_test.cpp storage/ndb/test/tools/spj_sanity_test.cpp === modified file 'mysql-test/r/join_outer.result' --- a/mysql-test/r/join_outer.result 2010-06-01 07:54:06 +0000 +++ b/mysql-test/r/join_outer.result 2010-11-25 14:13:23 +0000 @@ -1397,4 +1397,48 @@ id select_type table type possible_keys Warnings: Note 1003 select straight_join `test`.`jt1`.`f1` AS `f1` from `test`.`t1` `jt6` left join (`test`.`t1` `jt3` join `test`.`t1` `jt4` left join `test`.`t1` `jt5` on(1) left join `test`.`t1` `jt2` on(1)) on((`test`.`jt6`.`f1` and 1)) left join `test`.`t1` `jt1` on(1) where 1 DROP TABLE t1; +# +# Bug#58490: Incorrect result in multi level OUTER JOIN +# in combination with IS NULL +# +CREATE TABLE t1 (i INT NOT NULL); +INSERT INTO t1 VALUES (0), (2),(3),(4); +CREATE TABLE t2 (i INT NOT NULL); +INSERT INTO t2 VALUES (0),(1), (3),(4); +CREATE TABLE t3 (i INT NOT NULL); +INSERT INTO t3 VALUES (0),(1),(2), (4); +CREATE TABLE t4 (i INT NOT NULL); +INSERT INTO t4 VALUES (0),(1),(2),(3) ; +SELECT * FROM +t1 LEFT JOIN +( t2 LEFT JOIN +( t3 LEFT JOIN +t4 +ON t4.i = t3.i +) +ON t3.i = t2.i +) +ON t2.i = t1.i +; +i i i i +0 0 0 0 +2 NULL NULL NULL +3 3 NULL NULL +4 4 4 NULL +SELECT * FROM +t1 LEFT JOIN +( t2 LEFT JOIN +( t3 LEFT JOIN +t4 +ON t4.i = t3.i +) +ON t3.i = t2.i +) +ON t2.i = t1.i +WHERE t4.i IS NULL; +i i i i +2 NULL NULL NULL +3 3 NULL NULL +4 4 4 NULL +DROP TABLE t1,t2,t3,t4; End of 5.1 tests === modified file 'mysql-test/t/join_outer.test' --- a/mysql-test/t/join_outer.test 2010-06-01 07:54:06 +0000 +++ b/mysql-test/t/join_outer.test 2010-11-25 14:13:23 +0000 @@ -981,4 +981,45 @@ EXPLAIN EXTENDED SELECT STRAIGHT_JOIN jt DROP TABLE t1; + +--echo # +--echo # Bug#58490: Incorrect result in multi level OUTER JOIN +--echo # in combination with IS NULL +--echo # + +CREATE TABLE t1 (i INT NOT NULL); +INSERT INTO t1 VALUES (0), (2),(3),(4); +CREATE TABLE t2 (i INT NOT NULL); +INSERT INTO t2 VALUES (0),(1), (3),(4); +CREATE TABLE t3 (i INT NOT NULL); +INSERT INTO t3 VALUES (0),(1),(2), (4); +CREATE TABLE t4 (i INT NOT NULL); +INSERT INTO t4 VALUES (0),(1),(2),(3) ; + +SELECT * FROM + t1 LEFT JOIN + ( t2 LEFT JOIN + ( t3 LEFT JOIN + t4 + ON t4.i = t3.i + ) + ON t3.i = t2.i + ) + ON t2.i = t1.i + ; + +SELECT * FROM + t1 LEFT JOIN + ( t2 LEFT JOIN + ( t3 LEFT JOIN + t4 + ON t4.i = t3.i + ) + ON t3.i = t2.i + ) + ON t2.i = t1.i + WHERE t4.i IS NULL; + +DROP TABLE t1,t2,t3,t4; + --echo End of 5.1 tests === modified file 'sql/sql_select.cc' --- a/sql/sql_select.cc 2010-11-19 10:51:30 +0000 +++ b/sql/sql_select.cc 2010-11-25 14:13:23 +0000 @@ -11586,6 +11586,7 @@ evaluate_join_record(JOIN *join, JOIN_TA return NESTED_LOOP_ERROR; } + enum enum_nested_loop_state rc= NESTED_LOOP_OK; if (!select_cond || select_cond_result) { DBUG_PRINT("info", (" Condition passed")); @@ -11610,7 +11611,8 @@ evaluate_join_record(JOIN *join, JOIN_TA for (JOIN_TAB *tab= first_unmatched; tab <= join_tab; tab++) { if (tab->table->reginfo.not_exists_optimize) - return NESTED_LOOP_NO_MORE_ROWS; + rc= NESTED_LOOP_NO_MORE_ROWS; + /* Check all predicates that has just been activated. */ /* Actually all predicates non-guarded by first_unmatched->found @@ -11629,7 +11631,7 @@ evaluate_join_record(JOIN *join, JOIN_TA not to the last table of the current nest level. */ join->return_tab= tab; - return NESTED_LOOP_OK; + return rc; } } } @@ -11656,7 +11658,7 @@ evaluate_join_record(JOIN *join, JOIN_TA if (found) { DBUG_PRINT("info", (" found match")); - enum enum_nested_loop_state rc; + DBUG_ASSERT(rc==NESTED_LOOP_OK); /* A match from join_tab is found for the current partial join. */ rc= (*join_tab->next_select)(join, join_tab+1, 0); if (rc != NESTED_LOOP_OK && rc != NESTED_LOOP_NO_MORE_ROWS) @@ -11685,7 +11687,7 @@ evaluate_join_record(JOIN *join, JOIN_TA join->thd->row_count++; join_tab->read_record.unlock_row(join_tab); } - return NESTED_LOOP_OK; + return rc; } No bundle (reason: useless for push emails).