[DDC-1958] pager produces wrong results on postgresql Created: 30/Jul/12 Updated: 06/Aug/13 Resolved: 12/Nov/12
|Project:||Doctrine 2 - ORM|
|Reporter:||Miha Vrhovnik||Assignee:||Benjamin Eberlei|
The query build by pager to get the subset of PKs to fetch produces wrong results on potgresql (and probably any database), that conforms to the SQL standard. The standard says, that if you wish to have the results in specific order, then you have to specify that by using an ORDER BY clause. If such a clause is not present the database can return the results in whatever order it sees fit.
to pager produces SQL like this modified for readability
Now there is nothing wrong with this modified query per se, but there is no ORDER BY clause in the outer query so according to the standard the DB can choose whatever order it seems fit. Now mysql chooses the same order, but postgresql does not and it's probably not the only DB doing so.
If you are interested in the results, this is the output I'm seeing:
I and my coworker came to the standard compliant solution it was also tested on the dataset above on both postgresql and mysql and it produced equal results. We have found only one corner case this won't work and IMHO that can't be fixed. The problem is when you do a sort on a field from a table that is in 1:n relation to the main table.. e.g tables posts and tags, where one post can have a multiple tags and you want your results sorted by a tag.
Recipe for a correct query is:
so if I take the example from above the SQL should look like this:
|Comment by Jean-Philippe THEVENOUX [ 08/Nov/12 ]|
I reproduce same problem with Postgres 7.4, Doctrine 2.3 whereas with doctrine 2.2, all is fine
|Comment by Raymond Kolbe [ 09/Apr/13 ]|
http://www.doctrine-project.org/jira/browse/DDC-1800 This relates.
I just published a PR for an Oracle fix, but your solution appears to work for Oracle as well (issue is the same).
|Comment by Bojidar Hristov [ 06/Aug/13 ]|
Same bug occurs in MariaDB 5.5.
I commented out check for PostgreSQL and it works fine. Can you fix it for MariaDB too? Thanks