mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 13:02:28 +01:00
36b6bf2ef3
into mysql.com:/home/my/mysql-5.0 BitKeeper/etc/ignore: auto-union BitKeeper/deleted/.del-ctype_cp932.test: Auto merged BitKeeper/deleted/.del-isam.test~834fb0ee8196c445: Auto merged include/thr_lock.h: Auto merged mysql-test/t/alias.test: Auto merged mysql-test/t/alter_table.test: Auto merged mysql-test/t/archive.test: Auto merged mysql-test/t/backup.test: Auto merged mysql-test/t/bool.test: Auto merged mysql-test/t/connect.test: Auto merged mysql-test/t/count_distinct2.test: Auto merged mysql-test/t/create.test: Auto merged mysql-test/t/ctype_many.test: Auto merged mysql-test/t/ctype_ucs_binlog.test: Auto merged mysql-test/t/date_formats.test: Auto merged mysql-test/t/delayed.test: Auto merged mysql-test/t/derived.test: Auto merged mysql-test/t/distinct.test: Auto merged mysql-test/t/drop.test: Auto merged mysql-test/t/endspace.test: Auto merged mysql-test/t/flush.test: Auto merged mysql-test/t/fulltext.test: Auto merged mysql-test/t/fulltext_order_by.test: Auto merged mysql-test/t/func_compress.test: Auto merged mysql-test/t/func_concat.test: Auto merged mysql-test/t/func_date_add.test: Auto merged mysql-test/t/func_equal.test: Auto merged mysql-test/t/func_if.test: Auto merged mysql-test/t/func_sapdb.test: Auto merged mysql-test/t/func_set.test: Auto merged mysql-test/t/func_str.test: Auto merged mysql-test/t/gis-rtree.test: Auto merged mysql-test/t/gis.test: Auto merged mysql-test/t/grant.test: Auto merged mysql-test/t/grant2.test: Auto merged mysql-test/t/grant_cache.test: Auto merged mysql-test/t/heap.test: Auto merged mysql-test/t/heap_btree.test: Auto merged mysql-test/t/heap_hash.test: Auto merged mysql-test/t/init_connect.test: Auto merged mysql-test/t/insert_select.test: Auto merged mysql-test/t/insert_update.test: Auto merged mysql-test/t/key.test: Auto merged mysql-test/t/keywords.test: Auto merged mysql-test/t/limit.test: Auto merged mysql-test/t/lock.test: Auto merged mysql-test/t/lowercase_table.test: Auto merged mysql-test/t/lowercase_table3.test: Auto merged mysql-test/t/merge.test: Auto merged mysql-test/t/mix_innodb_myisam_binlog.test: Auto merged mysql-test/t/myisam.test: Auto merged mysql-test/t/mysqlbinlog2.test: Auto merged mysql-test/t/ndb_alter_table.test: Auto merged mysql-test/t/ndb_autodiscover.test: Auto merged mysql-test/t/ndb_charset.test: Auto merged mysql-test/t/ndb_grant.later: Auto merged mysql-test/t/ndb_index_ordered.test: Auto merged mysql-test/t/ndb_index_unique.test: Auto merged mysql-test/t/ndb_restore.test: Auto merged mysql-test/t/ndb_types.test: Auto merged mysql-test/t/ndb_update.test: Auto merged mysql-test/t/null.test: Auto merged mysql-test/t/null_key.test: Auto merged mysql-test/t/olap.test: Auto merged mysql-test/t/openssl_1.test: Auto merged mysql-test/t/order_by.test: Auto merged mysql-test/t/ps.test: Auto merged mysql-test/t/ps_1general.test: Auto merged mysql-test/t/ps_4heap.test: Auto merged mysql-test/t/ps_5merge.test: Auto merged mysql-test/t/query_cache.test: Auto merged mysql-test/t/replace.test: Auto merged mysql-test/t/row.test: Auto merged mysql-test/t/rpl000001.test: Auto merged mysql-test/t/rpl000015.test: Auto merged mysql-test/t/rpl000017.test: Auto merged mysql-test/t/rpl000018.test: Auto merged mysql-test/t/rpl_EE_error.test: Auto merged mysql-test/t/rpl_change_master.test: Auto merged mysql-test/t/rpl_charset.test: Auto merged mysql-test/t/rpl_create_database.test: Auto merged mysql-test/t/rpl_ddl.test: Auto merged mysql-test/t/rpl_deadlock.test: Auto merged mysql-test/t/rpl_empty_master_crash.test: Auto merged mysql-test/t/rpl_error_ignored_table.test: Auto merged mysql-test/t/rpl_flush_log_loop.test: Auto merged mysql-test/t/rpl_flush_tables.test: Auto merged mysql-test/t/rpl_get_lock.test: Auto merged mysql-test/t/rpl_heap.test: Auto merged mysql-test/t/rpl_loaddata.test: Auto merged mysql-test/t/rpl_loaddata_rule_m.test: Auto merged mysql-test/t/rpl_log.test: Auto merged mysql-test/t/rpl_log_pos.test: Auto merged mysql-test/t/rpl_max_relay_size.test: Auto merged mysql-test/t/rpl_multi_query.test: Auto merged mysql-test/t/rpl_openssl.test: Auto merged mysql-test/t/rpl_redirect.test: Auto merged mysql-test/t/rpl_relayrotate.test: Auto merged mysql-test/t/rpl_replicate_do.test: Auto merged mysql-test/t/rpl_reset_slave.test: Auto merged mysql-test/t/rpl_server_id2.test: Auto merged mysql-test/t/rpl_temporary.test: Auto merged mysql-test/t/rpl_timezone.test: Auto merged mysql-test/t/rpl_user_variables.test: Auto merged mysql-test/t/show_check.test: Auto merged mysql-test/t/subselect.test: Auto merged mysql-test/t/symlink.test: Auto merged mysql-test/t/synchronization.test: Auto merged mysql-test/t/system_mysql_db.test: Auto merged mysql-test/t/system_mysql_db_fix.test: Auto merged mysql-test/t/temp_table.test: Auto merged mysql-test/t/timezone2.test: Auto merged mysql-test/t/timezone_grant.test: Auto merged mysql-test/t/type_float.test: Auto merged mysql-test/t/type_ranges.test: Auto merged mysql-test/t/type_timestamp.test: Auto merged mysql-test/t/union.test: Auto merged mysql-test/t/update.test: Auto merged mysql-test/t/user_var-binlog.test: Auto merged mysql-test/t/warnings.test: Auto merged mysys/thr_lock.c: Auto merged sql/slave.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_lex.cc: Auto merged sql/sql_select.cc: Auto merged support-files/mysql.spec.sh: Auto merged BitKeeper/deleted/.del-rpl_trunc_binlog.test~961b1f6ac73d37c8: Simple merge mysql-test/r/ps_grant.result: Simple merge mysql-test/t/analyse.test: Simple merge mysql-test/t/auto_increment.test: Simple merge mysql-test/t/bdb.test: Simple merge mysql-test/t/bigint.test: Simple merge mysql-test/t/case.test: Simple merge mysql-test/t/cast.test: Simple merge mysql-test/t/check.test: Simple merge mysql-test/t/count_distinct.test: Simple merge mysql-test/t/ctype_latin1_de.test: Simple merge mysql-test/t/ctype_uca.test: Simple merge mysql-test/t/ctype_ucs.test: Simple merge mysql-test/t/ctype_utf8.test: Simple merge mysql-test/t/delete.test: Simple merge mysql-test/t/flush_block_commit.test: Simple merge mysql-test/t/func_default.test: Simple merge mysql-test/t/func_gconcat.test: Simple merge mysql-test/t/func_group.test: Aligned code with 4.1 mysql-test/t/func_in.test: Simple merge mysql-test/t/func_math.test: Simple merge mysql-test/t/func_misc.test: Simple merge mysql-test/t/func_test.test: Simple merge mysql-test/t/func_time.test: Simple merge mysql-test/t/group_by.test: Simple merge mysql-test/t/having.test: Simple merge mysql-test/t/innodb.test: Simple merge mysql-test/t/insert.test: Simple merge mysql-test/t/join_outer.test: Simple merge mysql-test/t/kill.test: Simple merge mysql-test/t/loaddata.test: Simple merge mysql-test/t/lock_multi.test: Simple merge mysql-test/t/multi_update.test: Simple merge mysql-test/t/mysqlbinlog.test: Simple merge mysql-test/t/mysqldump.test: Aligned code with 4.1 mysql-test/t/mysqltest.test: Simple merge mysql-test/t/ndb_basic.test: Simple merge mysql-test/t/ndb_cache.test: Simple merge mysql-test/t/ndb_subquery.test: Simple merge mysql-test/t/ps_grant.test: Simple merge mysql-test/t/range.test: Simple merge mysql-test/t/rpl_drop_temp.test: Simple merge mysql-test/t/rpl_loaddata_rule_s.test: Simple merge mysql-test/t/rpl_loaddatalocal.test: Simple merge mysql-test/t/rpl_rotate_logs.test: Simple merge mysql-test/t/rpl_until.test: Simple merge mysql-test/t/rpl_variables.test: Simple merge mysql-test/t/select.test: Simple merge mysql-test/t/sql_mode.test: Simple merge mysql-test/t/type_blob.test: Simple merge mysql-test/t/type_decimal.test: Simple merge mysql-test/t/user_var.test: Simple merge mysql-test/t/variables.test: Simple merge sql/lock.cc: Simple optimization sql/mysql_priv.h: Simple merge sql/sql_table.cc: Simple merge sql/table.cc: Simple merge sql/unireg.cc: Simple merge
280 lines
9.3 KiB
Text
280 lines
9.3 KiB
Text
--disable_warnings
|
|
drop table if exists t1,t2;
|
|
--enable_warnings
|
|
|
|
set @sav_dpi= @@div_precision_increment;
|
|
set div_precision_increment= 5;
|
|
show variables like 'div_precision_increment';
|
|
|
|
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 extended 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_id , year, sum(profit) from t1 group by product, country_id, year with cube;
|
|
--error 1235
|
|
explain select product, country_id , year, sum(profit) from t1 group by product, country_id, year with cube;
|
|
--error 1235
|
|
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;
|
|
|
|
#
|
|
# Test bug with const tables
|
|
#
|
|
|
|
CREATE TABLE t1 (i int);
|
|
INSERT INTO t1 VALUES(100);
|
|
CREATE TABLE t2 (i int);
|
|
INSERT INTO t2 VALUES (100),(200);
|
|
SELECT i, COUNT(*) FROM t1 GROUP BY i WITH ROLLUP;
|
|
SELECT t1.i, t2.i, COUNT(*) FROM t1,t2 GROUP BY t1.i,t2.i WITH ROLLUP;
|
|
drop table t1,t2;
|
|
|
|
#bug #4767: ROLLUP with LEFT JOIN
|
|
|
|
CREATE TABLE user_day(
|
|
user_id INT NOT NULL,
|
|
date DATE NOT NULL,
|
|
UNIQUE INDEX user_date (user_id, date)
|
|
);
|
|
|
|
INSERT INTO user_day VALUES
|
|
(1, '2004-06-06' ),
|
|
(1, '2004-06-07' ),
|
|
(2, '2004-06-06' );
|
|
|
|
SELECT
|
|
d.date AS day,
|
|
COUNT(d.user_id) as sample,
|
|
COUNT(next_day.user_id) AS not_cancelled
|
|
FROM user_day d
|
|
LEFT JOIN user_day next_day
|
|
ON next_day.user_id=d.user_id AND
|
|
next_day.date= DATE_ADD( d.date, interval 1 day )
|
|
GROUP BY day;
|
|
|
|
SELECT
|
|
d.date AS day,
|
|
COUNT(d.user_id) as sample,
|
|
COUNT(next_day.user_id) AS not_cancelled
|
|
FROM user_day d
|
|
LEFT JOIN user_day next_day
|
|
ON next_day.user_id=d.user_id AND
|
|
next_day.date= DATE_ADD( d.date, interval 1 day )
|
|
GROUP BY day
|
|
WITH ROLLUP;
|
|
|
|
DROP TABLE user_day;
|
|
|
|
#
|
|
# Tests for bugs #8616, #8615: distinct sum with rollup
|
|
#
|
|
|
|
CREATE TABLE t1 (a int, b int);
|
|
|
|
INSERT INTO t1 VALUES
|
|
(1,4),
|
|
(2,2), (2,2),
|
|
(4,1), (4,1), (4,1), (4,1),
|
|
(2,1), (2,1);
|
|
|
|
SELECT SUM(b) FROM t1 GROUP BY a WITH ROLLUP;
|
|
SELECT DISTINCT SUM(b) FROM t1 GROUP BY a WITH ROLLUP;
|
|
|
|
SELECT SUM(b), COUNT(DISTINCT b) FROM t1 GROUP BY a WITH ROLLUP;
|
|
SELECT DISTINCT SUM(b), COUNT(DISTINCT b) FROM t1 GROUP BY a WITH ROLLUP;
|
|
|
|
SELECT SUM(b), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
|
|
SELECT DISTINCT SUM(b), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
|
|
|
|
SELECT SUM(b), COUNT(DISTINCT b), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
|
|
SELECT DISTINCT SUM(b), COUNT(DISTINCT b), COUNT(*) FROM t1
|
|
GROUP BY a WITH ROLLUP;
|
|
|
|
SELECT a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP;
|
|
SELECT DISTINCT a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP;
|
|
|
|
SELECT b, a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP;
|
|
SELECT DISTINCT b,a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP;
|
|
|
|
ALTER TABLE t1 ADD COLUMN c INT;
|
|
SELECT a,b,sum(c) FROM t1 GROUP BY a,b,c WITH ROLLUP;
|
|
SELECT distinct a,b,sum(c) FROM t1 GROUP BY a,b,c WITH ROLLUP;
|
|
|
|
DROP TABLE t1;
|
|
|
|
#
|
|
# Tests for bugs #8617: SQL_CACL_FOUND_ROWS with rollup and limit
|
|
#
|
|
|
|
CREATE TABLE t1 (a int, b int);
|
|
|
|
INSERT INTO t1 VALUES
|
|
(1,4),
|
|
(2,2), (2,2),
|
|
(4,1), (4,1), (4,1), (4,1),
|
|
(2,1), (2,1);
|
|
|
|
SELECT a, SUM(b) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1;
|
|
SELECT SQL_CALC_FOUND_ROWS a, SUM(b) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1;
|
|
|
|
DROP TABLE t1;
|
|
|
|
#
|
|
# Tests for bug #9681: ROLLUP in subquery for derived table wiht
|
|
# a group by field declared as NOT NULL
|
|
#
|
|
|
|
CREATE TABLE t1 (a int(11) NOT NULL);
|
|
INSERT INTO t1 VALUES (1),(2);
|
|
|
|
SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP;
|
|
SELECT * FROM ( SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP ) t2;
|
|
|
|
DROP TABLE t1;
|
|
set div_precision_increment= @sav_dpi;
|
|
|
|
#
|
|
# Tests for bug #7914: ROLLUP over expressions on temporary table
|
|
#
|
|
|
|
CREATE TABLE t1 (a int(11));
|
|
INSERT INTO t1 VALUES (1),(2);
|
|
|
|
SELECT a, SUM(a), SUM(a)+1 FROM (SELECT a FROM t1 UNION select 2) d
|
|
GROUP BY a;
|
|
SELECT a, SUM(a), SUM(a)+1 FROM (SELECT a FROM t1 UNION select 2) d
|
|
GROUP BY a WITH ROLLUP;
|
|
|
|
SELECT a, SUM(a), SUM(a)+1 FROM (SELECT 1 a UNION select 2) d
|
|
GROUP BY a;
|
|
SELECT a, SUM(a), SUM(a)+1 FROM (SELECT 1 a UNION select 2) d
|
|
GROUP BY a WITH ROLLUP;
|
|
|
|
SELECT a, SUM(a), SUM(a)+1, CONCAT(SUM(a),'x'), SUM(a)+SUM(a), SUM(a)
|
|
FROM (SELECT 1 a, 2 b UNION SELECT 2,3 UNION SELECT 5,6 ) d
|
|
GROUP BY a WITH ROLLUP;
|
|
|
|
DROP TABLE t1;
|
|
|
|
#
|
|
# Tests for bug #7894: ROLLUP over expressions on group by attributes
|
|
#
|
|
|
|
CREATE TABLE t1 (a int(11));
|
|
INSERT INTO t1 VALUES (1),(2);
|
|
|
|
SELECT a, a+1, SUM(a) FROM t1 GROUP BY a WITH ROLLUP;
|
|
SELECT a+1 FROM t1 GROUP BY a WITH ROLLUP;
|
|
SELECT a+SUM(a) FROM t1 GROUP BY a WITH ROLLUP;
|
|
SELECT a, a+1 as b FROM t1 GROUP BY a WITH ROLLUP HAVING b > 2;
|
|
SELECT a, a+1 as b FROM t1 GROUP BY a WITH ROLLUP HAVING a IS NULL;
|
|
SELECT a, a+1 as b FROM t1 GROUP BY a WITH ROLLUP HAVING b IS NULL;
|
|
SELECT IFNULL(a, 'TEST') FROM t1 GROUP BY a WITH ROLLUP;
|
|
|
|
CREATE TABLE t2 (a int, b int);
|
|
INSERT INTO t2 VALUES
|
|
(1,4),
|
|
(2,2), (2,2),
|
|
(4,1), (4,1), (4,1), (4,1),
|
|
(2,1), (2,1);
|
|
|
|
SELECT a,b,SUM(b) FROM t2 GROUP BY a,b WITH ROLLUP;
|
|
SELECT a,b,SUM(b), a+b as c FROM t2
|
|
GROUP BY a,b WITH ROLLUP HAVING c IS NULL;
|
|
SELECT IFNULL(a, 'TEST'), COALESCE(b, 'TEST') FROM t2
|
|
GROUP BY a, b WITH ROLLUP;
|
|
|
|
DROP TABLE t1,t2;
|
|
|
|
#
|
|
# Tests for bug #11639: ROLLUP over view executed through filesort
|
|
#
|
|
|
|
CREATE TABLE t1(id int, type char(1));
|
|
INSERT INTO t1 VALUES
|
|
(1,"A"),(2,"C"),(3,"A"),(4,"A"),(5,"B"),
|
|
(6,"B"),(7,"A"),(8,"C"),(9,"A"),(10,"C");
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
SELECT type FROM t1 GROUP BY type WITH ROLLUP;
|
|
SELECT type FROM v1 GROUP BY type WITH ROLLUP;
|
|
EXPLAIN SELECT type FROM v1 GROUP BY type WITH ROLLUP;
|
|
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
# Test for bug #11543: ROLLUP query with a repeated column in GROUP BY
|
|
#
|
|
|
|
CREATE TABLE t1 (a INT(10) NOT NULL, b INT(10) NOT NULL);
|
|
INSERT INTO t1 VALUES (1, 1);
|
|
INSERT INTO t1 VALUES (1, 2);
|
|
|
|
SELECT a, b, a AS c, COUNT(*) AS count FROM t1 GROUP BY a, b, c WITH ROLLUP;
|
|
|
|
DROP TABLE t1;
|
|
|
|
# End of 4.1 tests
|