Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

casting identifier to string since it is a varchar database field #1432

Merged
merged 1 commit into from
Oct 21, 2015

Conversation

mariohiller
Copy link
Contributor

I have had some strange performance issues with the Translatable Behavior after having arount 1 million rows in ext_translations. Queries were dropping to around 300 - 400ms. Checking the Queries I found the following:

This query, generated by the behavior, is slow ( ~300ms ):
SELECT * FROM ext_translations WHERE object_class = 'Demo\DemoBundle\Entity\Demo' AND locale = 'en' AND foreign_key = 111

This query is fast ( ~1ms ):
SELECT * FROM ext_translations WHERE object_class = 'Demo\DemoBundle\Entity\Demo' AND locale = 'en' AND foreign_key = '111'

There are two posibilities to "solve" this. Changing the the foreign_key column to integer did the same performance boost. But since ids can also be alphanumeric this is probably a bad idea to change globally. Casting the identifier to string seems to be no problem, since it is a varchar field anyways. Local tests only increased performance so far.

Thanks for discussing this change with me ( maybe there is a totally easy and obvious different solution to this issue :) ).

Regards,
Mario

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Oct 21, 2015

Hi, another way would be to either use personal translations or extend translation superclass and override mapping to integer type. the default string was chosen, because it would fit all cases out of the box, though sacrificing performance, but in most cases if you have a mil of records you may need to customize anyway. The default behavior should fit only basic needs.
I see that this optimization will help a lot with the default behavior, thanks!

l3pp4rd added a commit that referenced this pull request Oct 21, 2015
casting identifier to string since it is a varchar database field
@l3pp4rd l3pp4rd merged commit 14ab29a into doctrine-extensions:master Oct 21, 2015
@l3pp4rd
Copy link
Contributor

l3pp4rd commented Oct 21, 2015

though, probably will still need to check metadata, whether it is integer or string..

l3pp4rd added a commit that referenced this pull request Oct 21, 2015
@mariohiller
Copy link
Contributor Author

I have seen your changes in commit 8bf241d which reverts the effect of my changes :)
Doctrine\DBAL\Types\StringType::convertToPHPValue() does nothing to the value, so the resulting query is slow again. Or did I miss anything?

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Oct 26, 2015

maybe I've made a mistake here, will have a look later

l3pp4rd added a commit that referenced this pull request Oct 30, 2015
@TriAnMan
Copy link

@mariohiller I've made a workaround for preformance problems in 2.x versions of Translatable.
Could you look at #1512?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants