Loading mysql-test/r/derived.result +9 −0 Original line number Diff line number Diff line Loading @@ -330,3 +330,12 @@ SELECT MIN(price) min, MAX(price) max, AVG(price) avg FROM (SELECT SUBSTRING( MA min max avg 10.00 10.00 10 DROP TABLE t1; create table t1 (a integer, b integer); insert into t1 values (1,4), (2,2),(2,2), (4,1),(4,1),(4,1),(4,1); select distinct sum(b) from t1 group by a; sum(b) 4 select distinct sum(b) from (select a,b from t1) y group by a; sum(b) 4 drop table t1; mysql-test/r/subselect.result +48 −0 Original line number Diff line number Diff line Loading @@ -2160,3 +2160,51 @@ ERROR 42S22: Unknown column 'a2' in 'scalar IN/ALL/ANY subquery' select * from t1 where a1 > any(select b1 from t2); a1 drop table t1,t2; create table t1 (a integer, b integer); select (select * from t1) = (select 1,2); (select * from t1) = (select 1,2) NULL select (select 1,2) = (select * from t1); (select 1,2) = (select * from t1) NULL select row(1,2) = ANY (select * from t1); row(1,2) = ANY (select * from t1) 0 select row(1,2) != ALL (select * from t1); row(1,2) != ALL (select * from t1) 1 drop table t1; create table t1 (a integer, b integer); select row(1,(2,2)) in (select * from t1 ); ERROR 21000: Operand should contain 2 column(s) select row(1,(2,2)) = (select * from t1 ); ERROR 21000: Operand should contain 2 column(s) select (select * from t1) = row(1,(2,2)); ERROR 21000: Operand should contain 1 column(s) drop table t1; create table t1 (a integer); insert into t1 values (1); select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx ; ERROR 42S22: Reference 'xx' not supported (forward reference in item list) select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; ERROR 42S22: Reference 'xx' not supported (forward reference in item list) select 1 as xx, 1 = ALL ( select 1 from t1 where 1 = xx ); xx 1 = ALL ( select 1 from t1 where 1 = xx ) 1 1 select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; ERROR 42S22: Reference 'xx' not supported (forward reference in item list) select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx from DUAL; ERROR 42S22: Reference 'xx' not supported (forward reference in item list) drop table t1; CREATE TABLE `t1` ( `a` char(3) NOT NULL default '', `b` char(3) NOT NULL default '', `c` char(3) NOT NULL default '', PRIMARY KEY (`a`,`b`,`c`)) ENGINE=InnoDB; CREATE TABLE t2 LIKE t1; INSERT INTO t1 VALUES (1,1,1); INSERT INTO t2 VALUES (1,1,1); PREPARE my_stmt FROM "SELECT t1.b, count(*) FROM t1 group by t1.b having count(*) > ALL (SELECT COUNT(*) FROM t2 WHERE t2.a=1 GROUP By t2.b)"; EXECUTE my_stmt; b count(*) EXECUTE my_stmt; b count(*) deallocate prepare my_stmt; drop table t1,t2; mysql-test/t/derived.test +10 −0 Original line number Diff line number Diff line Loading @@ -214,3 +214,13 @@ CREATE TABLE `t1` ( `itemid` int(11) NOT NULL default '0', `grpid` varchar(15) N insert into t1 values (128, 'rozn', 2, now(), 10),(128, 'rozn', 1, now(), 10); SELECT MIN(price) min, MAX(price) max, AVG(price) avg FROM (SELECT SUBSTRING( MAX(concat(date_,";",price)), 12) price FROM t1 WHERE itemid=128 AND grpid='rozn' GROUP BY itemid, grpid, vendor) lastprices; DROP TABLE t1; # # DISTINCT over grouped select on subquery in the FROM clause # create table t1 (a integer, b integer); insert into t1 values (1,4), (2,2),(2,2), (4,1),(4,1),(4,1),(4,1); select distinct sum(b) from t1 group by a; select distinct sum(b) from (select a,b from t1) y group by a; drop table t1; mysql-test/t/subselect.test +56 −0 Original line number Diff line number Diff line Loading @@ -1414,8 +1414,11 @@ SELECT f1 FROM t1 WHERE f1 <> ALL ( SELECT SUM(f1) AS sf1 FROM t2 HAVING sf1 > 10000); drop table t1,t2; # # Test for BUG#7885: Server crash when 'any' subselect compared to # non-existant field. # create table t1 (a1 int); create table t2 (b1 int); --error 1054 Loading @@ -1423,3 +1426,56 @@ select * from t1 where a2 > any(select b1 from t2); select * from t1 where a1 > any(select b1 from t2); drop table t1,t2; # # Comparison subquery with * and row # create table t1 (a integer, b integer); select (select * from t1) = (select 1,2); select (select 1,2) = (select * from t1); # queries whih can be converted to IN select row(1,2) = ANY (select * from t1); select row(1,2) != ALL (select * from t1); drop table t1; # # Comparison subquery and row with nested rows # create table t1 (a integer, b integer); -- error 1241 select row(1,(2,2)) in (select * from t1 ); -- error 1241 select row(1,(2,2)) = (select * from t1 ); -- error 1241 select (select * from t1) = row(1,(2,2)); drop table t1; # # Forward reference detection # create table t1 (a integer); insert into t1 values (1); -- error 1247 select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx ; -- error 1247 select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; select 1 as xx, 1 = ALL ( select 1 from t1 where 1 = xx ); -- error 1247 select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; -- error 1247 select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx from DUAL; drop table t1; # # cleaning up of results of subselects (BUG#8125) # CREATE TABLE `t1` ( `a` char(3) NOT NULL default '', `b` char(3) NOT NULL default '', `c` char(3) NOT NULL default '', PRIMARY KEY (`a`,`b`,`c`)) ENGINE=InnoDB; CREATE TABLE t2 LIKE t1; INSERT INTO t1 VALUES (1,1,1); INSERT INTO t2 VALUES (1,1,1); PREPARE my_stmt FROM "SELECT t1.b, count(*) FROM t1 group by t1.b having count(*) > ALL (SELECT COUNT(*) FROM t2 WHERE t2.a=1 GROUP By t2.b)"; EXECUTE my_stmt; EXECUTE my_stmt; deallocate prepare my_stmt; drop table t1,t2; sql/item.cc +4 −2 Original line number Diff line number Diff line Loading @@ -1482,12 +1482,13 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) } else if (refer != (Item **)not_found_item) { if (!(*refer)->fixed) if (!last->ref_pointer_array[counter]) { my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, "forward reference in item list"); return -1; } DBUG_ASSERT((*refer)->fixed); /* Here, a subset of actions performed by Item_ref::set_properties is not enough. So we pass ptr to NULL into Item_[direct]_ref Loading Loading @@ -2161,12 +2162,13 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) mark_as_dependent(thd, last, thd->lex->current_select, fld); return 0; } if (!(*ref)->fixed) if (!last->ref_pointer_array[counter]) { my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, "forward reference in item list"); return -1; } DBUG_ASSERT((*ref)->fixed); mark_as_dependent(thd, last, thd->lex->current_select, this); if (place == IN_HAVING) Loading Loading
mysql-test/r/derived.result +9 −0 Original line number Diff line number Diff line Loading @@ -330,3 +330,12 @@ SELECT MIN(price) min, MAX(price) max, AVG(price) avg FROM (SELECT SUBSTRING( MA min max avg 10.00 10.00 10 DROP TABLE t1; create table t1 (a integer, b integer); insert into t1 values (1,4), (2,2),(2,2), (4,1),(4,1),(4,1),(4,1); select distinct sum(b) from t1 group by a; sum(b) 4 select distinct sum(b) from (select a,b from t1) y group by a; sum(b) 4 drop table t1;
mysql-test/r/subselect.result +48 −0 Original line number Diff line number Diff line Loading @@ -2160,3 +2160,51 @@ ERROR 42S22: Unknown column 'a2' in 'scalar IN/ALL/ANY subquery' select * from t1 where a1 > any(select b1 from t2); a1 drop table t1,t2; create table t1 (a integer, b integer); select (select * from t1) = (select 1,2); (select * from t1) = (select 1,2) NULL select (select 1,2) = (select * from t1); (select 1,2) = (select * from t1) NULL select row(1,2) = ANY (select * from t1); row(1,2) = ANY (select * from t1) 0 select row(1,2) != ALL (select * from t1); row(1,2) != ALL (select * from t1) 1 drop table t1; create table t1 (a integer, b integer); select row(1,(2,2)) in (select * from t1 ); ERROR 21000: Operand should contain 2 column(s) select row(1,(2,2)) = (select * from t1 ); ERROR 21000: Operand should contain 2 column(s) select (select * from t1) = row(1,(2,2)); ERROR 21000: Operand should contain 1 column(s) drop table t1; create table t1 (a integer); insert into t1 values (1); select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx ; ERROR 42S22: Reference 'xx' not supported (forward reference in item list) select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; ERROR 42S22: Reference 'xx' not supported (forward reference in item list) select 1 as xx, 1 = ALL ( select 1 from t1 where 1 = xx ); xx 1 = ALL ( select 1 from t1 where 1 = xx ) 1 1 select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; ERROR 42S22: Reference 'xx' not supported (forward reference in item list) select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx from DUAL; ERROR 42S22: Reference 'xx' not supported (forward reference in item list) drop table t1; CREATE TABLE `t1` ( `a` char(3) NOT NULL default '', `b` char(3) NOT NULL default '', `c` char(3) NOT NULL default '', PRIMARY KEY (`a`,`b`,`c`)) ENGINE=InnoDB; CREATE TABLE t2 LIKE t1; INSERT INTO t1 VALUES (1,1,1); INSERT INTO t2 VALUES (1,1,1); PREPARE my_stmt FROM "SELECT t1.b, count(*) FROM t1 group by t1.b having count(*) > ALL (SELECT COUNT(*) FROM t2 WHERE t2.a=1 GROUP By t2.b)"; EXECUTE my_stmt; b count(*) EXECUTE my_stmt; b count(*) deallocate prepare my_stmt; drop table t1,t2;
mysql-test/t/derived.test +10 −0 Original line number Diff line number Diff line Loading @@ -214,3 +214,13 @@ CREATE TABLE `t1` ( `itemid` int(11) NOT NULL default '0', `grpid` varchar(15) N insert into t1 values (128, 'rozn', 2, now(), 10),(128, 'rozn', 1, now(), 10); SELECT MIN(price) min, MAX(price) max, AVG(price) avg FROM (SELECT SUBSTRING( MAX(concat(date_,";",price)), 12) price FROM t1 WHERE itemid=128 AND grpid='rozn' GROUP BY itemid, grpid, vendor) lastprices; DROP TABLE t1; # # DISTINCT over grouped select on subquery in the FROM clause # create table t1 (a integer, b integer); insert into t1 values (1,4), (2,2),(2,2), (4,1),(4,1),(4,1),(4,1); select distinct sum(b) from t1 group by a; select distinct sum(b) from (select a,b from t1) y group by a; drop table t1;
mysql-test/t/subselect.test +56 −0 Original line number Diff line number Diff line Loading @@ -1414,8 +1414,11 @@ SELECT f1 FROM t1 WHERE f1 <> ALL ( SELECT SUM(f1) AS sf1 FROM t2 HAVING sf1 > 10000); drop table t1,t2; # # Test for BUG#7885: Server crash when 'any' subselect compared to # non-existant field. # create table t1 (a1 int); create table t2 (b1 int); --error 1054 Loading @@ -1423,3 +1426,56 @@ select * from t1 where a2 > any(select b1 from t2); select * from t1 where a1 > any(select b1 from t2); drop table t1,t2; # # Comparison subquery with * and row # create table t1 (a integer, b integer); select (select * from t1) = (select 1,2); select (select 1,2) = (select * from t1); # queries whih can be converted to IN select row(1,2) = ANY (select * from t1); select row(1,2) != ALL (select * from t1); drop table t1; # # Comparison subquery and row with nested rows # create table t1 (a integer, b integer); -- error 1241 select row(1,(2,2)) in (select * from t1 ); -- error 1241 select row(1,(2,2)) = (select * from t1 ); -- error 1241 select (select * from t1) = row(1,(2,2)); drop table t1; # # Forward reference detection # create table t1 (a integer); insert into t1 values (1); -- error 1247 select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx ; -- error 1247 select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; select 1 as xx, 1 = ALL ( select 1 from t1 where 1 = xx ); -- error 1247 select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; -- error 1247 select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx from DUAL; drop table t1; # # cleaning up of results of subselects (BUG#8125) # CREATE TABLE `t1` ( `a` char(3) NOT NULL default '', `b` char(3) NOT NULL default '', `c` char(3) NOT NULL default '', PRIMARY KEY (`a`,`b`,`c`)) ENGINE=InnoDB; CREATE TABLE t2 LIKE t1; INSERT INTO t1 VALUES (1,1,1); INSERT INTO t2 VALUES (1,1,1); PREPARE my_stmt FROM "SELECT t1.b, count(*) FROM t1 group by t1.b having count(*) > ALL (SELECT COUNT(*) FROM t2 WHERE t2.a=1 GROUP By t2.b)"; EXECUTE my_stmt; EXECUTE my_stmt; deallocate prepare my_stmt; drop table t1,t2;
sql/item.cc +4 −2 Original line number Diff line number Diff line Loading @@ -1482,12 +1482,13 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) } else if (refer != (Item **)not_found_item) { if (!(*refer)->fixed) if (!last->ref_pointer_array[counter]) { my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, "forward reference in item list"); return -1; } DBUG_ASSERT((*refer)->fixed); /* Here, a subset of actions performed by Item_ref::set_properties is not enough. So we pass ptr to NULL into Item_[direct]_ref Loading Loading @@ -2161,12 +2162,13 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) mark_as_dependent(thd, last, thd->lex->current_select, fld); return 0; } if (!(*ref)->fixed) if (!last->ref_pointer_array[counter]) { my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, "forward reference in item list"); return -1; } DBUG_ASSERT((*ref)->fixed); mark_as_dependent(thd, last, thd->lex->current_select, this); if (place == IN_HAVING) Loading