? ? Success

User tests: Successful: Unsuccessful:

avatar nadeeshaan
nadeeshaan
13 Aug 2014

Testing Instructions:

In order to test this PR first apply the PR via the joomla Patch Test. Then log in to the admin panel and click on the add new article. After clicking on the add new article, the query executes.
Add New Article

Original Query before the Optimization

     SELECT a.id AS value, a.title AS text, a.level, a.published 
     FROM #_categories AS a 
     LEFT JOIN #_categories AS b 
     ON a.lft > b.lft 
     AND a.rgt < b.rgt 
     WHERE (a.extension = 'com_content') 
     AND a.published IN (0,1) 
     GROUP BY a.id, a.title, a.level, a.lft, a.rgt, a.extension, a.parent_id, a.published 
     ORDER BY a.lft ASC

After the Optimization

     SELECT DISTINCT c.id AS value, c.title AS text, c.level, c.published
      FROM (
                  SELECT DISTINCT id,title,level,published,parent_id,extension,lft,rgt 
                   FROM #_categories
                   WHERE  (extension = 'com_content') AND published IN (0,1)
                   ORDER BY lft ASC
                   ) AS c
      LEFT JOIN #_categories AS b
      ON x.lft > b.lft
      AND x.rgt < b.rgt

Query Change Description

In the new query the change is the new sub select. In the previous query the tables are being joined and in the new query as you can see in the red color query is the sub select. In the sub select it filters the rows according to the WHERE clause of the previous query. As you can see this filters the rows and reduce the number of rows before the join and which results a fever number of rows to choose the attributes.Also Removed the group by clause and added the SELECT DISTINCT instead

http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=34066

avatar nadeeshaan nadeeshaan - open - 13 Aug 2014
avatar jissues-bot jissues-bot - change - 13 Aug 2014
Status Pending New
Labels Added: ? ?
avatar zero-24
zero-24 - comment - 13 Aug 2014

@test @nadeeshaan i can confirm the query change. ok here. Is there any special thing that can/need be tested? It still retrun the same count of rows on my end.

avatar infograf768
infograf768 - comment - 13 Aug 2014

Before patch:
screen shot 2014-08-13 at 17 45 36_before

After patch
screen shot 2014-08-13 at 17 43 23_after

Query time is drastically reduced

