database icon indicating copy to clipboard operation
database copied to clipboard

With Mariadb 11.1.2 ordering of table is broken

Open tkuschel opened this issue 2 years ago • 4 comments

Copy from https://issues.joomla.org/tracker/joomla-cms/42333 https://github.com/joomla/joomla-cms/issues/42333

FURTHER BUG REPORT

I took a closer look at the function reorder and found out that the query is created with a windows function which is defined in /libraries/vendor/joomla/database/src/DatabaseQuery.php with the following line in

public function selectRowNumber($orderBy, $orderColumnAlias)

return $this->select("ROW_NUMBER() OVER (ORDER BY $orderBy) AS $orderColumnAlias");

but with MysqlQueryBuilder.php it is overwritten to

return $this->select("(SELECT @rownum := @rownum + 1 FROM (SELECT @rownum := 0) AS r) AS $orderColumnAlias");

This no longer works, so the first variant does it quite correctly. Since the MysqlQueryBuilder.php is just a "traited" class of the former class DatabaseQuery in DatabaseQuery.php, we can simply remove this function in the MysqlQueryBuilder.php: (here it is commented out)


/*
  public function selectRowNumber($orderBy, $orderColumnAlias)
  {
     $this->validateRowNumber($orderBy, $orderColumnAlias);

     return $this->select("(SELECT @rownum := @rownum + 1 FROM (SELECT @rownum := 0) AS r) AS $orderColumnAlias");
  }
*/

It works for:

  • MariaDB Version 11.1.2, MariaDB Version 10.11.4,
  • Both connections via MySQLi and PDO
  • Joomla 5.0.0 and 4.4.0 with removed function selectRowNumber in MysqlQueryBuilder.php

Good to know: The used SQL function ROW_NUMBER(), is introduced in MYSQL since version 8.0 (2016/09) So the requirements for Joomla 5 with MySQL 8.1 minimum 8.0.13, and MariaDB 11.1.0 minimum 10.4.0 should work.

tkuschel avatar Nov 12 '23 17:11 tkuschel

please test #291

alikon avatar Nov 12 '23 20:11 alikon

please test #291

who?

tkuschel avatar Nov 29 '23 13:11 tkuschel

to all whom would like this bug fixed with some spare time & MariaDB 😄

alikon avatar Nov 29 '23 17:11 alikon

See also my alternative PR #300 which still supports older databases, as the minimum database requirements of the database framework have not been changed in the recent years so they are still the same on all 3 branches.

richard67 avatar Mar 16 '24 13:03 richard67

See also PR #308 for another alternative way to do it.

richard67 avatar Aug 03 '24 12:08 richard67

fixed with #300

rdeutz avatar Aug 15 '24 09:08 rdeutz