feat(pagination): provide a way to manually disable distinct on count #6036
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Using DISTINCT in a COUNT has a major impact on performance. This change pushes the existing fix forward by delegating the responsibility to disable the DISTINCT presence to the developers.
For instance, it is possible to safely remove the DISTINCT from a query that joins a "to one" association.
The existing optimization still exists for most cases.
TODO:
I'm not a big fan of this solution, given the amount of properties that already exist on the
Operation
class (including its inheritance tree).An alternative would be to change the current detection behavior (which is only based on the number of aliases in the query), to take into account the type of the associations ("to one" association are ok, DISTINCT should be discardable). I could use the
QueryChecker::hasJoinedToManyAssociation
for instance.Any suggestions on how to proceed are very welcome,
Thanks.