avatar infograf768 infograf768 - change - 13 Aug 2014
The description was changed
Description <h2>Testing Instructions:</h2> <p>In order to test this PR first apply the PR via the joomla Patch Test. Then log in to the admin panel and click on the add new article. After clicking on the add new article, the query executes.<br><a href="https://cloud.githubusercontent.com/assets/1329674/3895200/d14f9d8e-224b-11e4-9a13-d83208ea42d5.PNG" target="_blank"><img src="https://cloud.githubusercontent.com/assets/1329674/3895200/d14f9d8e-224b-11e4-9a13-d83208ea42d5.PNG" alt="Add New Article" style="max-width:100%;"></a></p> <h3>Original Query before the Optimization</h3> <div class="highlight highlight-sql"><pre> <span class="k">SELECT</span> <span class="n">a</span><span class="p">.</span><span class="n">id</span> <span class="k">AS</span> <span class="n">value</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">title</span> <span class="k">AS</span> <span class="nb">text</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="k">level</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">published</span> <span class="k">FROM</span> <span class="o">#</span><span class="n">_categories</span> <span class="k">AS</span> <span class="n">a</span> <span class="k">LEFT</span> <span class="k">JOIN</span> <span class="o">#</span><span class="n">_categories</span> <span class="k">AS</span> <span class="n">b</span> <span class="k">ON</span> <span class="n">a</span><span class="p">.</span><span class="n">lft</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">lft</span> <span class="k">AND</span> <span class="n">a</span><span class="p">.</span><span class="n">rgt</span> <span class="o">&lt;</span> <span class="n">b</span><span class="p">.</span><span class="n">rgt</span> <span class="k">WHERE</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">extension</span> <span class="o">=</span> <span class="s1">'com_content'</span><span class="p">)</span> <span class="k">AND</span> <span class="n">a</span><span class="p">.</span><span class="n">published</span> <span class="k">IN</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="k">GROUP</span> <span class="k">BY</span> <span class="n">a</span><span class="p">.</span><span class="n">id</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">title</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="k">level</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">lft</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">rgt</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">extension</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">parent_id</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">published</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">a</span><span class="p">.</span><span class="n">lft</span> <span class="k">ASC</span> </pre></div> <h3>After the Optimization</h3> <div class="highlight highlight-sql"><pre> <span class="k">SELECT</span> <span class="k">DISTINCT</span> <span class="k">c</span><span class="p">.</span><span class="n">id</span> <span class="k">AS</span> <span class="n">value</span><span class="p">,</span> <span class="k">c</span><span class="p">.</span><span class="n">title</span> <span class="k">AS</span> <span class="nb">text</span><span class="p">,</span> <span class="k">c</span><span class="p">.</span><span class="k">level</span><span class="p">,</span> <span class="k">c</span><span class="p">.</span><span class="n">published</span> <span class="k">FROM</span> <span class="p">(</span> <span class="k">SELECT</span> <span class="k">DISTINCT</span> <span class="n">id</span><span class="p">,</span><span class="n">title</span><span class="p">,</span><span class="k">level</span><span class="p">,</span><span class="n">published</span><span class="p">,</span><span class="n">parent_id</span><span class="p">,</span><span class="n">extension</span><span class="p">,</span><span class="n">lft</span><span class="p">,</span><span class="n">rgt</span> <span class="k">FROM</span> <span class="o">#</span><span class="n">_categories</span> <span class="k">WHERE</span> <span class="p">(</span><span class="n">extension</span> <span class="o">=</span> <span class="s1">'com_content'</span><span class="p">)</span> <span class="k">AND</span> <span class="n">published</span> <span class="k">IN</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">lft</span> <span class="k">ASC</span> <span class="p">)</span> <span class="k">AS</span> <span class="k">c</span> <span class="k">LEFT</span> <span class="k">JOIN</span> <span class="o">#</span><span class="n">_categories</span> <span class="k">AS</span> <span class="n">b</span> <span class="k">ON</span> <span class="n">x</span><span class="p">.</span><span class="n">lft</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">lft</span> <span class="k">AND</span> <span class="n">x</span><span class="p">.</span><span class="n">rgt</span> <span class="o">&lt;</span> <span class="n">b</span><span class="p">.</span><span class="n">rgt</span> </pre></div> <h3>Query Change Description</h3> <p>In the new query the change is the new sub select. In the previous query the tables are being joined and in the new query as you can see in the red color query is the sub select. In the sub select it filters the rows according to the <code>WHERE</code> clause of the previous query. As you can see this filters the rows and reduce the number of rows before the join and which results a fever number of rows to choose the attributes.Also Removed the group by clause and added the <code>SELECT DISTINCT</code> instead</p> <h2>Testing Instructions:</h2> <p>In order to test this PR first apply the PR via the joomla Patch Test. Then log in to the admin panel and click on the add new article. After clicking on the add new article, the query executes.<br><a href="https://cloud.githubusercontent.com/assets/1329674/3895200/d14f9d8e-224b-11e4-9a13-d83208ea42d5.PNG" target="_blank"><img src="https://cloud.githubusercontent.com/assets/1329674/3895200/d14f9d8e-224b-11e4-9a13-d83208ea42d5.PNG" alt="Add New Article" style="max-width:100%;"></a></p> <h3>Original Query before the Optimization</h3> <div class="highlight highlight-sql"><pre> <span class="k">SELECT</span> <span class="n">a</span><span class="p">.</span><span class="n">id</span> <span class="k">AS</span> <span class="n">value</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">title</span> <span class="k">AS</span> <span class="nb">text</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="k">level</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">published</span> <span class="k">FROM</span> <span class="o">#</span><span class="n">_categories</span> <span class="k">AS</span> <span class="n">a</span> <span class="k">LEFT</span> <span class="k">JOIN</span> <span class="o">#</span><span class="n">_categories</span> <span class="k">AS</span> <span class="n">b</span> <span class="k">ON</span> <span class="n">a</span><span class="p">.</span><span class="n">lft</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">lft</span> <span class="k">AND</span> <span class="n">a</span><span class="p">.</span><span class="n">rgt</span> <span class="o">&lt;</span> <span class="n">b</span><span class="p">.</span><span class="n">rgt</span> <span class="k">WHERE</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">extension</span> <span class="o">=</span> <span class="s1">'com_content'</span><span class="p">)</span> <span class="k">AND</span> <span class="n">a</span><span class="p">.</span><span class="n">published</span> <span class="k">IN</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="k">GROUP</span> <span class="k">BY</span> <span class="n">a</span><span class="p">.</span><span class="n">id</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">title</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="k">level</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">lft</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">rgt</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">extension</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">parent_id</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">published</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">a</span><span class="p">.</span><span class="n">lft</span> <span class="k">ASC</span> </pre></div> <h3>After the Optimization</h3> <div class="highlight highlight-sql"><pre> <span class="k">SELECT</span> <span class="k">DISTINCT</span> <span class="k">c</span><span class="p">.</span><span class="n">id</span> <span class="k">AS</span> <span class="n">value</span><span class="p">,</span> <span class="k">c</span><span class="p">.</span><span class="n">title</span> <span class="k">AS</span> <span class="nb">text</span><span class="p">,</span> <span class="k">c</span><span class="p">.</span><span class="k">level</span><span class="p">,</span> <span class="k">c</span><span class="p">.</span><span class="n">published</span> <span class="k">FROM</span> <span class="p">(</span> <span class="k">SELECT</span> <span class="k">DISTINCT</span> <span class="n">id</span><span class="p">,</span><span class="n">title</span><span class="p">,</span><span class="k">level</span><span class="p">,</span><span class="n">published</span><span class="p">,</span><span class="n">parent_id</span><span class="p">,</span><span class="n">extension</span><span class="p">,</span><span class="n">lft</span><span class="p">,</span><span class="n">rgt</span> <span class="k">FROM</span> <span class="o">#</span><span class="n">_categories</span> <span class="k">WHERE</span> <span class="p">(</span><span class="n">extension</span> <span class="o">=</span> <span class="s1">'com_content'</span><span class="p">)</span> <span class="k">AND</span> <span class="n">published</span> <span class="k">IN</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">lft</span> <span class="k">ASC</span> <span class="p">)</span> <span class="k">AS</span> <span class="k">c</span> <span class="k">LEFT</span> <span class="k">JOIN</span> <span class="o">#</span><span class="n">_categories</span> <span class="k">AS</span> <span class="n">b</span> <span class="k">ON</span> <span class="n">x</span><span class="p">.</span><span class="n">lft</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">lft</span> <span class="k">AND</span> <span class="n">x</span><span class="p">.</span><span class="n">rgt</span> <span class="o">&lt;</span> <span class="n">b</span><span class="p">.</span><span class="n">rgt</span> </pre></div> <h3>Query Change Description</h3> <p>In the new query the change is the new sub select. In the previous query the tables are being joined and in the new query as you can see in the red color query is the sub select. In the sub select it filters the rows according to the <code>WHERE</code> clause of the previous query. As you can see this filters the rows and reduce the number of rows before the join and which results a fever number of rows to choose the attributes.Also Removed the group by clause and added the <code>SELECT DISTINCT</code> instead</p> <p><a href="http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&amp;tracker_item_id=34066">http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&amp;tracker_item_id=34066</a></p>
Labels Removed: ?
avatar infograf768 infograf768 - change - 13 Aug 2014
Labels Added: ?
avatar nadeeshaan
nadeeshaan - comment - 13 Aug 2014

