<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Thu Jun 20 04:32:36 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DDC-1800/DDC-1800.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DDC-1800] Paginator results is wrong if your query use order by clause</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-1800</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;NOTE: I didn&apos;t try this on other database, I&apos;m using Oracle.&lt;/p&gt;

&lt;p&gt;if my original fetchJoin query use an order by clause, the results is not keeping the provided order by clause and re-order them by id.&lt;/p&gt;

&lt;p&gt;here is my generated query to get the distinct records that get generated:&lt;/p&gt;

&lt;p&gt;SELECT distinct ID0&lt;br/&gt;
FROM &lt;br/&gt;
(&lt;br/&gt;
  SELECT f0_.id AS ID0, f0_.deal_type_id AS DEAL_TYPE_ID1, f0_.title AS TITLE2, f0_.deal_date AS DEAL_DATE3, f0_.amount AS AMOUNT4, &lt;br/&gt;
    f0_.abstract AS ABSTRACT5, f0_.created_date AS CREATED_DATE6, f0_.last_updated_date AS LAST_UPDATED_DATE7, &lt;br/&gt;
    f0_.object_status_id AS OBJECT_STATUS_ID8, f0_.published_date AS PUBLISHED_DATE9, f0_.publishing_status_id AS PUBLISHING_STATUS_ID10, &lt;br/&gt;
    f1_.id AS ID11, f1_.role_id AS ROLE_ID12, f1_.role_type_id AS ROLE_TYPE_ID13, f2_.id AS ID14, f3_.id AS ID15, f4_.id AS ID16, f5_.id AS ID17, &lt;br/&gt;
    c6_.id AS ID18, d7_.id AS ID19 &lt;br/&gt;
  FROM fo_deal f0_ &lt;br/&gt;
  INNER JOIN fo_deal_role f1_ ON f0_.id = f1_.deal_id &lt;br/&gt;
  INNER JOIN fo_people f2_ ON f1_.people_id = f2_.id &lt;br/&gt;
  INNER JOIN fo_property_deal f3_ ON f0_.id = f3_.deal_id &lt;br/&gt;
  INNER JOIN fo_property f4_ ON f3_.property_id = f4_.id &lt;br/&gt;
  LEFT JOIN fo_property_asset f5_ ON f4_.id = f5_.property_id &lt;br/&gt;
  LEFT JOIN co_asset c6_ ON f5_.asset_id = c6_.id &lt;br/&gt;
  LEFT JOIN ds_record d7_ ON c6_.ds_id = d7_.id &lt;br/&gt;
  WHERE f1_.people_id = 2 &lt;br/&gt;
  AND f0_.object_status_id &amp;lt;&amp;gt; 3 &lt;br/&gt;
  AND f0_.publishing_status_id = 2 &lt;br/&gt;
  ORDER BY f0_.deal_date DESC, f0_.published_date DESC&lt;br/&gt;
)&lt;/p&gt;

&lt;p&gt;running this query I get the id 30, 44 when the inner query return 44, 30&lt;/p&gt;

&lt;p&gt;here is the query that should get generated to take care of the order by clause:&lt;br/&gt;
SELECT distinct ID0, rownum+&lt;br/&gt;
FROM &lt;br/&gt;
(&lt;br/&gt;
  SELECT f0_.id AS ID0, f0_.deal_type_id AS DEAL_TYPE_ID1, f0_.title AS TITLE2, f0_.deal_date AS DEAL_DATE3, f0_.amount AS AMOUNT4, &lt;br/&gt;
    f0_.abstract AS ABSTRACT5, f0_.created_date AS CREATED_DATE6, f0_.last_updated_date AS LAST_UPDATED_DATE7, &lt;br/&gt;
    f0_.object_status_id AS OBJECT_STATUS_ID8, f0_.published_date AS PUBLISHED_DATE9, f0_.publishing_status_id AS PUBLISHING_STATUS_ID10, &lt;br/&gt;
    f1_.id AS ID11, f1_.role_id AS ROLE_ID12, f1_.role_type_id AS ROLE_TYPE_ID13, f2_.id AS ID14, f3_.id AS ID15, f4_.id AS ID16, f5_.id AS ID17, &lt;br/&gt;
    c6_.id AS ID18, d7_.id AS ID19 &lt;br/&gt;
  FROM fo_deal f0_ &lt;br/&gt;
  INNER JOIN fo_deal_role f1_ ON f0_.id = f1_.deal_id &lt;br/&gt;
  INNER JOIN fo_people f2_ ON f1_.people_id = f2_.id &lt;br/&gt;
  INNER JOIN fo_property_deal f3_ ON f0_.id = f3_.deal_id &lt;br/&gt;
  INNER JOIN fo_property f4_ ON f3_.property_id = f4_.id &lt;br/&gt;
  LEFT JOIN fo_property_asset f5_ ON f4_.id = f5_.property_id &lt;br/&gt;
  LEFT JOIN co_asset c6_ ON f5_.asset_id = c6_.id &lt;br/&gt;
  LEFT JOIN ds_record d7_ ON c6_.ds_id = d7_.id &lt;br/&gt;
  WHERE f1_.people_id = 2 &lt;br/&gt;
  AND f0_.object_status_id &amp;lt;&amp;gt; 3 &lt;br/&gt;
  AND f0_.publishing_status_id = 2 &lt;br/&gt;
  ORDER BY f0_.deal_date DESC, f0_.published_date DESC&lt;br/&gt;
) ORDER BY rownum ASC&lt;/p&gt;

