Commit d4e9da31 authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #802845.

If the expression for a derived table contained a clause LIMIT 0
SELECT from such derived table incorrectly returned a non-empty set.

Fixed by ensuring JOIN::do_send_rows to be updated after the call
of st_select_lex_unit::set_limit that sets the value of 
JOIN::unit->select_limit_cnt.
parent 3d002a70
......@@ -725,3 +725,13 @@ a a a b
c c c c
DROP VIEW v1;
DROP TABLE t1,t2,t3;
#
# LP bug #802845: select from derived table with limit 0
#
SELECT * FROM (SELECT 1 LIMIT 0) t;
1
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (7), (1), (3);
SELECT * FROM (SELECT * FROM t1 LIMIT 0) t;
a
DROP TABLE t1;
......@@ -343,3 +343,19 @@ SELECT * FROM t1, t2, v1 WHERE t2.a=t1.a AND t2.a=v1.a AND t2.a=v1.b;
DROP VIEW v1;
DROP TABLE t1,t2,t3;
--echo #
--echo # LP bug #802845: select from derived table with limit 0
--echo #
SELECT * FROM (SELECT 1 LIMIT 0) t;
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (7), (1), (3);
SELECT * FROM (SELECT * FROM t1 LIMIT 0) t;
DROP TABLE t1;
......@@ -865,6 +865,7 @@ JOIN::optimize()
uint no_jbuf_after;
DBUG_ENTER("JOIN::optimize");
do_send_rows = (unit->select_limit_cnt) ? 1 : 0;
// to prevent double initialization on EXPLAIN
if (optimized)
DBUG_RETURN(0);
......@@ -914,7 +915,6 @@ JOIN::optimize()
select_limit= unit->select_limit_cnt;
if (having || (select_options & OPTION_FOUND_ROWS))
select_limit= HA_POS_ERROR;
do_send_rows = (unit->select_limit_cnt) ? 1 : 0;
// Ignore errors of execution if option IGNORE present
if (thd->lex->ignore)
thd->lex->current_select->no_error= 1;
......
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