1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-05-02 19:24:47 +03:00
Sergey Zefirov 8632c85ecf
feat(primproc,aggregegation)!: Changes for ROLLUP with single-phase aggregation (#3025)
The fix is simple: enable subtotals in single-phase aggregation and
disable parallel processing when there are subtotals and aggregation is
single-phase.
2023-11-28 17:33:02 +03:00

73 lines
2.3 KiB
Plaintext
Executable File

#
# SELECT ... WITH ROLLUP #
# https://mariadb.com/kb/en/select-with-rollup/ #
#
# Author: Susil, susil.behera@mariadb.com #
#
-- source ../include/have_columnstore.inc
--disable_warnings
DROP DATABASE IF EXISTS mcs84_db;
--enable_warnings
CREATE DATABASE mcs84_db;
USE mcs84_db;
CREATE TABLE booksales (
country CHAR(35), genre CHAR(15), year INT, sales INT)
ENGINE=Columnstore;
INSERT INTO booksales VALUES
('Senegal','fiction',2014,12234), ('Senegal','fiction',2015,15647),
('Senegal','non-fiction',2014,64980), ('Senegal','non-fiction',2015,78901),
('Paraguay','fiction',2014,87970), ('Paraguay','fiction',2015,76940),
('Paraguay','non-fiction',2014,8760), ('Paraguay','non-fiction',2015,9030);
SELECT year, SUM(sales) FROM booksales GROUP BY year ORDER BY year;
# Negative. WITH ROLLUP cannot be used with ORDER BY.
--error 1221
SELECT year, SUM(sales) FROM booksales GROUP BY year WITH ROLLUP ORDER BY year;
--sorted_result
SELECT year, sales, MAX(country) FROM booksales GROUP BY year, sales;
--sorted_result
SELECT year, MAX(country) FROM booksales GROUP BY year;
--sorted_result
SELECT year, sales, MAX(country) FROM booksales GROUP BY year, sales WITH ROLLUP;
--sorted_result
SELECT year, SUM(sales) FROM booksales GROUP BY year WITH ROLLUP;
--sorted_result
SELECT country, genre, SUM(sales) FROM booksales GROUP BY country, genre WITH ROLLUP;
--sorted_result
SELECT country, genre, SUM(sales) FROM (SELECT country, genre, sales FROM booksales) t1 GROUP BY country, genre WITH ROLLUP;
CREATE TABLE three_cols ( key1 INTEGER, key2 INTEGER, value DECIMAL(38)) ENGINE=COLUMNSTORE;
INSERT INTO three_cols(key1, key2, value) VALUES
(NULL, NULL, NULL)
, (NULL, NULL, 1)
, (NULL, 1, 2)
, ( 1, 1, 3)
, ( 1, 2, 4)
, ( 1, 2, 5)
, ( 2, 3, 6)
, ( 2, 3, 7);
--sorted_result
SELECT key1, key2, SUM(value), AVG(value), MIN(value), MAX(value), COUNT(value), COUNT(*) FROM three_cols GROUP BY key1, key2 WITH ROLLUP;
--error 1815
SELECT key1, key2, GROUP_CONCAT(value) FROM three_cols GROUP BY key1, key2 WITH ROLLUP;
--error 1815
SELECT key1, key2, JSON_ARRAYAGG(value) FROM three_cols GROUP BY key1, key2 WITH ROLLUP;
--error 1815
SELECT 100, SUM(value) FROM three_cols GROUP BY 1 WITH ROLLUP;
# Clean up
DROP DATABASE IF EXISTS mcs84_db;