[MCOL-2166] Sub-query with GROUP BY and ORDER BY allows non-aggregates in projection. Created: 2019-02-12  Updated: 2020-03-13  Resolved: 2020-02-28

Status: Closed
Project: MariaDB ColumnStore
Component/s: ExeMgr
Affects Version/s: 1.1.6, 1.2.2
Fix Version/s: 1.4.4

Type: Bug Priority: Minor
Reporter: Roman Assignee: Roman
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MCOL-3843 Sub-query with GROUP BY and ORDER BY ... Closed
relates to MCOL-2121 Implement select_handler support Closed
Sprint: 2019-02, 2019-03, 2019-04, 2019-05, 2019-06, 2020-1, 2020-2, 2020-3

 Description   

Consider this query that must fail b/c i2 is in projection.

MariaDB [test]> select * from ( select count(1), i, i2 from cs1 group by i order by i2 ) a;
+----------+------+------+
| count(1) | i    | i2   |
+----------+------+------+
|        1 |    1 |   36 |
|        1 |  100 |    5 |
|        1 |   26 |    1 |
|        1 |   25 |  103 |
|        1 |    1 |   41 |
|        1 |    2 |   42 |
+----------+------+------+
6 rows in set (0.028 sec)

Despite the fact that MDB allows to sort over non-aggregated column CS doesn't support this functionality so here is the expected behavior.

MariaDB [test]> select * from ( select count(1), i, i2 from cs1 group by i order by i2 )a ;
ERROR 1815 (HY000): Internal error: IDB-2021: 'i2' is not in GROUP BY clause. All non-aggregate columns in the SELECT and ORDER BY clause must be included in the GROUP BY clause.



 Comments   
Comment by Roman [ 2019-02-13 ]

joblistfactory.cpp has checkGroupByCols() function. The first loop in it adds all non-aggregated columns from ORDER BY list into GROUP BY list trying to optimize ORDER BY out. And this is an error prone behavior.

Comment by Roman [ 2019-02-13 ]

After some consideration I moved the logic into FE(dbcon/mysql/ha_calpont_execplan.cpp) b/c it is better to stop errenous query processing as soon as possible.

Comment by Roman [ 2020-02-28 ]

The original issue is fixed. This issue had been left open as a remainder about non-aggregates in sorting and projection. I've made another feature issue and closed this one.

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