?
avatar aDaneInSpain
aDaneInSpain
27 Dec 2021

This is more to open a discussion, I guess. When reviewing performance issues with a site, I noticed that even loading the core language selector triggers a filesort in MariaDB which is not ideal. As there will only ever be a few languages on a site this will most likely never be a huge performance issue, but every little optimization we can do, we should do, right? In order to not have a filesort for the query:

SELECT *
  FROM #__languages
  WHERE published=1
  ORDER BY ordering ASC

We need to add a composite key for both published and ordering.

This does speed up loading very minutely and if done throughout the app so that at least there are keys for core functionality would have a real impact (although small) on performance.

Summary of Changes

Add KEY to table structure to prevent filesort

avatar aDaneInSpain aDaneInSpain - open - 27 Dec 2021
avatar brianteeman
brianteeman - comment - 27 Dec 2021

Does this change not also have to be made to the postgresql install AND the updates?

avatar PhilETaylor
PhilETaylor - comment - 27 Dec 2021

This will also need to be added to the upgrade SQL's but I guess @richard67 will be able to comment more on that.

docs: https://dev.mysql.com/doc/refman/8.0/en/order-by-optimization.html

avatar PhilETaylor
PhilETaylor - comment - 27 Dec 2021

and if this is needed on this table, maybe its needed on other tables too?

avatar richard67
richard67 - comment - 27 Dec 2021

It needs to do the same for PostgreSQL, and it needs to add an update script for each MySQL and PostgreSQL.

avatar PhilETaylor
PhilETaylor - comment - 27 Dec 2021

This also breaks the unit tests... because a comma is missing...

InstallCest installJoomla mysql fail

avatar alikon
alikon - comment - 27 Dec 2021

i don't think this is needed cause with the low cardinality of these table items, the db-engine will always perform a table scan, so PK index apart, no need for other indexes

avatar joomla-cms-bot joomla-cms-bot - change - 28 Dec 2021
Category SQL Installation
avatar aDaneInSpain
aDaneInSpain - comment - 28 Dec 2021

i don't think this is needed cause with the low cardinality of these table items, the db-engine will always perform a table scan, so PK index apart, no need for other indexes

This is the kind of input I was after. I am not a DB optimization expert. But we have found minute performance improvements by adding additional keys to several tables. Milliseconds, but still. From EXPLAIN SELECT I can see that it is using "file_sort" which is my understanding is always ideal to avoid?

avatar aDaneInSpain
aDaneInSpain - comment - 30 Dec 2021

From what I can read around the web the general guideline is that you should provide indexes for your select queries to improve performance. The only downside is that inserts, deletes and some updates can take slightly longer (as it needs to also update the index). But that should only be an issue if you have a table with frequent i/o operations which #__languages and #__extensions certainly aren't.

avatar PhilETaylor
PhilETaylor - comment - 30 Dec 2021

While you are correct... in theory.

the #__languages table will only ever be a handful of languages... so the fraction of a millisecond is hardly worth arguing about.

Now, if the same applies on the content tables, then it would be worth it, as those tables can get very very large.

avatar aDaneInSpain
aDaneInSpain - comment - 30 Dec 2021

I have not reviewed everything yet, but I know it applies to the #__extensions table, for instance. And if it does, minutely help on performance (and shows less "file sort" warnings) in the Joomla debug then I think it is worth fixing throughout. I just want to make sure there is no reason NOT to do it.

avatar aDaneInSpain
aDaneInSpain - comment - 4 Jan 2022

Would still love to hear if anyone has any reasons for not to do this. If there are no objections, I will modify the pull request to handle all instances in all core tables and implement installation and migration for both MySQL and PostgreSQL.

avatar aDaneInSpain
aDaneInSpain - comment - 11 Jan 2022

I am going to close this as I don't believe it has much impact on performance and the debugger in J4 does not show the "explain selects", so it does not jump out at you (which is a shame really) so it will not "scare" users as much.

avatar aDaneInSpain aDaneInSpain - change - 11 Jan 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-01-11 09:36:33
Closed_By aDaneInSpain
Labels Added: ?
avatar aDaneInSpain aDaneInSpain - close - 11 Jan 2022
avatar HLeithner
HLeithner - comment - 11 Jan 2022

the debugger in J4 does not show the "explain selects", so it does not jump out at you (which is a shame really)

@aDaneInSpain Actually you have to activate this functionality in the plugin, then you have also an explain to each query.

avatar aDaneInSpain
aDaneInSpain - comment - 12 Jan 2022

@aDaneInSpain Actually you have to activate this functionality in the plugin, then you have also an explain to each query.

Oh! Was not aware. Thanks.

Add a Comment

Login with GitHub to post a comment