Reorder tables with single SQL query (all DBs compatible), greatly improving reorder performance#11184
Reorder tables with single SQL query (all DBs compatible), greatly improving reorder performance#11184ggppdk wants to merge 7 commits intojoomla:stagingfrom
Conversation
libraries/joomla/table/table.php
Outdated
| $this->_db->setQuery($query); | ||
| $rows = $this->_db->loadObjectList(); | ||
| // Reorder configuration | ||
| $uses_single_key = count($this->_tbl_keys == 1); |
There was a problem hiding this comment.
Shouldn't this be:
$uses_single_key = count($this->_tbl_keys) == 1;
|
If joomla users want to stay with old ordering then Your patch will do the same but it is more complicated. |
|
What is complicated about it ? it is actually very simple collect all updates in 1 query also a transaction with multiple queries should always be slower or a lot slower, |
|
SORRY AGAIN! This test is NOT RELEVANT! Forgot to select "successful". I have tested this item 🔴 unsuccessfully on c43254e |
|
I have tested this item ✅ successfully on c43254e (But the more I think about this whole reordering issue I don't understand why we have to reorder the table while saving a new article. Ordering is an This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11184. |
|
Anyone testing
FIX for visible selectors was merged in latest staging (for J3.6.3+) here: #11572 |
I didn't and had no issues. Fields don't update without page reload. That's all Off Topic: |
|
Please take a look at Review of solutions #11139 (comment) |
|
I'm back to there because this is more related. BEGIN
-- loop on each 10000 queries:
-- UPDATE max 10000 rows
COMMIT |
|
this PR fixes performance issue and makes race issue very rare but transactions are not be directly related to this PR Joomla database API needs to add them first ?
right ? |
|
So it is safe to use regardless of enironment ? i will make use of it, [EDIT] |
|
I have tested You can see some example on fof library: |
|
I have managed to pull it locally and rebase it, (originally i made it from the GitHub GUI)
case/when/then/else/end expression, was added by SQL-92, so it should be supported by all DBs ? |
|
added to my to-do list 👍 p.s. |
|
@alikon Also updated the description of the first posting, to be up to date, shorter and clearer. |
|
I'd suggest checking your limits with the SQL Server docs. For an INSERT query, it only allows 1000 values at a time (see https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_finder/helpers/indexer/driver/sqlsrv.php#L543 for Smart Search where it hit this issue). |
|
That code tries to do the same thing for the case of inserts
To be honest in this case i don't know of what limitation applies to the size of queries of SQL server but, in our case the updates are really small strings
Let's say that the code below is 30 characters you will get in the code of this, i use 10,000 updates per query i do not know if SQL server has smaller limits we can probably change it to 1,000 with small or little performance drop If the values were mostly variable length, |
|
i will check the docs, but we also need a website, with some category with 30,000 articles for testing this properly |
|
I can give you that or you can make your own using com_overload
|
|
Thanks brian, i have for MySql, i have made a patch for com_overload to make it run faster, and had created a website with 500,000 articles but i have not setup any Joomla web-sites in other DBs |
|
I mainly just want to make sure UPDATE queries in SQL Server don't have the On Saturday, August 13, 2016, Georgios Papadakis notifications@github.com
|
|
I hope this PR is proven good to be accepted for the other DBs too, |
plus for the 10,000 x 10 characters [ IN (nnnnnnnn1, nnnnnnnn2, ......., nnnnnnnn) less than < 100 KBytes so still under default max_packet_size 1MB ( should be the same on postgres ) call to @waader for a test on mssql |
|
Reordering works with testing data installed but because of this #11932 i was not able to create new articles. So I could not follow the test instructions. |
|
Also during the time i was making this PR i tested by using limit of 5 or 50 values to confirm that breaking the update Query into more than 1 update queries works: https://github.com/joomla/joomla-cms/pull/11184/files#diff-8254e2c441a41d3fa26f0f83fbbb3043R1374 so you may want to test by adding a 5 or 50 limit to the above (depending on how many articles / records your category has) thus the update queries, for updating 500 records will be 10 UPDATE queries
|
|
The change of using last order number in new record creation was reverted This PR does not have a milestone |
|
After upodating my joomla to 3.6.3 (from 3.6.2) I had problems with "504 gateaway" error when saving new articles. Found this PR, did everything like its written and now its working fine. |
|
Since PR: #11581 Revert "Performance gain - new featured article" This PR was supposed to also be considered for accepting and merging, to address the performance issue, so J3.6.3 has the known JTable::reorder() performance issue (and in big sites timeouts can occur too) [EDIT] |
|
Reading through this conversation and patch again, I'm still not 100% comfortable with this. It still seems as though it has been coded against default MySQL configurations. I've seen a couple tests for PostgreSQL, where frankly I'm not as concerned about it working since it usually behaves closer to MySQL anyway. I haven't seen anything in here at all for SQL Server (and yes it's still supported right now so that needs to be validated). Two things I think need to happen:
I'm really not trying to be difficult, even if others think my arguments are BS. But we are making changes at the base level of the database integration layer and the changes need to be properly validated and flexible enough to deal with lower end configurations. So far, I think we're OK for default MySQL and PostgreSQL configurations. |
|
There is a very old article that describe similar solution to this PR at http://www.databasejournal.com/features/mssql/article.php/1460001/Complex-Updates-Using-the-Case-Statement.htm |
The query start breaking into multiple queries at 10,000 records, which is about 350KBytes Max query string size for MySQL, default is: 1MByte Max query string size for postgresql: 1 Gbyte So, this is well below the default limits, but even if we change the limit to e.g. 5,000 or to 3,000 records per query the performance difference will be small / very small
|
|
The other idea could be use |
|
You mean this PR (scroll to the bottom to see the query) |
|
I don't know what can be done, but all I know is this is coded against MySQL's defaults, and based on your comment I guess PostgreSQL has a bigger default. Are we sure SQL Server has a similar configuration? If so then it should be fine, but if not then this needs to be addressed. Also, as I pointed out above, SQL Server has a stricter configuration with the number of records/values that can be set with queries. Maybe this isn't an issue with UPDATE queries as being issued here, but when I wrote the SQL Server adapter for Smart Search it was a very real issue with INSERT queries and the 10,000 records limit you have here exceeds the 1,000 record limitation I had to work around. So even if the configurations are OK for the query size (in terms of bytes), we may still have an issue with this aspect of it. Unless I scrolled past something, that was another thing I don't remember seeing an answer for. Again, so far it seems like we're doing fine for MySQL and PostgreSQL for the most part. But there's still one environment with no testing that we claim to support. At least we're dropping it at 4.0 but we should still make sure it's working as long as 3.x is supported. |
|
hhmm,
Also even a very low limit of 500 records will have about 90%-95% of the performance benefit that 10,000 records limit per query gives so we can just use 1,000 as limit of records and thus be sure of SQL server too |
|
I ll find time to test |
|
With the other PRs that have been merged addressing reordering performance, is this still valid? |
|
This PR is no longer needed |
Performance fix for JTable::reorder(),
greatly improves performance / race condition issues on drag and drop reordering and break-up: Drag and drop sorting messes up on large menu #4303It should work in all Database servers, since it uses case/when/then/else/end expression, (SQL-92)
Summary of Changes
Testing Instructions
1 - Applying PR to latest staging
2 - It helps to make the per row ORDER inputs visible, to do it add CSS to your backend template file: /templates/isis/css/template.css
You may want to add just before JTable::reorder() final return;
https://github.com/joomla/joomla-cms/pull/11184/files#diff-8254e2c441a41d3fa26f0f83fbbb3043R1431