&lt;p&gt;To fix this on the Paginator code:&lt;/p&gt;

&lt;p&gt;file: ORM/Tools/Pagination/LimitSubqueryOutputWalker.php&lt;br/&gt;
method: walkSelectStatement&lt;/p&gt;

&lt;p&gt;change: &lt;br/&gt;
$sql = sprintf(&apos;SELECT b.*, rownum as rn FROM (SELECT DISTINCT %s FROM (%s)) b&apos;, // AS _dctrn_result&apos;,&lt;br/&gt;
            implode(&apos;, &apos;, $sqlIdentifier), $sql);&lt;/p&gt;

&lt;p&gt;for:&lt;br/&gt;
$sql = sprintf(&apos;SELECT b.*, rownum as rn FROM (SELECT DISTINCT %s, numrow FROM (%s) ORDER BY numrow ASC) b&apos;, // AS _dctrn_result&apos;,&lt;br/&gt;
            implode(&apos;, &apos;, $sqlIdentifier), $sql);&lt;/p&gt;</description>
                <environment>linux oracle</environment>
            <key id="13664">DDC-1800</key>
            <summary>Paginator results is wrong if your query use order by clause</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="mdrolet">Marc Drolet</reporter>
                        <labels>
                    </labels>
                <created>Fri, 27 Apr 2012 19:52:20 +0000</created>
                <updated>Tue, 9 Apr 2013 20:03:37 +0000</updated>
                    <resolved>Wed, 29 Aug 2012 13:18:33 +0000</resolved>
                            <version>2.2.2</version>
                                <fixVersion>2.2.4</fixVersion>
                <fixVersion>2.3</fixVersion>
                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="17946" author="mdrolet" created="Mon, 14 May 2012 14:30:41 +0000"  >&lt;p&gt;rownum instead of numrow.  sorry.&lt;/p&gt;

&lt;p&gt;$sql = sprintf(&apos;SELECT b.*, rownum as rn FROM (SELECT DISTINCT %s, rownum FROM (%s) ORDER BY rownum ASC) b&apos;,&lt;br/&gt;
            implode(&apos;, &apos;, $sqlIdentifier), $sql);&lt;/p&gt;</comment>
                    <comment id="18228" author="beberlei" created="Sat, 7 Jul 2012 16:20:28 +0000"  >&lt;p&gt;Doctrine 2.2.2 doesnt have the LimitSubqueryoutputWalker and Doctrine 2.3-dev does not have the line in the code. Can you make a more explicit statement of where the change is necessary?&lt;/p&gt;</comment>
                    <comment id="18254" author="mdrolet" created="Mon, 9 Jul 2012 13:44:59 +0000"  >&lt;p&gt;It&apos;s in the Pagination of version 2.2.2.  ORM/Tools/Pagination/LimitSubqueryOutputWalker.php&lt;/p&gt;</comment>
                    <comment id="18260" author="beberlei" created="Mon, 9 Jul 2012 15:15:11 +0000"  >&lt;p&gt;This is the 2.2 branch, &lt;a href=&quot;https://github.com/doctrine/doctrine2/tree/2.2/lib/Doctrine/ORM/Tools/Pagination&quot; class=&quot;external-link&quot;&gt;https://github.com/doctrine/doctrine2/tree/2.2/lib/Doctrine/ORM/Tools/Pagination&lt;/a&gt; and &lt;a href=&quot;https://github.com/doctrine/doctrine2/tree/2.2.2/lib/Doctrine/ORM/Tools/Pagination&quot; class=&quot;external-link&quot;&gt;https://github.com/doctrine/doctrine2/tree/2.2.2/lib/Doctrine/ORM/Tools/Pagination&lt;/a&gt; is the 2.2.2 tag.&lt;/p&gt;

&lt;p&gt;no LimitSubqueryOutputWalker.php in there.&lt;/p&gt;</comment>
                    <comment id="18577" author="beberlei" created="Wed, 29 Aug 2012 13:18:33 +0000"  >&lt;p&gt;Fixed&lt;/p&gt;</comment>
                    <comment id="19966" author="rkolbe" created="Tue, 9 Apr 2013 17:25:07 +0000"  >&lt;p&gt;This issue is popping it&apos;s head up again!&lt;/p&gt;

&lt;p&gt;Benjamin, your tests don&apos;t test for the ordering problem unless those tests are happening somewhere else?&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/doctrine/doctrine2/commit/f55b5411c8b1f75bf2b5cf5ffe4bc50034fb91cb&quot; class=&quot;external-link&quot;&gt;https://github.com/doctrine/doctrine2/commit/f55b5411c8b1f75bf2b5cf5ffe4bc50034fb91cb&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am performing a query as complex as Marc&apos;s and I experience the same exact issue. I have checked out today&apos;s latest master branch as well as the 2.3 tag with no change.&lt;/p&gt;

&lt;p&gt;Please advise.&lt;/p&gt;</comment>
                    <comment id="19968" author="rkolbe" created="Tue, 9 Apr 2013 20:03:37 +0000"  >&lt;p&gt;I have a PR in &lt;a href=&quot;https://github.com/doctrine/doctrine2/pull/645&quot; class=&quot;external-link&quot;&gt;https://github.com/doctrine/doctrine2/pull/645&lt;/a&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>