ALTER DATABASE test CHARACTER SET latin1 COLLATE latin1_swedish_ci; set @sav_dpi= @@div_precision_increment; set div_precision_increment= 5;
show variables like 'div_precision_increment';
Variable_name Value
div_precision_increment 5
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');
select product, sum(profit) from t1 group by product;
product sum(profit)
Calculator 275
Computer 6900
Phone 10
TV 600
select product, sum(profit) from t1 group by product with rollup;
product sum(profit)
Calculator 275
Computer 6900
Phone 10
TV 600
NULL 7785
select product, sum(profit) from t1 group by 1 with rollup;
product sum(profit)
Calculator 275
Computer 6900
Phone 10
TV 600
NULL 7785
select product, sum(profit),avg(profit) from t1 group by product with rollup;
product sum(profit) avg(profit)
Calculator 27568.75000
Computer 69001380.00000
Phone 1010.00000
TV 600120.00000
NULL 7785519.00000
select product, country_id , year, sum(profit) from t1 group by product, country_id, year;
product country_id year sum(profit)
Calculator 1199950
Calculator 1200075
Calculator 22000150
Computer 119992700
Computer 120001500
Computer 220002700
Phone 3200310
TV 11999250
TV 12000150
TV 22000200
select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup;
product country_id year sum(profit)
Calculator 1199950
Calculator 1200075
Calculator 1 NULL 125
Calculator 22000150
Calculator 2 NULL 150
Calculator NULL NULL 275
Computer 119992700
Computer 120001500
Computer 1 NULL 4200
Computer 220002700
Computer 2 NULL 2700
Computer NULL NULL 6900
Phone 3200310
Phone 3 NULL 10
Phone NULL NULL 10
TV 11999250
TV 12000150
TV 1 NULL 400
TV 22000200
TV 2 NULL 200
TV NULL NULL 600
NULL NULL NULL 7785
explain extended select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup;
id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 15100.00 Using filesort
Warnings:
Note 1003 select `test`.`t1`.`product` AS `product`,`test`.`t1`.`country_id` AS `country_id`,`test`.`t1`.`year` AS `year`,sum(`test`.`t1`.`profit`) AS `sum(profit)` from `test`.`t1` group by `test`.`t1`.`product`,`test`.`t1`.`country_id`,`test`.`t1`.`year` with rollup
select product, country_id , sum(profit) from t1 group by product desc, country_id with rollup;
product country_id sum(profit)
TV 1400
TV 2200
TV NULL 600
Phone 310
Phone NULL 10
Computer 14200
Computer 22700
Computer NULL 6900
Calculator 1125
Calculator 2150
Calculator NULL 275
NULL NULL 7785
select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup limit 5;
product country_id year sum(profit)
Calculator 1199950
Calculator 1200075
Calculator 1 NULL 125
Calculator 22000150
Calculator 2 NULL 150
select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup limit 3,3;
product country_id year sum(profit)
Calculator 22000150
Calculator 2 NULL 150
Calculator NULL NULL 275
select product, country_id, count(*), count(distinct year) from t1 group by product, country_id;
product country_id count(*) count(distinct year)
Calculator 122
Calculator 221
Computer 132
Computer 221
Phone 311
TV 132
TV 221
select product, country_id, count(*), count(distinct year) from t1 group by product, country_id with rollup;
product country_id count(*) count(distinct year)
Calculator 122
Calculator 221
Calculator NULL 42
Computer 132
Computer 221
Computer NULL 52
Phone 311
Phone NULL 11
TV 132
TV 221
TV NULL 52
NULL NULL 153
select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup having country_id = 1;
product country_id year sum(profit)
Calculator 1199950
Calculator 1200075
Calculator 1 NULL 125
Computer 119992700
Computer 120001500
Computer 1 NULL 4200
TV 11999250
TV 12000150
TV 1 NULL 400
select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup having sum(profit) > 200;
product country_id year sum(profit)
Calculator NULL NULL 275
Computer 119992700
Computer 120001500
Computer 1 NULL 4200
Computer 220002700
Computer 2 NULL 2700
Computer NULL NULL 6900
TV 11999250
TV 1 NULL 400
TV NULL NULL 600
NULL NULL NULL 7785
select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup having sum(profit) > 7000;
product country_id year sum(profit)
NULL NULL NULL 7785
select concat(product,':',country_id) as 'prod', concat(":",year,":") as 'year',1+1, sum(profit)/count(*) from t1 group by 1,2 with rollup;
prod year 1+1 sum(profit)/count(*)
Calculator:1 :1999: 250.00000
Calculator:1 :2000: 275.00000
Calculator:1 NULL 262.50000
Calculator:2 :2000: 275.00000
Calculator:2 NULL 275.00000
Computer:1 :1999: 21350.00000
Computer:1 :2000: 21500.00000
Computer:1 NULL 21400.00000
Computer:2 :2000: 21350.00000
Computer:2 NULL 21350.00000
Phone:3 :2003: 210.00000
Phone:3 NULL 210.00000
TV:1 :1999: 2125.00000
TV:1 :2000: 2150.00000
TV:1 NULL 2133.33333
TV:2 :2000: 2100.00000
TV:2 NULL 2100.00000
NULL NULL 2519.00000
select product, sum(profit)/count(*) from t1 group by product with rollup;
product sum(profit)/count(*)
Calculator 68.75000
Computer 1380.00000
Phone 10.00000
TV 120.00000
NULL 519.00000
select left(product,4) as prod, sum(profit)/count(*) from t1 group by prod with rollup;
prod sum(profit)/count(*)
Calc 68.75000
Comp 1380.00000
Phon 10.00000
TV 120.00000
NULL 519.00000
select concat(product,':',country_id), 1+1, sum(profit)/count(*) from t1 group by concat(product,':',country_id) with rollup;
concat(product,':',country_id) 1+1 sum(profit)/count(*)
Calculator:1262.50000
Calculator:2275.00000
Computer:121400.00000
Computer:221350.00000
Phone:3210.00000
TV:12133.33333
TV:22100.00000
NULL 2519.00000
select product, country , year, sum(profit) from t1,t2 where t1.country_id=t2.country_id group by product, country, year with rollup;
product country year sum(profit)
Calculator India 2000150
Calculator India NULL 150
Calculator USA 199950
Calculator USA 200075
Calculator USA NULL 125
Calculator NULL NULL 275
Computer India 20002700
Computer India NULL 2700
Computer USA 19992700
Computer USA 20001500
Computer USA NULL 4200
Computer NULL NULL 6900
Phone Finland 200310
Phone Finland NULL 10
Phone NULL NULL 10
TV India 2000200
TV India NULL 200
TV USA 1999250
TV USA 2000150
TV USA NULL 400
TV NULL NULL 600
NULL NULL NULL 7785
select product, `sum` from (select product, sum(profit) as 'sum' from t1 group by product with rollup) as tmp where product is null;
product sum
NULL 7785
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);
product
Computer
Computer
Computer
Computer
Computer
select product, country_id , year, sum(profit) from t1 group by product, country_id, year having country_id is NULL;
product country_id year sum(profit)
select concat(':',product,':'), sum(profit),avg(profit) from t1 group by product with rollup;
concat(':',product,':') sum(profit) avg(profit)
:Calculator: 27568.75000
:Computer: 69001380.00000
:Phone: 1010.00000
:TV: 600120.00000
NULL 7785519.00000
select product, country_id , year, sum(profit) from t1 group by product, country_id, year with cube; ERROR42000: This version of MariaDB doesn't yet support 'CUBE'
explain select product, country_id , year, sum(profit) from t1 group by product, country_id, year with cube; ERROR42000: This version of MariaDB doesn't yet support 'CUBE'
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; ERROR42000: This version of MariaDB doesn't yet support 'CUBE'
drop table t1,t2;
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;
i COUNT(*) 1001
NULL 1
SELECT t1.i, t2.i, COUNT(*) FROM t1,t2 GROUP BY t1.i,t2.i WITH ROLLUP;
i i COUNT(*) 1001001 1002001 100 NULL 2
NULL NULL 2
drop table t1,t2;
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;
day sample not_cancelled 2004-06-0621 2004-06-0710
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;
day sample not_cancelled 2004-06-0621 2004-06-0710
NULL 31
DROP TABLE user_day;
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;
SUM(b) 4 6 4 14
SELECT DISTINCT SUM(b) FROM t1 GROUP BY a WITH ROLLUP;
SUM(b) 4 6 14
SELECT SUM(b), COUNT(DISTINCT b) FROM t1 GROUP BY a WITH ROLLUP;
SUM(b) COUNT(DISTINCT b) 41 62 41 143
SELECT DISTINCT SUM(b), COUNT(DISTINCT b) FROM t1 GROUP BY a WITH ROLLUP;
SUM(b) COUNT(DISTINCT b) 41 62 143
SELECT SUM(b), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
SUM(b) COUNT(*) 41 64 44 149
SELECT DISTINCT SUM(b), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
SUM(b) COUNT(*) 41 64 44 149
SELECT SUM(b), COUNT(DISTINCT b), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
SUM(b) COUNT(DISTINCT b) COUNT(*) 411 624 414 1439
SELECT DISTINCT SUM(b), COUNT(DISTINCT b), COUNT(*) FROM t1
GROUP BY a WITH ROLLUP;
SUM(b) COUNT(DISTINCT b) COUNT(*) 411 624 414 1439
SELECT a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP;
a sum(b) 14 14 22 24 26 44 44
NULL 14
SELECT DISTINCT a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP;
a sum(b) 14 22 24 26 44
NULL 14
SELECT b, a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP;
b a sum(b) 414
NULL 14 122 224
NULL 26 144
NULL 44
NULL NULL 14
SELECT DISTINCT b,a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP;
b a sum(b) 414
NULL 14 122 224
NULL 26 144
NULL 44
NULL NULL 14
ALTER TABLE t1 ADD COLUMN c INT;
SELECT a,b,sum(c) FROM t1 GROUP BY a,b,c WITH ROLLUP;
a b sum(c) 14 NULL 14 NULL 1 NULL NULL 21 NULL 21 NULL 22 NULL 22 NULL 2 NULL NULL 41 NULL 41 NULL 4 NULL NULL
NULL NULL NULL
SELECT distinct a,b,sum(c) FROM t1 GROUP BY a,b,c WITH ROLLUP;
a b sum(c) 14 NULL 1 NULL NULL 21 NULL 22 NULL 2 NULL NULL 41 NULL 4 NULL NULL
NULL NULL NULL
DROP TABLE t1;
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;
a SUM(b) 14
SELECT SQL_CALC_FOUND_ROWS a, SUM(b) FROM t1 GROUP BY a WITH ROLLUP LIMIT 1;
a SUM(b) 14
DROP TABLE t1;
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;
a m 11 22
NULL 3
SELECT * FROM ( SELECT a, SUM(a) m FROM t1 GROUP BY a WITH ROLLUP ) t2;
a m 11 22
NULL 3
DROP TABLE t1; set div_precision_increment= @sav_dpi;
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;
a SUM(a) SUM(a)+1 112 223
SELECT a, SUM(a), SUM(a)+1 FROM (SELECT a FROM t1 UNION select 2) d
GROUP BY a WITH ROLLUP;
a SUM(a) SUM(a)+1 112 223
NULL 34
SELECT a, SUM(a), SUM(a)+1 FROM (SELECT 1 a UNION select 2) d
GROUP BY a;
a SUM(a) SUM(a)+1 112 223
SELECT a, SUM(a), SUM(a)+1 FROM (SELECT 1 a UNION select 2) d
GROUP BY a WITH ROLLUP;
a SUM(a) SUM(a)+1 112 223
NULL 34
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;
a SUM(a) SUM(a)+1 CONCAT(SUM(a),'x') SUM(a)+SUM(a) SUM(a) 1121x 21 2232x 42 5565x 105
NULL 898x 168
DROP TABLE t1;
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;
a a+1 SUM(a) 121 232
NULL NULL 3
SELECT a+1 FROM t1 GROUP BY a WITH ROLLUP;
a+1 2 3
NULL
SELECT a+SUM(a) FROM t1 GROUP BY a WITH ROLLUP;
a+SUM(a) 2 4
NULL
SELECT a, a+1 as b FROM t1 GROUP BY a WITH ROLLUP HAVING b > 2;
a b 23
SELECT a, a+1 as b FROM t1 GROUP BY a WITH ROLLUP HAVING a IS NULL;
a b
NULL NULL
SELECT a, a+1 as b FROM t1 GROUP BY a WITH ROLLUP HAVING b IS NULL;
a b
NULL NULL
SELECT IFNULL(a, 'TEST') FROM t1 GROUP BY a WITH ROLLUP;
IFNULL(a, 'TEST') 1 2
TEST
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;
a b SUM(b) 144 1 NULL 4 212 224 2 NULL 6 414 4 NULL 4
NULL NULL 14
SELECT a,b,SUM(b), a+b as c FROM t2
GROUP BY a,b WITH ROLLUP HAVING c IS NULL;
a b SUM(b) c 1 NULL 4 NULL 2 NULL 6 NULL 4 NULL 4 NULL
NULL NULL 14 NULL
SELECT IFNULL(a, 'TEST'), COALESCE(b, 'TEST') FROM t2
GROUP BY a, b WITH ROLLUP;
IFNULL(a, 'TEST') COALESCE(b, 'TEST') 14 1 TEST 21 22 2 TEST 41 4 TEST
TEST TEST
DROP TABLE t1,t2;
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;
a b c count 1111 11 NULL 1 1211 12 NULL 1 1 NULL NULL 2
NULL NULL NULL 2
DROP TABLE t1;
CREATE TABLE t1 (a int(11) NOT NULL);
INSERT INTO t1 VALUES (1),(2);
SELECT * FROM (SELECT a, a + 1, COUNT(*) FROM t1 GROUP BY a WITH ROLLUP) t;
a a + 1 COUNT(*) 121 231
NULL NULL 2
SELECT * FROM (SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP) t;
a LENGTH(a) COUNT(*) 111 211
NULL NULL 2
DROP TABLE t1;
create table t1 ( a varchar(9), b int );
insert into t1 values('a',1),(null,2);
select a, max(b) from t1 group by a with rollup;
a max(b)
NULL 2
a 1
NULL 2
select distinct a, max(b) from t1 group by a with rollup;
a max(b)
NULL 2
a 1
drop table t1;
create table t1 (a varchar(22) not null , b int);
insert into t1 values ("2006-07-01 21:30", 1), ("2006-07-01 23:30", 10);
select left(a,10), a, sum(b) from t1 group by 1,2 with rollup;
left(a,10) a sum(b) 2006-07-012006-07-0121:301 2006-07-012006-07-0123:3010 2006-07-01 NULL 11
NULL NULL 11
select left(a,10) x, a, sum(b) from t1 group by x,a with rollup;
x a sum(b) 2006-07-012006-07-0121:301 2006-07-012006-07-0123:3010 2006-07-01 NULL 11
NULL NULL 11
drop table t1;
CREATE TABLE t1 (a int, b int);
INSERT INTO t1
VALUES (2,10),(3,30),(2,40),(1,10),(2,30),(1,20),(2,10);
SELECT a, SUM(b) FROM t1 GROUP BY a WITH ROLLUP;
a SUM(b) 130 290 330
NULL 150
SELECT DISTINCT a, SUM(b) FROM t1 GROUP BY a WITH ROLLUP;
a SUM(b) 130 290 330
NULL 150
SELECT a, b, COUNT(*) FROM t1 GROUP BY a,b WITH ROLLUP;
a b COUNT(*) 1101 1201 1 NULL 2 2102 2301 2401 2 NULL 4 3301 3 NULL 1
NULL NULL 7
SELECT DISTINCT a, b, COUNT(*) FROM t1 GROUP BY a,b WITH ROLLUP;
a b COUNT(*) 1101 1201 1 NULL 2 2102 2301 2401 2 NULL 4 3301 3 NULL 1
NULL NULL 7
SELECT 'x', a, SUM(b) FROM t1 GROUP BY 1,2 WITH ROLLUP;
x a SUM(b)
x 130
x 290
x 330
x NULL 150
NULL NULL 150
SELECT DISTINCT 'x', a, SUM(b) FROM t1 GROUP BY 1,2 WITH ROLLUP;
x a SUM(b)
x 130
x 290
x 330
x NULL 150
NULL NULL 150
SELECT DISTINCT 'x', a, SUM(b) FROM t1 GROUP BY 1,2 WITH ROLLUP;
x a SUM(b)
x 130
x 290
x 330
x NULL 150
NULL NULL 150
DROP TABLE t1;
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;
type
A
B
C
NULL
SELECT type FROM v1 GROUP BY type WITH ROLLUP;
type
A
B
C
NULL
EXPLAIN SELECT type FROM v1 GROUP BY type WITH ROLLUP;
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using filesort
DROP VIEW v1;
DROP TABLE t1;
CREATE TABLE t1 (a int(11) NOT NULL);
INSERT INTO t1 VALUES (1),(2);
CREATE VIEW v1 AS
SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
DESC v1;
Field Type Null Key Default Extra
a int(11) YES NULL
LENGTH(a) int(10) YES NULL
COUNT(*) bigint(21) NO 0
SELECT * FROM v1;
a LENGTH(a) COUNT(*) 111 211
NULL NULL 2
DROP VIEW v1;
DROP TABLE t1;
CREATE TABLE t1 (a int, KEY (a));
INSERT INTO t1 VALUES (3), (1), (4), (1), (3), (1), (1);
SELECT * FROM (SELECT a, SUM(a) FROM t1 GROUP BY a WITH ROLLUP) as t;
a SUM(a) 14 36 44
NULL 14
DROP TABLE t1;
#
# Bug#31095: Unexpected NULL constant caused server crash.
#
create table t1(a int);
insert into t1 values (1),(2),(3);
select count(a) from t1 group by null with rollup;
count(a) 3 3
drop table t1;
##############################################################
CREATE TABLE t1(a INT);
INSERT INTO t1 VALUES(0);
SELECT 1 FROM t1 GROUP BY (DATE(NULL)) WITH ROLLUP; 1 1 1
DROP TABLE t1;
#
# Bug #48131: crash group by with rollup, distinct,
# filesort, with temporary tables
#
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY);
INSERT INTO t1 VALUES (1), (2);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (100);
SELECT a, b FROM t1, t2 GROUP BY a, b WITH ROLLUP;
a b 1100 1 NULL 2100 2 NULL
NULL NULL
SELECT DISTINCT b FROM t1, t2 GROUP BY a, b WITH ROLLUP;
b 100
NULL
DROP TABLE t1, t2;
#
# Bug #48475: DISTINCT is ignored with GROUP BY WITH ROLLUP
# and only const tables
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (b INT);
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (1);
SELECT DISTINCT b FROM t1, t2 GROUP BY a, b WITH ROLLUP;
b 1
NULL
DROP TABLE t1, t2;
End of 5.0 tests
#
# End of 10.0 tests
#
#
# MDEV-16190 Server crashes in Item_null_result::field_type on SELECT with time field, ROLLUP and HAVING
#
CREATE TABLE t1 (t TIME) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('12:12:12');
SELECT t, COUNT(*) FROM t1 GROUP BY t WITH ROLLUP HAVING t > '00:00:00';
t COUNT(*) 12:12:121
DROP TABLE t1;
CREATE TABLE t1 (t TIME) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('12:12:12'),('12:12:13');
SELECT t, COUNT(*) FROM t1 GROUP BY t WITH ROLLUP HAVING t > '00:00:00';
t COUNT(*) 12:12:121 12:12:131
DROP TABLE t1;
#
# MDEV-17830 Server crashes in Item_null_result::field_type upon SELECT with CHARSET(date) and ROLLUP
#
CREATE TABLE t (d DATE) ENGINE=MyISAM;
INSERT INTO t VALUES ('2018-12-12');
SELECT CHARSET(d) AS f FROM t GROUP BY d WITH ROLLUP;
f
binary
binary
DROP TABLE t;
#
# MDEV-14041 Server crashes in String::length on queries with functions and ROLLUP
#
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1),(2);
SELECT GET_LOCK( 'foo', 0 );
GET_LOCK( 'foo', 0 ) 1
SELECT HEX( RELEASE_LOCK( 'foo' ) ) AS f FROM t1 GROUP BY f WITH ROLLUP;
f
NULL 1
NULL
DROP TABLE t1;
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1),(2);
SELECT i FROM t1 GROUP BY i WITH ROLLUP
UNION ALL
SELECT ELT( FOUND_ROWS(), 1 ) f FROM t1 GROUP BY f WITH ROLLUP;
i 1 2
NULL
NULL
NULL
DROP TABLE t1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
SELECT a FROM t1 GROUP BY NULLIF( CONVERT('', DATE), '2015-10-15' ) WITH ROLLUP;
a 1 1
Warnings:
Warning 1292 Truncated incorrect datetime value: ''
Warning 1292 Incorrect datetime value: ''
Warning 1292 Truncated incorrect datetime value: ''
Warning 1292 Incorrect datetime value: ''
Warning 1292 Truncated incorrect datetime value: ''
Warning 1292 Incorrect datetime value: ''
Warning 1292 Truncated incorrect datetime value: ''
Warning 1292 Incorrect datetime value: ''
Warning 1292 Truncated incorrect datetime value: ''
Warning 1292 Incorrect datetime value: ''
DROP TABLE t1;
#
# End of 10.1 tests
#
#
# End of 10.2 tests
#
#
# MDEV-12886 Different default for INT and BIGINT column in a VIEW for a SELECT with ROLLUP
#
CREATE TABLE t1 (a int(11) NOT NULL);
INSERT INTO t1 VALUES (1),(2);
CREATE ORREPLACE VIEW v1 AS SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
DESCRIBE v1;
Field Type Null Key Default Extra
a int(11) YES NULL
LENGTH(a) int(10) YES NULL
COUNT(*) bigint(21) NO 0
DROP VIEW v1;
DROP TABLE t1;
CREATE TABLE t1 (a bigint(11) NOT NULL);
INSERT INTO t1 VALUES (1),(2);
CREATE ORREPLACE VIEW v1 AS SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
DESCRIBE v1;
Field Type Null Key Default Extra
a bigint(20) YES NULL
LENGTH(a) int(10) YES NULL
COUNT(*) bigint(21) NO 0
DROP VIEW v1;
DROP TABLE t1;
#
# MDEV-9410 VIEW over a ROLLUP query reports too large columns
#
CREATE TABLE t1 (a int(10) NOT NULL, b int(20) NOT NULL);
INSERT INTO t1 VALUES (1,1),(2,2);
CREATE VIEW v1 AS SELECT a,b FROM t1;
DESC v1;
Field Type Null Key Default Extra
a int(10) NO NULL
b int(20) NO NULL
DROP VIEW v1;
CREATE VIEW v1 AS SELECT a, b FROM t1 GROUP BY a,b;
DESC v1;
Field Type Null Key Default Extra
a int(10) NO NULL
b int(20) NO NULL
DROP VIEW v1;
CREATE VIEW v1 AS SELECT a, b FROM t1 GROUP BY a,b WITH ROLLUP;
DESC v1;
Field Type Null Key Default Extra
a int(11) YES NULL
b int(20) YES NULL
DROP VIEW v1;
DROP TABLE t1;
#
# MDEV-15576: Server crashed in Cached_item_str::cmp / sortcmp or
# Assertion `item->null_value' failed in
# Type_handler_temporal_result::make_sort_key upon SELECT with NULLIF
# and ROLLUP
#
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1),(2);
SELECT NULLIF( CAST( 'foo' AS DATE ), NULL & 'bar' ) AS f FROM t1 GROUP BY f WITH ROLLUP;
f
NULL
NULL
DROP TABLE t1;
# End of 10.3 tests
#
# MDEV-34984 rr_from_cache does not update generated columns
#
CREATE TABLE t1 (i INT DEFAULT 0, c VARCHAR(2048) GENERATED ALWAYS AS (i));
INSERT INTO t1 (i) SELECT seq FROM seq_1_to_6000;
SELECT MAX(c) FROM t1 GROUP BY c WITH ROLLUP limit 5; MAX(c) 1 10 100 1000 1001
DROP TABLE t1;
# End of 10.11 tests
ALTER DATABASE test CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci;
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.