DDC-2752: Item order lost using paginator #3445

Closed
opened 2026-01-22 14:19:59 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 20, 2013).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user krmarien:

We are using the doctrine pagination tool for faster queries in paginated results.

But doctrine is now creating the following query:

SELECT DISTINCT id0 FROM (
SELECT c0_.id AS id0, c0_.number AS number1
FROM cudi.stock_orders_items c0_
INNER JOIN cudi.stock_orders c1_ ON c0_.order_id = c1_.id
WHERE c1_.date_ordered IS NOT NULL AND c1_.date_ordered > $1 AND c1_.date_ordered < $2
ORDER BY c1_.date_ordered DESC
) dctrn_result LIMIT 25 OFFSET 50

But due to the distinct, the order is lost and the results are not sorted by date_ordered anymore. How can this be solved?

Thanks

Originally created by @doctrinebot on GitHub (Oct 20, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user krmarien: We are using the doctrine pagination tool for faster queries in paginated results. But doctrine is now creating the following query: SELECT DISTINCT id0 FROM ( SELECT c0_.id AS id0, c0_.number AS number1 FROM cudi.stock_orders_items c0_ INNER JOIN cudi.stock_orders c1_ ON c0_.order_id = c1_.id WHERE c1_.date_ordered IS NOT NULL AND c1_.date_ordered > $1 AND c1_.date_ordered < $2 ORDER BY c1_.date_ordered DESC ) dctrn_result LIMIT 25 OFFSET 50 But due to the distinct, the order is lost and the results are not sorted by date_ordered anymore. How can this be solved? Thanks
admin added the Bug label 2026-01-22 14:19:59 +01:00
admin closed this issue 2026-01-22 14:19:59 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 20, 2013):

Comment created by @ocramius:

[~cyberwolf] is the order lost already in this result or in the WHERE IN() subsequent query?

@doctrinebot commented on GitHub (Oct 20, 2013): Comment created by @ocramius: [~cyberwolf] is the order lost already in this result or in the `WHERE IN()` subsequent query?
Author
Owner

@doctrinebot commented on GitHub (Oct 20, 2013):

Comment created by krmarien:

I was digging in the paginator code and this is the query used to select the ids in \Doctrine\ORM\Tools\Pagination\Paginator (line 173)

The subquery from above, outputs the results in the right order. But after applying the distinct the order is messed up. I think this problem needs to be solved by the preserveSqlOrdering function in LimitSubqueryOutputWalker. But this function doesn't add a column to sort on...

@doctrinebot commented on GitHub (Oct 20, 2013): Comment created by krmarien: I was digging in the paginator code and this is the query used to select the ids in \Doctrine\ORM\Tools\Pagination\Paginator (line 173) The subquery from above, outputs the results in the right order. But after applying the distinct the order is messed up. I think this problem needs to be solved by the preserveSqlOrdering function in LimitSubqueryOutputWalker. But this function doesn't add a column to sort on...
Author
Owner

@doctrinebot commented on GitHub (Oct 26, 2013):

Comment created by @beberlei:

[~krmarien] Since you have the example already, so you mean the ORDER BY has to be part of the subquery and ALSO added to the outer query? That actually makes sense.

@doctrinebot commented on GitHub (Oct 26, 2013): Comment created by @beberlei: [~krmarien] Since you have the example already, so you mean the ORDER BY has to be part of the subquery and ALSO added to the outer query? That actually makes sense.
Author
Owner

@doctrinebot commented on GitHub (Oct 28, 2013):

Comment created by krmarien:

That would solve the problem for me.

@doctrinebot commented on GitHub (Oct 28, 2013): Comment created by krmarien: That would solve the problem for me.
Author
Owner

@doctrinebot commented on GitHub (Nov 20, 2013):

Comment created by krmarien:

Any progress on this issue?

@doctrinebot commented on GitHub (Nov 20, 2013): Comment created by krmarien: Any progress on this issue?
Author
Owner

@doctrinebot commented on GitHub (Dec 4, 2013):

Comment created by krmarien:

I have found another query with the same problem. The common thing they have is that I want to order on a column of a joined entity.

@doctrinebot commented on GitHub (Dec 4, 2013): Comment created by krmarien: I have found another query with the same problem. The common thing they have is that I want to order on a column of a joined entity.
Author
Owner

@doctrinebot commented on GitHub (Dec 6, 2013):

Comment created by krmarien:

After digging in the code I found that I just had to add the joined entity to my select statement. This issue can be closed

@doctrinebot commented on GitHub (Dec 6, 2013): Comment created by krmarien: After digging in the code I found that I just had to add the joined entity to my select statement. This issue can be closed
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2013):

Issue was closed with resolution "Won't Fix"

@doctrinebot commented on GitHub (Dec 13, 2013): Issue was closed with resolution "Won't Fix"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3445