Le 11/06/2014 17:40, 'Jasper N. Brouwer' via doctrine-user a écrit :
In the first query, DISTINCT is used to fetch unique ids. The ORDER BY is in 
there because it's in your query, but theoritically it isn't needed here. This 
query should fetch _all_ ids, so the order isn't relevant.
It's strange though there's a ROWNUM in the first query, as far as I know it 
shouldn't be there.

The second query is the one that will actually retreive the results that get 
hydrated. There should be no DISTINCT in there, and the ROWNUM should be.

PS: I've no experience with Oracle (or Doctrine in combination with Oracle), so 
maybe someone else can elaborate on the ROWNUM in the first query?

The first query does not retrieve all ids. It retrieves the paginated ids for the elements which should be returned. So the ORDER BY is needed here, otherwise you will get random elements in your results. Applyign the LIMIT must be done on the id query without joins. this is precisely why it is done. If you fetch join a collection in your query, we cannot apply a limit on it directly, because a single object will span multiple result row (one per element in the collection) because of how joins work.

Note that if your DQL query does not fetch join a collection (i.e. it only joins toOne relations or the toMany relations are only used in the WHERE clause and not in the SELECT clause), you can use the second argument of the Paginator constructor to tell it it can do the pagination in a single query rather than 2.

--
Christophe | Stof

--
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to