From 203d46bb387b4cb178fe0e4cf9135daa440233e5 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 14 Jul 2006 19:28:58 -0700 Subject: [PATCH 1/3] 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. mysql-test/r/subselect.result: Added a test case fir bug #20519. mysql-test/t/subselect.test: Added a test case fir bug #20519. --- mysql-test/r/subselect.result | 45 +++++++++++++++++++++++++++++++++++ mysql-test/t/subselect.test | 40 +++++++++++++++++++++++++++++++ sql/sql_select.cc | 5 ++++ 3 files changed, 90 insertions(+) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 11dc68fe99b..13f653b2f07 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -3238,3 +3238,48 @@ i 10000000000000000000 DROP TABLE t1; 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; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 9fc4f8a8d4e..310adcc5323 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -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 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; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 8361986e020..a7158960ed0 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1209,6 +1209,11 @@ int 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; if (exec_tmp_table1) From 9a5daa602a11a2285b69b3c400d2e683cf63837a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 17 Jul 2006 14:22:21 +0400 Subject: [PATCH 2/3] mysql.test, mysql.result: Corrected the test case after fixing bug#10977 mysql-test/t/mysql.test: Corrected the test case after fixing bug#10977 mysql-test/r/mysql.result: Corrected the test case after fixing bug#10977 --- mysql-test/r/mysql.result | 8 ++++---- mysql-test/t/mysql.test | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result index 4b7084e813c..d70366a7589 100644 --- a/mysql-test/r/mysql.result +++ b/mysql-test/r/mysql.result @@ -36,19 +36,19 @@ Tables_in_test t1 t2 t3 - +_ Test delimiter : from command line a 1 - +_ Test delimiter :; from command line a 1 - +_ Test 'go' command(vertical output) G *************************** 1. row *************************** a: 1 - +_ Test 'go' command g a 1 diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index ac4c323f51e..98fadcfc75d 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -20,16 +20,16 @@ insert into t1 values(1); --disable_query_log # Test delimiter : supplied on the command line -select "Test delimiter : from command line" as " "; +select "Test delimiter : from command line" as "_"; --exec $MYSQL test --delimiter=":" -e "select * from t1:" # Test delimiter :; supplied on the command line -select "Test delimiter :; from command line" as " "; +select "Test delimiter :; from command line" as "_"; --exec $MYSQL test --delimiter=":;" -e "select * from t1:;" # Test 'go' command (vertical output) \G -select "Test 'go' command(vertical output) \G" as " "; +select "Test 'go' command(vertical output) \G" as "_"; --exec $MYSQL test -e "select * from t1\G" # Test 'go' command \g -select "Test 'go' command \g" as " "; +select "Test 'go' command \g" as "_"; --exec $MYSQL test -e "select * from t1\g" --enable_query_log drop table t1; From 14d72663f1eb0d9ec7cf7d353f09c2cc14a30597 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 17 Jul 2006 16:12:42 +0400 Subject: [PATCH 3/3] select.result, select.test: Test case for bug#10977 altered to make it work in both plain and ps-protocol modes. mysql-test/t/select.test: Test case for bug#10977 altered to make it work in both plain and ps-protocol modes. mysql-test/r/select.result: Test case for bug#10977 altered to make it work in both plain and ps-protocol modes. --- mysql-test/r/select.result | 7 ++++--- mysql-test/t/select.test | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 30708c0ccda..c2218585f7c 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -3398,8 +3398,9 @@ drop table t1,t2; SELECT 0.9888889889 * 1.011111411911; 0.9888889889 * 1.011111411911 0.9998769417899202067879 -select 1 as ' a '; -a -1 +prepare stmt from 'select 1 as " a "'; Warnings: Warning 1466 Leading spaces are removed from name ' a ' +execute stmt; +a +1 diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index ac5c121550a..592e366f835 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2910,4 +2910,5 @@ SELECT 0.9888889889 * 1.011111411911; # # Bug #10977: No warning issued if a column name is truncated # -select 1 as ' a '; +prepare stmt from 'select 1 as " a "'; +execute stmt;