Skip to content

Conversation

@richard67
Copy link
Contributor

Pull Request for joomla/joomla-cms#45236 and joomla/joomla-cms#44545

Summary of Changes

This pull request (PR) changes the fix from PR #300 to use the ROW_NUMBER() window function instead of the unreliable SQL variable incrementation so that it is applied on MariaDB >= 10.2.0 and MySQL >= 8.0.0 and now only on MariaDB 11.0.0 and newer.

When I had made my PR #300 I was advised to play safe and do it only for MariaDB 11 because the issue was only reported for that version.

But meanwhile the same issue has also been reported for MariaDB versions 10.4.32 and 10.11.11, see e.g, joomla/joomla-cms#45236 .

For MySQL the issues has not been reported, so it seems the ugly old "hack" with incrementing an SQL variable still works, but who knows if this will be the case forever.

The ROW_NUMBER() window function meanwhile has become an SQL standard and is supported by all kinds of databases supported by the database framework here, only not for the old MySQL and MariaDB versions. It is more reliable than any SQL variable, and it might also be better regarding performance.

Therefore I think ROW_NUMBER() window function should be used whenever supported, and this is what this PR here does.

Testing Instructions

On a Joomla 5.2 or 5.3 with a MariaDB database version 10.2.0 or newer, but is must be a 10.x, not an 11.x, reproduce joomla/joomla-cms#45236 .

Then apply the changes from this PR to file libraries/vendor/joomla/database/src/Query/MysqlQueryBuilder.php on the CMS.

Then try again with the same starting conditions, i.e. the ordering not being messed up by the previous test, e.g. by making a new installation again before this test.

Result: Issue should be fixed by this PR also for MariaDB 10.x >= 10.2.0.

If you also have a MySQL 8.x database available:

Try to reproduce joomla/joomla-cms#45236 .

Result: Issue does not happen.

Apply the changes from this PR as described before.

Try again to reproduce joomla/joomla-cms#45236 .

Result: Issue still does not happen, ordering works as well as before.

Documentation Changes Required

None.

Use ROW_NUMBER() window function on MariaDB >= 10.2.0 and MySQL >= 8.0.0
@Hackwar Hackwar merged commit cedd0fd into joomla-framework:3.x-dev Mar 30, 2025
2 checks passed
@richard67 richard67 deleted the 3.x-dev-select-row-number-2 branch March 30, 2025 14:46
@chmst
Copy link

chmst commented Mar 31, 2025

Tested this local with
Database Version 10.4.32-MariaDB there it works fine - ordering remains

but with Database Version 10.11.11-MariaDB-0+deb12u1
it makes no difference, the ordering changes as before patch

@richard67
Copy link
Contributor Author

Tested this local with Database Version 10.4.32-MariaDB there it works fine - ordering remains

but with Database Version 10.11.11-MariaDB-0+deb12u1 it makes no difference, the ordering changes as before patch

That's weird as the change in this PR concerns both of these versions. So either there is another issue with MariaDB 10.11, or I don't know.

@chmst
Copy link

chmst commented Mar 31, 2025

Indeed. Php version local: 8.2, online 8.3 if this makes a difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants