[MCOL-678] support "with rollup" Created: 2017-04-23  Updated: 2023-12-21

Status: In Testing
Project: MariaDB ColumnStore
Component/s: ExeMgr
Affects Version/s: 1.0.8
Fix Version/s: 23.10.1

Type: New Feature Priority: Major
Reporter: David Thompson (Inactive) Assignee: Sergey Zefirov
Resolution: Unresolved Votes: 0
Labels: rm_tpcds

Issue Links:
Blocks
Problem/Incident
causes MCOL-5583 The invariant check in RGData::getRow... Closed
Epic Link: ColumnStore Compatibility Improvements
Sprint: 2023-8, 2023-10, 2023-11, 2023-12
Assigned for Review: Roman Roman
Assigned for Testing: Kirill Perov Kirill Perov

 Description   

If you use 'with rollup' syntax then the following error is returned by default:

MariaDB [flights]> select carrier, count(*) from flights group by carrier with rollup;
ERROR 1178 (42000): The storage engine for the table doesn't support IDB-1014: Rollup is currently not supported.

This can be worked around by specifying non distributed query operating mode as documented here: https://mariadb.com/kb/en/mariadb/columnstore-operating-mode/

 set infinidb_vtable_mode=0;

Testing the changes

The behavior of WITH ROLLUP is the same with regard to types of rolled up GROUP BY columns. E.g., if we GROUP BY on TEXT and TEXT columns, the behavior ith regards to adding rows with NULLs should be the same as with INTEGER and INTEGER columns.

The aggregates we definitely must support; MIN, MAX, SUM, AVG, COUNT (both forms).

The aggregates we do not support right now: GROUP_CONCAT and JSONARRAYAGG.

Any other may or may not work.



 Comments   
Comment by David Thompson (Inactive) [ 2017-05-22 ]

MariaDB Syntax is covered here: https://mariadb.com/kb/en/mariadb/select-with-rollup/ and should be considered the reference point for behavior / syntax.

Comment by Todd Stoffel (Inactive) [ 2022-11-05 ]

This item is being closed because it was well passed the expiration date with no activity. If you suspect this was done in error please create a new ticket.

Comment by Gagan Goel (Inactive) [ 2022-12-16 ]

I have reopened this ticket as this affects TPC-DS query67.

Comment by Roman [ 2023-09-26 ]

sergey.zefirov Could you add your suggestions for QA on how to test this feature.

Comment by Kirill Perov [ 2023-10-27 ]

sergey.zefirov Found problems with union all for MCS+MDB tables:

DROP DATABASE IF EXISTS mcs84_db;
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);

CREATE TABLE booksales3 (country3 CHAR(35), genre3 CHAR(15), year3 INT, sales3 INT);

INSERT INTO booksales3 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 country, year, genre, SUM(sales) FROM booksales GROUP BY country, year, genre WITH ROLLUP UNION all SELECT country3, year3, genre3, SUM(sales3) FROM booksales3 GROUP BY country3,year3,genre3 WITH ROLLUP;

returns:

country year genre SUM(sales)
NULL NULL NULL 354462
Paraguay 2014 NULL 96730
Paraguay 2014 fiction 87970
Paraguay 2014 fiction 87970
Paraguay 2014 non-fiction 8760
Paraguay 2014 non-fiction 8760
Paraguay 2015 NULL 85970
Paraguay 2015 fiction 76940
Paraguay 2015 fiction 76940
Paraguay 2015 non-fiction 9030
Paraguay 2015 non-fiction 9030
Paraguay NULL NULL 182700
Senegal 2014 NULL 77214
Senegal 2014 fiction 12234
Senegal 2014 fiction 12234
Senegal 2014 non-fiction 64980
Senegal 2014 non-fiction 64980
Senegal 2015 NULL 94548
Senegal 2015 fiction 15647
Senegal 2015 fiction 15647
Senegal 2015 non-fiction 78901
Senegal 2015 non-fiction 78901
Senegal NULL NULL 171762

'normal' rows doubled by union all
but rollup rows not

if both tables are MDB or both MCS - rollup rows are doubled

