diff options
Diffstat (limited to 'mysql-test/t')
-rw-r--r-- | mysql-test/t/ansi.test | 5 | ||||
-rw-r--r-- | mysql-test/t/derived.test | 9 | ||||
-rw-r--r-- | mysql-test/t/func_system.test | 2 | ||||
-rw-r--r-- | mysql-test/t/lowercase_table.test | 1 | ||||
-rw-r--r-- | mysql-test/t/olap.test | 96 | ||||
-rw-r--r-- | mysql-test/t/sql_mode.test | 4 | ||||
-rw-r--r-- | mysql-test/t/subselect.test | 14 |
7 files changed, 97 insertions, 34 deletions
diff --git a/mysql-test/t/ansi.test b/mysql-test/t/ansi.test index da82b7a9e31..f4aef5c3f8e 100644 --- a/mysql-test/t/ansi.test +++ b/mysql-test/t/ansi.test @@ -17,3 +17,8 @@ SELECT id,NULL,1,1.1,'a' FROM t1 GROUP BY id; --error 1055 SELECT id FROM t1 GROUP BY id2; drop table t1; + +set sql_mode="MySQL40"; +select @@sql_mode; +set sql_mode="ANSI"; +select @@sql_mode; diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test index 2ce90c93bd9..4f0af1edbaa 100644 --- a/mysql-test/t/derived.test +++ b/mysql-test/t/derived.test @@ -65,3 +65,12 @@ SELECT 1 as a FROM (SELECT a UNION SELECT 1) b; SELECT 1 as a FROM (SELECT 1 UNION SELECT a) b; --error 1054 select 1 from (select 2) a order by 0; + +# +# Test of explain (bug #251) +# + +create table t1 (id int); +insert into t1 values (1),(2),(3); +describe select * from (select * from t1 group by id) bar; +drop table t1; diff --git a/mysql-test/t/func_system.test b/mysql-test/t/func_system.test index 41b776719dc..998b2a5c3f4 100644 --- a/mysql-test/t/func_system.test +++ b/mysql-test/t/func_system.test @@ -18,7 +18,7 @@ select version()>=_utf8"3.23.29"; select version()>=_latin1"3.23.29"; select charset(version()); -create table t1 select database(), user(), version(); +create table t1 (version char(40)) select database(), user(), version() as 'version'; show create table t1; drop table t1; diff --git a/mysql-test/t/lowercase_table.test b/mysql-test/t/lowercase_table.test index f3a747c4d61..348116b02f2 100644 --- a/mysql-test/t/lowercase_table.test +++ b/mysql-test/t/lowercase_table.test @@ -14,4 +14,3 @@ ALTER TABLE T2 ADD new_col int not null; ALTER TABLE T2 RENAME T3; show tables like 't_'; drop table t3; - diff --git a/mysql-test/t/olap.test b/mysql-test/t/olap.test index 99bb2656001..3b1e3fac7c2 100644 --- a/mysql-test/t/olap.test +++ b/mysql-test/t/olap.test @@ -1,31 +1,79 @@ --disable_warnings -drop table if exists t1; +drop table if exists t1,t2; --enable_warnings -create table t1 ( product varchar(32), country varchar(32), year int, profit int); -insert into t1 values ( 'Computer', 'India',2000, 1200), -( 'TV', 'United States', 1999, 150), -( 'Calculator', 'United States', 1999,50), -( 'Computer', 'United States', 1999,1500), -( 'Computer', 'United States', 2000,1500), -( 'TV', 'United States', 2000, 150), -( 'TV', 'India', 2000, 100), -( 'TV', 'India', 2000, 100), -( 'Calculator', 'United States', 2000,75), -( 'Calculator', 'India', 2000,75), -( 'TV', 'India', 1999, 100), -( 'Computer', 'India', 1999,1200), -( 'Computer', 'United States', 2000,1500), -( 'Calculator', 'United States', 2000,75); ---error 1235 -select product, country , year, sum(profit) from t1 group by product, country, year with cube; ---error 1235 -explain select product, country , year, sum(profit) from t1 group by product, country, year with cube; +create table t1 (product varchar(32), country_id int not null, year int, profit int); +insert into t1 values ( 'Computer', 2,2000, 1200), +( 'TV', 1, 1999, 150), +( 'Calculator', 1, 1999,50), +( 'Computer', 1, 1999,1500), +( 'Computer', 1, 2000,1500), +( 'TV', 1, 2000, 150), +( 'TV', 2, 2000, 100), +( 'TV', 2, 2000, 100), +( 'Calculator', 1, 2000,75), +( 'Calculator', 2, 2000,75), +( 'TV', 1, 1999, 100), +( 'Computer', 1, 1999,1200), +( 'Computer', 2, 2000,1500), +( 'Calculator', 2, 2000,75), +( 'Phone', 3, 2003,10) +; + +create table t2 (country_id int primary key, country char(20) not null); +insert into t2 values (1, 'USA'),(2,'India'), (3,'Finland'); + +# First simple rollups, with just grand total +select product, sum(profit) from t1 group by product; +select product, sum(profit) from t1 group by product with rollup; +select product, sum(profit) from t1 group by 1 with rollup; +select product, sum(profit),avg(profit) from t1 group by product with rollup; + +# Sub totals +select product, country_id , year, sum(profit) from t1 group by product, country_id, year; +select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup; +explain select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup; +select product, country_id , sum(profit) from t1 group by product desc, country_id with rollup; + +# limit +select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup limit 5; +select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup limit 3,3; + +select product, country_id, count(*), count(distinct year) from t1 group by product, country_id; +select product, country_id, count(*), count(distinct year) from t1 group by product, country_id with rollup; + +# Test of having +select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup having country_id = 1; +select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup having sum(profit) > 200; +select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup having sum(profit) > 7000; + +# Functions +select concat(product,':',country_id) as 'prod', concat(":",year,":") as 'year',1+1, sum(profit)/count(*) from t1 group by 1,2 with rollup; +select product, sum(profit)/count(*) from t1 group by product with rollup; +select left(product,4) as prod, sum(profit)/count(*) from t1 group by prod with rollup; +select concat(product,':',country_id), 1+1, sum(profit)/count(*) from t1 group by concat(product,':',country_id) with rollup; + +# Joins +select product, country , year, sum(profit) from t1,t2 where t1.country_id=t2.country_id group by product, country, year with rollup; + +# Derived tables and sub selects +select product, `sum` from (select product, sum(profit) as 'sum' from t1 group by product with rollup) as tmp where product is null; +select product from t1 where exists (select product, country_id , sum(profit) from t1 as t2 where t1.product=t2.product group by product, country_id with rollup having sum(profit) > 6000); + +# The following doesn't return the expected answer, but this is a limitation +# in the implementation so we should just document it +select product, country_id , year, sum(profit) from t1 group by product, country_id, year having country_id is NULL; +select concat(':',product,':'), sum(profit),avg(profit) from t1 group by product with rollup; + +# Error handling + +# Cube is not yet implemented --error 1235 -select product, country , year, sum(profit) from t1 group by product, country, year with rollup; +select product, country_id , year, sum(profit) from t1 group by product, country_id, year with cube; --error 1235 -explain select product, country , year, sum(profit) from t1 group by product, country, year with rollup; +explain select product, country_id , year, sum(profit) from t1 group by product, country_id, year with cube; --error 1235 -select product, country , year, sum(profit) from t1 group by product, country, year with cube union all select product, country , year, sum(profit) from t1 group by product, country, year with rollup; -drop table t1; +select product, country_id , year, sum(profit) from t1 group by product, country_id, year with cube union all select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup; + +drop table t1,t2; diff --git a/mysql-test/t/sql_mode.test b/mysql-test/t/sql_mode.test index fd464f74de4..d3531f0c440 100644 --- a/mysql-test/t/sql_mode.test +++ b/mysql-test/t/sql_mode.test @@ -24,7 +24,7 @@ show create table t1; set @@sql_mode="no_field_options,mysql323,mysql40"; show variables like 'sql_mode'; show create table t1; -set @@sql_mode="postgresql,oracle,mssql,db2,sapdb"; -show variables like 'sql_mode'; +set sql_mode="postgresql,oracle,mssql,db2,sapdb"; +select @@sql_mode; show create table t1; drop table t1; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 8377a756c5b..c116d03e274 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -59,7 +59,7 @@ SELECT 1 as a,(SELECT a+a) b,(SELECT b); create table t1 (a int); create table t2 (a int, b int); create table t3 (a int); -create table t4 (a int, b int); +create table t4 (a int not null, b int not null); insert into t1 values (2); insert into t2 values (1,7),(2,7); insert into t4 values (4,8),(3,8),(5,9); @@ -106,11 +106,13 @@ delete from t2 where a=100; select * from t3 where a in (select a,b from t2); -- error 1239 select * from t3 where a in (select * from t2); -insert into t4 values (12,7),(1,7),(10,9),(9,6),(7,6),(3,9); -select b,max(a) as ma from t4 group by b having b < (select max(t2.a) -from t2 where t2.b=t4.b); -select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) -from t2 where t2.b=t4.b); +insert into t4 values (12,7),(1,7),(10,9),(9,6),(7,6),(3,9),(1,10); +-- empty set +select b,max(a) as ma from t4 group by b having b < (select max(t2.a) from t2 where t2.b=t4.b); +insert into t2 values (2,10); +select b,max(a) as ma from t4 group by b having ma < (select max(t2.a) from t2 where t2.b=t4.b); +delete from t2 where a=2 and b=10; +select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 where t2.b=t4.b); create table t5 (a int); select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; insert into t5 values (5); |