Sql optimise new index merged branch#4115
Sql optimise new index merged branch#4115nadeeshaan wants to merge 19 commits intojoomla:stagingfrom
Conversation
|
Related Tracker - Tracker! |
|
Test results: viewlevels Before patch: 0.97 ms
|
|
Please regroup in one file the db alterations to ease testing and as anyway it would be necessary: |
|
@810 Test is not necessarily failed: If your test is with default small dataset, query time can increase a bit with indexes with small sets, but with big sets dramatically decrease. @nadeeshaan Great work! It is easy to review the great work that you did from a database optimization perspective, as it is well presented here. So i'll give my database optimization perspective comments one by one:
agree.
agree
shouldn't that be ?: and the related query be changed to: ?
agree.
agree
agree
agree. (my above comments are from a MySQL/MariaDB perspective only, which is anyway 99+% of Joomla's audience). |
|
Thank you very much for helping to verify the indexing @beat. I will On Sat, Aug 16, 2014 at 2:08 AM, beat notifications@github.com wrote:
Nadeeshaan Gunasinghe |
|
@test I'm finding it much harder to test this one as it isnt clear exactly where each of the indexes should be tested |
|
@brianteeman In the above testing Instructions comment I have made include the details about the index and the related query as well as where to find the query. If you have any issue of figuring out an index to be test please mention and I will definitely update the instruction |
|
@brianteeman you can use the explain on "the query" before apply the patch and after applying the patch you should notice the use of the new index |
libraries/cms/html/access.php
Outdated
There was a problem hiding this comment.
Please change it to ->where('a.title != "" ') instead of above.
and if you can make it like this, it will be awesome.
->where($db->qn('a.title') . ' != "" ')Thanks.
There was a problem hiding this comment.
Why does this need to be changed from <> to != ?
iirc, in SQL the prefered notation for inequality is <>.
There was a problem hiding this comment.
As far as I understand for String to String comparison it is better to use !=
|
@infograf768 added update file for ALTER Queries. |
|
the query before the query after |
|
I'm really not a fan of this changing of a * to the entire set of fields from the table. How much of an effect does this have on performance vs just the key changes? I'm just worried that readability is severely affected. Plus if any db changes ever happen to these tables it means more places where these things need changes and where bugs can be introduced |
|
@wilsonge Good points! 👍 You're right: indexes have MUCH bigger performance gains than rewriting * to fields lists. And specially if it's full fields-list, I doubt about any performance gains, and if there are any, that could be automated in code and not made manually for maintainability in case of added fields. In MySQL, sometimes/often * is slightly faster than the full list. E.g. COUNT(*) can be faster than e.g. COUNT(id). In Postgress, it could be different in older versions. |
|
sorry is my mental sql syntax check 1.0 alpha the right thing to do is to select the only "app" needed fields i think is more easy to understand what that query "ask" |
installation/sql/mysql/joomla.sql
Outdated
There was a problem hiding this comment.
Looks like there might be a change from spaces to a tab here.
|
Can you add the indexes for postresql and mssql too? |
|
Github say that Can you have a look into it? |
1e219eb to
7e0ed08
Compare
|
This PR is conflict is now solved and ready to review. Thanks everyone for review and tests. |
|
the Query FROM INNER JOIN INNER JOIN INNER JOIN WHERE GROUP BY ORDER BY SELECT folder AS type, element AS name, params This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4115. |
|
I have tested this item 🔴 unsuccessfully on 7e0ed08 This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4115. |
|
@euismod2336 That's not necessarily an unsuccessful test! Specially if master has no better result... Many other improvements, worthwhile ones were made here. :-) sure an adequate index seems to exist: |
|
No but this PR does conflict because it predates all the utf8mb4 index changes - there's no point in testing this unless the branch is updated again |
|
For when @brianteeman hits this in a few weeks at the sprint tho - this is one that needs redoing - not just closing. It's going to give big improvements for "free" |
|
@beat i agree that the improvements are considerable, but not all issues were "fixed" (as far as i could see), i'll have another go at it with more records if it might change it. all the other queries showed direct results. @wilsonge not sure about the utf8mb4 changes, but this was PR was tested on the staging branch. This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4115. |
|
I have tested this item ✅ successfully on 7e0ed08 Thank you @beat for pointing this out. This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4115. |
|
Set to "closed" on behalf of @zero-24 by The JTracker Application at issues.joomla.org/joomla-cms/4115 |
|
Closing as we have a new updated PR at #10284 by @alikon This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/4115. |






Testing Instructions:
This PR consists all the PRs merged in to this one regarding the index additions. Two approaches can be followed in order to test this PR. One is in an already installed site and one is for fresh distributions.
For already installed sites
For already installed sites first apply the PR and then add follow the bellow commands in order to add the indexes manually to the database
ALTER TABLE #__languages ADD INDEX 'idx_published_ordering' ('published','ordering');(#11)Related Query Before changes
Related Query Before changes
ALTER TABLE #__session DROP PRIMARY KEY, ADD PRIMARY KEY(session_id(32))( #8 )ALTER TABLE #__session DROP INDEX time, ADD INDEX time(time(10))Index Description
This Index added in order to speed up the session update query allowing the sub string index usages
ALTER TABLE #__template_styles ADD INDEX idx_client_id('client_id')( #13 )Index Description
Without applying this index the below query cannot use any index to retrieve the rows from the database. After applying this index it clearly shows in the explanation section that the query uses the index to retrieve the rows
Related Query
ALTER TABLE #__contentitem_tag_map ADD INDEX idx_alias_item_id ('type_alias','content_item_id')( #14 )Index Description
Without applying this index the below query cannot use any index to retrieve the rows from the database. After applying this index it clearly shows in the explanation section that the query uses the index to retrieve the rows. Also one another change did relevant to this index changes. Which is removing the
t.*from the relevant query and adding the table fields instead. This change can be found (#14) and please refer to that PR also.Related Query Before changes
Related Query After changes
ALTER TABLE #__extensions ADD INDEX 'idx_type_ordering' ('type','ordering')( #16 )Index Description
Without applying this index the below query uses
filesortto retrieve the rows from the database, which is an expensive retrieval operation. After applying this index it clearly shows in the explanation section that the query uses the index to retrieve the rows except thefilesort.Related Query
ALTER TABLE #__menu ADD INDEX 'idx_client_id_published_lft' ('client_id','published','lft')( #17 )Index Description
Without applying this index the below query uses
filesortto retrieve the rows from the database, which is an expensive retrieval operation. After applying this index it clearly shows in the explanation section that the query uses the index to retrieve the rows except thefilesort.Related Query
(query Executes when clicking on the add new category in the admin console)
ALTER TABLE #__viewlevels ADD INDEXidx_ordering_title(ordering,title)( #21 )Index Description
Without applying this index the below query uses
filesortto retrieve the rows from the database, which is an expensive retrieval operation. After applying this index it clearly shows in the explanation section that the query uses the index to retrieve the rows except thefilesort. Also changed theJROOT/libraries/cms/html/access.phpfile's query which is shown below by removing theGROUP BYclause since thePRIMARY KEYincludes in the selected fields. And this reduce the execution timeRelated Query Before Change
Related Query After Change