Comment by Kirill Perov [ 2023-10-27 ]

sergey.zefirov second problem with union of 2 MCS tables:

DROP DATABASE IF EXISTS mcs84_db;
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);

CREATE TABLE booksales2 (country2 CHAR(35), genre2 CHAR(15), year2 INT, sales2 INT) ENGINE=Columnstore;

INSERT INTO booksales2 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 country,year,genre,sum(sales),avg(sales) from (SELECT country, year, genre, sales FROM booksales UNION all SELECT country2, year2, genre2, sales2 FROM booksales2) t1 GROUP BY country,year,genre WITH ROLLUP;

returns:

---------------------------------------------

country year genre sum(sales) avg(sales)

---------------------------------------------

Paraguay 2015 fiction 153880 76940.0000
Paraguay 2014 fiction 175940 87970.0000
Paraguay 2015 non-fiction 18060 9030.0000
Senegal 2015 non-fiction 157802 78901.0000
Paraguay 2014 non-fiction 17520 8760.0000
Senegal 2014 non-fiction 129960 64980.0000
Senegal 2014 fiction 24468 12234.0000
Senegal 2015 fiction 31294 15647.0000

---------------------------------------------
8 rows in set (0.094 sec)

no rollup rows!!! (also no for MCS+MDB tables or MDB+MCS)

(if both tables are MDB - rollup rows exist):

MariaDB [mcs84_db]> select country3,year3,genre3,sum(sales3),avg(sales3) from (SELECT country3, year3, genre3, sales3 FROM booksales3 UNION all SELECT country4, year4, genre4, sales4 FROM booksales4) t1 GROUP BY country3,year3,genre3 WITH ROLLUP;
------------------------------------------------

country3 year3 genre3 sum(sales3) avg(sales3)

------------------------------------------------

Paraguay 2014 fiction 175940 87970.0000
Paraguay 2014 non-fiction 17520 8760.0000
Paraguay 2014 NULL 193460 48365.0000
Paraguay 2015 fiction 153880 76940.0000
Paraguay 2015 non-fiction 18060 9030.0000
Paraguay 2015 NULL 171940 42985.0000
Paraguay NULL NULL 365400 45675.0000
Senegal 2014 fiction 24468 12234.0000
Senegal 2014 non-fiction 129960 64980.0000
Senegal 2014 NULL 154428 38607.0000
Senegal 2015 fiction 31294 15647.0000
Senegal 2015 non-fiction 157802 78901.0000
Senegal 2015 NULL 189096 47274.0000
Senegal NULL NULL 343524 42940.5000
NULL NULL NULL 708924 44307.7500

------------------------------------------------

Comment by Kirill Perov [ 2023-10-27 ]

At drone CI under docker first query using two engine tables raise error:

select country, year3, sum(sales3) from booksales b1 join booksales3 b3 on b1.sales=b3.sales3 group by country,year3 WITH ROLLUP;

mysqltest: At line 74: query 'select country, year3, sum(sales3) from booksales b1 join booksales3 b3 on b1.sales=b3.sales3 group by country,year3 WITH ROLLUP' failed: ER_INTERNAL_ERROR (1815): Internal error: CrossEngineStep::execute() fatal error running mysql_real_connect() in libmysql_client lib (1045) (Access denied for user 'cejuser'@'localhost' (using password: YES))

Comment by Roman [ 2023-11-02 ]

kirill.perov@mariadb.com The last issue description looks like there was no CrossEngineJoin user with the specific password in MDB or there was no `select flush privileges;` has been called after the user had been added.

Comment by Kirill Perov [ 2023-11-02 ]

sergey.zefirov, drrtuy Yes, error in drone was resolved by adding CrossEngineJoin user.

Comment by Roman [ 2023-11-28 ]

The issue with WITH ROLLUP on subselect found by kirill.perov@mariadb.com has been fixed.

Comment by Kirill Perov [ 2023-12-02 ]

query with 2 MCS tables is working well
but I can not reach working query between MCS and MDB tables

Generated at Thu Feb 08 02:22:59 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.