? Success

User tests: Successful: Unsuccessful:

avatar alikon
alikon
2 Jun 2016

Summary of Changes

use index scan instead of sequential scan changing the order of the WHERE conditions

Testing Instructions

save/create an article this query is executed to verify that there is no the same alias i guess
usenoindex

as you can see enabling debug plugin + some dirty hack see #10567 (comment) thanks @ggppdk

the #__content table is scanned sequential but that table alreay have an index on the field catid,
so we can have some performance benefit simply take advantages from the index

apply the patch and then the index is used
usetheindex

Additional comments

question for the #php experts
Can someone explain why this query is issued 3 times ???

can give some speed to #10567

avatar alikon alikon - open - 2 Jun 2016
avatar alikon alikon - change - 2 Jun 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 2 Jun 2016
Labels Added: ?
avatar alikon alikon - change - 2 Jun 2016
The description was changed
avatar alikon alikon - change - 2 Jun 2016
The description was changed
avatar alikon alikon - change - 2 Jun 2016
The description was changed
avatar brianteeman brianteeman - change - 2 Jun 2016
Category Components
avatar andrepereiradasilva
andrepereiradasilva - comment - 2 Jun 2016

@alikon, i'm no expert in db as youknow, so let me try to understand this.

Basicly you change the order of the where clauses in the query so the catid is called first, and by that, since the catid has an index (and alias not) it improves the performance, right?

Anyway, this are my results (clean joomla install) with mysql

Before:
image

After
image

i notice the "using where" after patch is this how it's supossed to be?

reggarding the query being repeated 3 times:
i only have it one time

avatar ggppdk
ggppdk - comment - 3 Jun 2016

Hello

@andrepereiradasilva , @alikon , @pici65

i found time to test, with a big website and a category with 4200 articles
(created an article inside the category that has 4200 articles)

Database is on an SSD

  • if it is not on SSD, then you have 10x 20x bigger times ...

I confirm the finding of @alikon, delay is due to the duplicate alias check (duplicate inside the same category)


Article creation

  • duplicate alias query executed 3 times 3 x (about) 2 seconds = 4 to 6 seconds

Article update

  • duplicate alias query executed 1 times cost: about 2 seconds to 3 seconds

but this PR gives no benefit

i tested by adding an index to the alias column
the query is reduced to ... 6.5 milliseconds

Solution is to remove duplicate alias check or to add an index to the alias column

  • note same problem is faced by any TABLE that tries to check for duplicate alias inside the given category, when the table does not have an index for the alias column
avatar mbabker
mbabker - comment - 3 Jun 2016

The duplicate alias check is required at the PHP level without efficient
SQL schema to enforce duplicate aliases and an efficient manner to execute
a query and rely on that schema to raise the appropriate error for a model
to know it needs to auto-increment the duplicated alias. So the index and
query optimization will have to be good enough for now.

On Thursday, June 2, 2016, Georgios Papadakis notifications@github.com
wrote:

Hello

@andrepereiradasilva https://github.com/andrepereiradasilva , @alikon
https://github.com/alikon , @pici65 https://github.com/pici65

i found time to test, with a big website and a category with 4200 articles
(created an article inside the category that has 4200 articles)

Database is on an SSD

  • if it is not on SSD, then you have 10x 20x bigger times ...

I confirm the finding of @alikon https://github.com/alikon, delay is

due to the duplicate alias check (duplicate inside the same category)

Article creation

  • duplicate alias query executed 3 times 3 x (about) 2 seconds = 4 to 6 seconds

Article update

  • duplicate alias query executed 1 times cost: about 2 seconds to 3 seconds

but this PR gives no benefit

i tested by adding an index to the alias column
the query is reduced to ... 6.5 milliseconds

Solution is to remove duplicate alias check or to add an index to the
alias column

  • note same problem is faced by any TABLE that tries to check for duplicate alias inside the given category, when the table does not have an index for the alias column


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#10710 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAWfoc_ax1FVENC6B33vCa2dFOGCEO_5ks5qH3UWgaJpZM4IsbO_
.

avatar ggppdk
ggppdk - comment - 3 Jun 2016

Ok, surely the solution is to add the index to alias column,

not only because of duplicate alias check being required,

but because in future (or even now) more SQL queries may need the index to be there

avatar alikon
alikon - comment - 3 Jun 2016

The #__content table already have IRC 8 indexes if we want to add another
one maybe the better solution should be to add a composite index
alias+catid to full match the WHERE conditions instead of a partial match
on only the alias field...
On 3 Jun 2016 10:27 am, "Georgios Papadakis" notifications@github.com
wrote:

Ok, surely the solution is to add the index to alias column,

not only because of duplicate alias check being required,

but because in future (or even now) more SQL queries may need the index to
be there


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#10710 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AALFsWvsPd0EpfJPMc3jg4c3iVsB2Z2Pks5qH-VsgaJpZM4IsbO_
.

avatar ggppdk
ggppdk - comment - 3 Jun 2016

ok we agree that a new index is needed

but i will disagree on the composite index, it is best to have an atomic index on the alias column,

  • let's not target to optimize this query only, we do not know which other query may use alias in the future or using it already
avatar ggppdk
ggppdk - comment - 3 Jun 2016

Hi

i forgot to say and please correct me if i am wrong

  • since the alias is unique inside a category (because current PHP will never insert a duplicate alias inside same category)

adding a composite index: alias+catid
is a total waste

[EDIT ... explanation] :
because you would need e.g. 100+ categories to have articles with same alias to get the composite index to produce a slight benefit

so 1 more reason why, the index on alias should be atomic on the alias column only

[EDIT]
adding a composite index: catid+alias is a different case (it will give just a little more performance benefit), but

  • it will not be useable by queries that want to limit by alias only
  • the benefit that will give compared to the atomic index on alias will be really small, unless you have 100,000 ? a million articles web-site thus it may make a little noticeable difference ?
avatar alikon
alikon - comment - 6 Jun 2016

@ggppdk it's not so uncommon that sites have more than 100 categories as far as i know, but i can agree with you that can be more common for a query to have only the alias field in the where condition so let's go with an atomic index for now after all there is a performance gain, we will see in the future if some report will be issued regarding sites with a lot of categories....

closing this one in favor of #10739

avatar alikon alikon - change - 6 Jun 2016
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2016-06-06 10:04:58
Closed_By alikon
avatar alikon alikon - close - 6 Jun 2016

Add a Comment

Login with GitHub to post a comment