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

Add option to select max position through ORDER BY + LIMIT 1 #2906

Open
ywarnier opened this issue Dec 24, 2024 · 0 comments
Open

Add option to select max position through ORDER BY + LIMIT 1 #2906

ywarnier opened this issue Dec 24, 2024 · 0 comments

Comments

@ywarnier
Copy link
Contributor

ywarnier commented Dec 24, 2024

In the following code, obtaining the maximum value for a field uses a query in the select('MAX(n.'.$config['position'].')') form.

https://github.com/doctrine-extensions/DoctrineExtensions/blob/5d80d9d348e0384f0b0d2096bdd7c4a07009a866/src/Sortable/Mapping/Event/Adapter/ORM.php#L40C1-L41C51

In the case of a large table (hundreds of thousands of records) with an index that includes the field to be sorted, it can be about 10 times more efficient to issue a query of the form select(n.'.$config['position'].')') with an added sorting like ORDER BY n.'.$config['position'].' DESC LIMIT 1)').

Given the class is final, it is very complicated to include a change downstream to allow us to use this second method.

I would like to humbly request a feature that allows me to configure (maybe through the Gedmo annotations) this query to use the ORDER BY form rather than the MAX() form.

This already seems to be the case by default in ODM.php, but I'm not very familiar with the non-relational query builder.

$qb->sort($config['position'], 'desc');

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

No branches or pull requests

1 participant