@zero-24
Please consider the execution time of the query. Not the number of rows.
cause number of rows should be the same. What I explained was in the sub
select it selects a reduced number of rows in order to join with the next
table

On Wed, Aug 13, 2014 at 7:50 PM, zero-24 notifications@github.com wrote:

@test https://github.com/test @nadeeshaan
https://github.com/nadeeshaan i can confirm the query change. ok here.
Is there any special thing that can/need be tested? It still retrun the
same count of rows om my end.


Reply to this email directly or view it on GitHub
#4106 (comment).

Nadeeshaan Gunasinghe
Department of Computer Science and Engineering
University of Moratuwa
Sri Lanka

avatar nadeeshaan nadeeshaan - change - 13 Aug 2014
Title
Sql optimise category edit options branch2
[#34066] Sql optimise category edit options branch2
avatar zero-24
zero-24 - comment - 13 Aug 2014

thanks @nadeeshaan I can confirm the result by @infograf768

My results are:
Query time bevor the patch: 6.76 ms
Query time after the patch: 1.78 ms

So full success here. :+1:

avatar 810
810 - comment - 14 Aug 2014

My test results are different:
Query time before the patch: 2.18 ms

before

Query time after the patch: 2.29 ms

after

avatar infograf768
infograf768 - comment - 15 Aug 2014

@810
For 3 rows ? Weird...

avatar infograf768
infograf768 - comment - 15 Aug 2014

@nadeeshan
This should be tested with the other types of DB

avatar nadeeshaan
nadeeshaan - comment - 15 Aug 2014

@infograf768
Yes of course. For that we need the support of community members who use the other type of DBs. I think all will give the support in this testing process.
:)

