[MCOL-1180] GROUP BY requires ORDER BY... Created: 2018-01-26  Updated: 2022-11-05  Resolved: 2022-11-05

Status: Closed
Project: MariaDB ColumnStore
Component/s: N/A
Affects Version/s: 1.1.2
Fix Version/s: Icebox

Type: Bug Priority: Minor
Reporter: MIke Thibodeau Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None
Environment:

Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-1049-aws x86_64)


Epic Link: ColumnStore Compatibility Improvements

 Description   

Running a query with GROUP BY does not sort by grouped by column. Adding ASC or DESC does not affect the order. Repeating the query may produces results in different sequence particularly if the date range is expanded. Easy work around by adding an ORDER BY so I marked this as minor.

-- version                  10.2.10-MariaDB-log         
-- version_comment          Columnstore 1.1.2-1         
 
CREATE TABLE `cs1` (
  `id` INT(10) UNSIGNED NOT NULL ,
  `timestamp_` DATETIME NOT NULL ,
  `numeric_val` DOUBLE DEFAULT NULL,
  `raw_val` DOUBLE DEFAULT NULL,
  `string_val` VARCHAR(3) DEFAULT NULL,
  `bitflags` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0 
) ENGINE=Columnstore DEFAULT CHARSET=latin1;
 
SELECT DAY(timestamp_) as `Day`,SUM(numeric_val) AS Total, AVG(numeric_val) AS Average 
    FROM cs1
    WHERE timestamp_ >= '2017-09-01 00:00:00' AND timestamp_ < '2017-09-08 00:00:00'
      AND id IN (228091,228231,228233,227867,228216,228241)
    GROUP BY DAY(timestamp_);
+------+--------------------+--------------------+
| Day  | Total              | Average            |
+------+--------------------+--------------------+
|    2 |  52866.02035699998 |  157.8090159910447 |
|    4 | 102331.42581999997 | 304.55781494047613 |
|    7 |  41462.75725900001 | 123.40106327083338 |
|    5 |  59282.80332899997 |  176.4369146696428 |
|    1 |  65330.15804799998 |  195.0153971582089 |
|    6 |  41260.32251999997 | 123.90487243243236 |
|    3 |  87296.08161299997 | 259.80976670535705 |
+------+--------------------+--------------------+
 



 Comments   
Comment by David Thompson (Inactive) [ 2018-01-27 ]

In general different databases have differing behavior around this, often times group by has an implied order but it doesn't have to. That said the defined mariadb behavior (https://mariadb.com/kb/en/library/group-by/) is that it should be ordered by the group by columns and support the optional asc / desc. group by is evaluated by by exemgr and so is a different implementation than mysqld so this is another case of compatibility issue.

Comment by Gregory Dorman (Inactive) [ 2020-01-10 ]

I recommend we close it. There is no such thing as default order by in SQL standard. And any database which deploys parallel execution of queries will sacrifice a good deal of performance in order to achieve a totally unnecessary result. Just reassign to Todd with the above recommendation.

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

Item is out of date. Closing due to inactivity. If you feel this was done in error please open a new ticket.

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