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

feat(pagination): provide a way to manually disable distinct on count #6036

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gquemener
Copy link
Contributor

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.

Q A
Branch? main
Tickets
License MIT
Doc PR to write (depending on the output of the discussion)

TODO:

  • write doc (api-platform/docs)
  • Update CHANGELOG.md
  • Discuss alternatives

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.

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.
@@ -80,6 +80,10 @@ public function getResult(QueryBuilder $queryBuilder, string $resourceClass = nu
$query->setHint(CountWalker::HINT_DISTINCT, false);
}

if (null !== $distinctCount = $operation?->getDistinctCount()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a stateOption instead (see the Options object on the ORM namespace). I'd keep the option but we should probably check that the JOIN doesn't exist.

@soyuka
Copy link
Member

soyuka commented Dec 29, 2023

Hi @gquemener will you work this feature?

Copy link

stale bot commented Feb 27, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 27, 2024
@stale stale bot removed the stale label Feb 29, 2024
@soyuka soyuka removed the enhancement label Apr 3, 2024
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

2 participants