avatar beat
beat - comment - 15 Aug 2014

@nadeeshaan Use of subquery would makes sense but think there is an error in your description (mentioning x.). Additionally, in this case the LEFT JOIN could be avoided completely imho, as b is not used at all in the query!!!

@all Imho, those optimization tests should be conducted with large datasets and after having queried the database at least 20 times if not more, so that it has "warmed-up", not with just 3, 30 or even 300 rows, if you want to have any meaningful results, thousands or tens of thousands of rows are needed to see a significant result.

avatar dgt41
dgt41 - comment - 15 Aug 2014

@beat com_overload is sufficient for the task? Any links for a Joomla 3 compatible version?

avatar beat
beat - comment - 15 Aug 2014

@dgt41 don't understand your question. What is com_overload ?

What I said, is that even though table b is joined in "Original Query before the Optimization" above in the description, none of its columns is used. Moreover, as it is a left join, the only benefit is to have multiple repeated rows depending on if more than 1 left join is possible. So the query itself seems buggy. I guess its original intend was to compute the level by counting the joined elements, but as the (redundant) "level" column exists and is used here, the join is a leftover from the past (from when nested trees were implemented according to The Book).

So not sure that the optimization makes any sense (didn't look at the PHP code as the diff shows not that easily understandable original code).

avatar dgt41
dgt41 - comment - 15 Aug 2014

com_overload is a component that creates mass content in joomla: http://github.com/nikosdion/com_overload
But I am not so sure that is up to date, last commit was like a year ago

avatar brianteeman
brianteeman - comment - 15 Aug 2014

com-overload should work fine on j3,3 - I have it running on my test site right now building over 1000 categories and 1500 articles.

On 15 August 2014 22:40, dgt41 notifications@github.com wrote:

com_overload is a component that creates mass content in joomla:
http://github.com/nikosdion/com_overload
https://github.com/nikosdion/com_overload
But I am not so sure that is up to date, last commit was like a year ago


Reply to this email directly or view it on GitHub
#4106 (comment).

Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/

avatar dgt41
dgt41 - comment - 15 Aug 2014

:+1: Brian, I already setup a new test bench, I will post some results when the script finish adding stuff
https://www.dropbox.com/s/crkqx6mfpg7zty6/Screenshot%202014-08-16%2001.01.14.png

avatar brianteeman
brianteeman - comment - 15 Aug 2014

Yeah. I've set mine running and will test tomorrow
On 15 Aug 2014 23:03, "dgt41" notifications@github.com wrote:

[image: :+1:] Brian, I already setup a new test bench, I will post some
results when the script finish adding stuff

https://www.dropbox.com/s/crkqx6mfpg7zty6/Screenshot%202014-08-16%2001.01.14.png


Reply to this email directly or view it on GitHub
#4106 (comment).

avatar dgt41
dgt41 - comment - 16 Aug 2014

Here are my test results

No PHP opcode, cache, no joomla cache, no MYSQL query_cache
PHP 5.5.10, Mysql 5.5.34
Data set:
Table assets: 18.509
Table categories: 1.119
Table content: 17.364

Before: 404.42ms
After: 9.11ms

screenshot 2014-08-16 04 06 29

avatar brianteeman
brianteeman - comment - 16 Aug 2014

@test
Tested with 1178 categories and 57345 articles (created by com_overload)
before 884.51ms
after 16.39ms

screenshot 2014-08-16 11 10 11
screenshot 2014-08-16 11 12 10

avatar dgt41
dgt41 - comment - 16 Aug 2014

By the way @beat's suggestion to remove the last left join
line:101 ->join('LEFT', $db->quoteName('#__categories') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt’);
made things worst:
screenshot 2014-08-16 13 27 18

avatar alikon
alikon - comment - 18 Aug 2014

@test
test conditions:
no MYSQL query_cache, Mysql 5.6.16
Data set:
Table assets: 15427
Table categories: 1561
Table content: 13639

tool used: mysqlslap
only the affected query is tested pure sql

old query

alikon@PC-ALIKON c:\xampp
# mysqlslap --concurrency=10 --iterations=10 --query=old_pr6.sql --create-schema
=gtest  -uroot -padmin
Warning: Using a password on the command line interface can be insecure.
Benchmark
        Average number of seconds to run all queries: 27.457 seconds
        Minimum number of seconds to run all queries: 26.557 seconds
        Maximum number of seconds to run all queries: 27.900 seconds
        Number of clients running queries: 10
        Average number of queries per client: 1

new query

alikon@PC-ALIKON c:\xampp
# mysqlslap --concurrency=10 --iterations=10 --query=new_pr6.sql --create-schema
=gtest  -uroot -padmin
Warning: Using a password on the command line interface can be insecure.
Benchmark
        Average number of seconds to run all queries: 0.599 seconds
        Minimum number of seconds to run all queries: 0.265 seconds
        Maximum number of seconds to run all queries: 1.359 seconds
        Number of clients running queries: 10
        Average number of queries per client: 1
avatar nicksavov nicksavov - change - 21 Aug 2014
Labels Removed: ?
avatar nicksavov nicksavov - change - 21 Aug 2014
Title
Sql optimise category edit options branch2
[#34066] Sql optimise category edit options branch2
avatar brianteeman brianteeman - change - 22 Aug 2014
Labels Added: ?
avatar brianteeman brianteeman - change - 22 Aug 2014
Labels Added: ?
avatar Bakual Bakual - reference | - 31 Aug 14
avatar Bakual Bakual - close - 31 Aug 2014
avatar Bakual
Bakual - comment - 31 Aug 2014

Merged into the 3.4-dev branch. Thanks!

avatar Bakual Bakual - change - 31 Aug 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-08-31 18:39:46
avatar Bakual Bakual - close - 31 Aug 2014

Add a Comment

Login with GitHub to post a comment