mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
[Perf] useless discriminator column filtering for top level classes #6185
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rbs-asimon on GitHub (Feb 22, 2019).
Originally assigned to: @Ocramius on GitHub.
Given the following Address mapping :
It seems to me that the SQL translation of the DQL
SELECT a, FROM Addressshould be the simpleSELECT q0_... FROM "quote-address" q0_instead of the actualSELECT q0_... FROM "quote-address" q0_ WHERE q0_.type IN ('simple', 'full').It is certainly not wrong but sometimes not so optimal : the condition is only needed when you ask for a subclass.
@Ocramius commented on GitHub (Feb 23, 2019):
The discriminator is to be covered by an index anyway: closing, since this is not an issue.
@rbs-asimon commented on GitHub (Feb 23, 2019):
@Ocramius Thank you for the feedback.
I have to disagree : it can sometimes be an issue. Please take a look at these MySQL results :
Given the table :
populated with some rows :
We can compare
select count(*) from address where entity_type in(1,2)andselect count(*) from address:@Messere commented on GitHub (Feb 17, 2021):
Just a note: indexes on discriminator were suggested to be bad practice in https://github.com/doctrine/orm/issues/2037
and I can see how having an index on discriminator needs to be considered as case by case optimization.
Omitting any condition that is know to always evaluate to true seems like a good idea, especially that db engine has no way to know it and needs to evaluate the condition with each query.