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/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/r/subselect.result b/mysql-test/r/subselect.result index 5bd02c9ea6c..3ce8124ade9 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -3239,6 +3239,50 @@ i 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; i1 int(11) NOT NULL default '0', i2 int(11) NOT NULL default '0', t datetime NOT NULL default '0000-00-00 00:00:00', 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; 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; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 4a977dd4826..8bf8337714f 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -2163,6 +2163,46 @@ 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; + +# # Bug#20869: subselect with range access by DESC # 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)