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

Remove ORDER BY when counting collection items #529

Open
mrceperka opened this issue Aug 1, 2021 · 4 comments · May be fixed by #530
Open

Remove ORDER BY when counting collection items #529

mrceperka opened this issue Aug 1, 2021 · 4 comments · May be fixed by #530
Milestone

Comments

@mrceperka
Copy link

mrceperka commented Aug 1, 2021

Describe the bug
Calling $collection->countStored() should remove ORDER BY clause

To Reproduce

// SomeMapper.php

$builder->addOrderBy('id');
$builder->limitBy(10, 0);
// ...
$collection = $this->toCollection($builder);

// counting with ORDER BY, which is weird, because order does not matter
$total = $collection->countStored();


// hotfix
$collection  = $this->toCollection((clone $builder)->orderBy(null));
// counting without ORDER BY
$total = $collection->countStored();

Expected behavior
ORDER BY clause should be removed

Versions:

  • Database: mariadb 10.4
  • Orm: 4.0
  • Dbal: 4.0

TODO

  • test case
  • PR with fix
@mrceperka
Copy link
Author

@hrach can this if statement be removed?

if (!$builder->hasLimitOffsetClause()) {

@hrach
Copy link
Member

hrach commented Aug 1, 2021

Probably. Not fully sure now what was the reason for it. You may try it and see if any test "needs it".

@mrceperka mrceperka linked a pull request Aug 1, 2021 that will close this issue
@mrceperka
Copy link
Author

Probably. Not fully sure now what was the reason for it. You may try it and see if any test "needs it".

I've found it :(

-- FAILED: integration/Collection/collection.phpt dataprovider=sqlsrv|/home/runner/work/orm/orm/tests/cases/integration/Collection/../../../databases.ini method=testCountStoredDbalWithoutOrderByClause
   Exited with error code 255 (expected 0)
   Nextras\Dbal\Drivers\Exception\QueryException: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near 'OFFSET'.

@hrach
Copy link
Member

hrach commented Aug 2, 2021

We could workaround it and keep the ordering only for MSSQL.

@hrach hrach added this to the v5.0 milestone Dec 12, 2021
@hrach hrach removed the bug label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants