Commit 4de3186a authored by igor@olga.mysql.com's avatar igor@olga.mysql.com

Fixed bug #20519.

The bug was due to a loss happened during a refactoring made
on May 30 2005 that modified the function JOIN::reinit.
As a result of it for any subquery the value of offset_limit_cnt
was not restored for the following executions. Yet the first 
execution of the subquery made it equal to 0.
The fix restores this value in the function JOIN::reinit.  
parent 10b2590c
...@@ -3238,3 +3238,48 @@ i ...@@ -3238,3 +3238,48 @@ i
10000000000000000000 10000000000000000000
DROP TABLE t1; DROP TABLE t1;
DROP TABLE t2; DROP TABLE t2;
CREATE TABLE t1 (
id bigint(20) unsigned NOT NULL auto_increment,
name varchar(255) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO t1 VALUES
(1, 'Balazs'), (2, 'Joe'), (3, 'Frank');
CREATE TABLE t2 (
id bigint(20) unsigned NOT NULL auto_increment,
mid bigint(20) unsigned NOT NULL,
date date NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO t2 VALUES
(1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'),
(4, 2, '2006-04-20'), (5, 1, '2006-05-01');
SELECT *,
(SELECT date FROM t2 WHERE mid = t1.id
ORDER BY date DESC LIMIT 0, 1) AS date_last,
(SELECT date FROM t2 WHERE mid = t1.id
ORDER BY date DESC LIMIT 3, 1) AS date_next_to_last
FROM t1;
id name date_last date_next_to_last
1 Balazs 2006-05-01 NULL
2 Joe 2006-04-20 NULL
3 Frank 2006-04-13 NULL
SELECT *,
(SELECT COUNT(*) FROM t2 WHERE mid = t1.id
ORDER BY date DESC LIMIT 1, 1) AS date_count
FROM t1;
id name date_count
1 Balazs NULL
2 Joe NULL
3 Frank NULL
SELECT *,
(SELECT date FROM t2 WHERE mid = t1.id
ORDER BY date DESC LIMIT 0, 1) AS date_last,
(SELECT date FROM t2 WHERE mid = t1.id
ORDER BY date DESC LIMIT 1, 1) AS date_next_to_last
FROM t1;
id name date_last date_next_to_last
1 Balazs 2006-05-01 2006-03-30
2 Joe 2006-04-20 2006-04-06
3 Frank 2006-04-13 NULL
DROP TABLE t1,t2;
...@@ -2161,3 +2161,43 @@ SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED); ...@@ -2161,3 +2161,43 @@ SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED);
DROP TABLE t1; DROP TABLE t1;
DROP TABLE t2; DROP TABLE t2;
#
# Bug#20519: subselect with LIMIT M, N
#
CREATE TABLE t1 (
id bigint(20) unsigned NOT NULL auto_increment,
name varchar(255) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO t1 VALUES
(1, 'Balazs'), (2, 'Joe'), (3, 'Frank');
CREATE TABLE t2 (
id bigint(20) unsigned NOT NULL auto_increment,
mid bigint(20) unsigned NOT NULL,
date date NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO t2 VALUES
(1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'),
(4, 2, '2006-04-20'), (5, 1, '2006-05-01');
SELECT *,
(SELECT date FROM t2 WHERE mid = t1.id
ORDER BY date DESC LIMIT 0, 1) AS date_last,
(SELECT date FROM t2 WHERE mid = t1.id
ORDER BY date DESC LIMIT 3, 1) AS date_next_to_last
FROM t1;
SELECT *,
(SELECT COUNT(*) FROM t2 WHERE mid = t1.id
ORDER BY date DESC LIMIT 1, 1) AS date_count
FROM t1;
SELECT *,
(SELECT date FROM t2 WHERE mid = t1.id
ORDER BY date DESC LIMIT 0, 1) AS date_last,
(SELECT date FROM t2 WHERE mid = t1.id
ORDER BY date DESC LIMIT 1, 1) AS date_next_to_last
FROM t1;
DROP TABLE t1,t2;
...@@ -1209,6 +1209,11 @@ int ...@@ -1209,6 +1209,11 @@ int
JOIN::reinit() JOIN::reinit()
{ {
DBUG_ENTER("JOIN::reinit"); DBUG_ENTER("JOIN::reinit");
unit->offset_limit_cnt= (ha_rows)(select_lex->offset_limit ?
select_lex->offset_limit->val_uint() :
ULL(0));
first_record= 0; first_record= 0;
if (exec_tmp_table1) if (exec_tmp_table1)
......
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