[MDEV-29546] spider group by handler wrong result on order by aggregate Created: 2022-09-15  Updated: 2023-11-28

Status: Open
Project: MariaDB Server
Component/s: Storage Engine - Spider
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Major
Reporter: Sergei Golubchik Assignee: Yuchen Pei
Resolution: Unresolved Votes: 0
Labels: spider-gbh

Issue Links:
Relates
relates to MDEV-29480 spider group by handler wrong result ... Closed

 Description   

if I change mdev_29008.test to use ORDER BY without aliases to an aggregate function, like

SELECT MIN(t2.a) AS f1, t1.b AS f2 FROM tbl_a AS t1 JOIN tbl_a AS t2 GROUP BY f2 ORDER BY MIN(t2.a), MAX(t2.a), f2;

Then I can see that the spider will generate the query

select max(t1.`a`) ``,min(t1.`a`) ``,min(t1.`a`) `f1`,t0.`b` `b` from `auto_test_remote`.`tbl_a` t0,`auto_test_remote`.`tbl_a` t1 group by t0.`b` order by ``,``,t0.`b`

which is clearly wrong, it doesn't distinguish between min and max. It needs to auto-generate names for aggregates as needed.

Also might apply to HAVING


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