SQL query has order by which slows down execution

Hi!

We are using Metabase v0.45.3 deployed on AWS ELB. Metabase is connected to AWS RDS MySQL v8.0 database.

We've noticed issues with the display of visualisations as there's a long SQL query execution. From logs we see that "SQLTimeoutException" happens after 60s.

SQL query is quite simple and table fields are properly indexed.
Here's the query:

SELECT `order`.`country` AS `country`, count(*) AS `count` 
FROM `order` 
WHERE (`order`.`date_order_created_at` >= date(date_add(now(6), INTERVAL -30 day)) AND `order`.`date_order_created_at` < date(now(6))) 
GROUP BY `order`.`country` 
ORDER BY `order`.`country` ASC

We've found out that if we remove the ORDER BY part, query execution is like 20x times quicker. Execution finishes in few seconds instead of a minute and more.
As the visualisation is of a Map type, there's no need for order anyway.

Temporary we have set higher nginx timeouts so the query execution doesn't get terminated.

Why is ORDER BY now automatically added to those type of queries?

Regards,
Miha P.

Please post a screenshot of the gui builder

Furthermore, if I add "Sort" (by Country or Count from query above) the "order by" ASC/DESC is added to the SQL, which is okey and works as expected. If "Sort" is removed from the query builder, "order by" first field is put back to SQL query (shown on "View the SQL" popup").

just added this issue ORDER BY getting added by default · Issue #28962 · metabase/metabase · GitHub