<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Wed Jun 19 19:56:56 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-821/DDC-821.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-821] Consider adding Query-Join as another join method for DQL</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-821</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;Some ORM systems support an alternative to fetch-join queries, called a &quot;query-join&quot;.  See &lt;a href=&quot;http://www.avaje.org/ebean/introquery_joinquery.html&quot; class=&quot;external-link&quot;&gt;http://www.avaje.org/ebean/introquery_joinquery.html&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A query-join accomplishes the same as a fetch-join (hydrating a larger object graph across all associations types) but executes more than one SQL query in sequence in order to hydrate the requested portions of the graph in a result set.  The first query retrieves data from the base entity/table and the next queries retrieve the data for the requested associations.&lt;/p&gt;

&lt;p&gt;In some cases this approach is more efficient to a fetch-join:&lt;/p&gt;

&lt;p&gt;(1) &lt;b&gt;No data duplication in the SQL result&lt;/b&gt; as occurs in a fetch-join on to-many associations.  Instead, this data is loaded through a second query.  This saves network traffic, memory and general overhead in hydrating the returned results.  In the case where large TEXT data is included in result sets, the savings here may be substantial.&lt;/p&gt;

&lt;p&gt;(2) &lt;b&gt;setFirstResult() and setMaxResult() are again effective (for pagination)&lt;/b&gt; and more importantly more efficient on these query-joins.  The current DoctrineExtension solution to enable pagination on fetch-joins requires a series of queries to determine the target primary keys of the root entity of the query.  The primary key lookup query requires DISTINCT or GROUP BY &amp;#8211; which often triggers filesorts, temporary tables, etc (at least on MySQL) and greatly slows down the query.  Query joins would not require this. &lt;/p&gt;

&lt;p&gt;Possible implementation example:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
&lt;span class=&quot;code-comment&quot;&gt;// existing fetch-join
&lt;/span&gt;$query = $em-&amp;gt;createQuery(&apos;SELECT c, o FROM Customers c JOIN c.orders o&apos;);
$query-&amp;gt;setFirstResult(10)-&amp;gt;setMaxResult(20); &lt;span class=&quot;code-comment&quot;&gt;// doesn&apos;t &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; what you&apos;d hope it would &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt;, no ability to use &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; pagination
&lt;/span&gt;$customersAndOrders = $query-&amp;gt;getResult(); &lt;span class=&quot;code-comment&quot;&gt;// array of Customer objects with Orders hydrated
&lt;/span&gt;
&lt;span class=&quot;code-comment&quot;&gt;// proposed query-join
&lt;/span&gt;$query = $em-&amp;gt;createQuery(&apos;SELECT c, o FROM Customers c QUERY JOIN c.orders o&apos;);
$query-&amp;gt;setFirstResult(10)-&amp;gt;setMaxResult(20); &lt;span class=&quot;code-comment&quot;&gt;// now works &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; pagination
&lt;/span&gt;$customersAndOrders = $query-&amp;gt;getResult(); &lt;span class=&quot;code-comment&quot;&gt;// array of Customer objects with Orders hyrdated
&lt;/span&gt;&lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; would execute a series of queries -- i.e. in SQL
&lt;/span&gt;&lt;span class=&quot;code-comment&quot;&gt;// SELECT ... FROM customers LIMIT 10, 20
&lt;/span&gt;&lt;span class=&quot;code-comment&quot;&gt;// SELECT ... FROM orders WHERE customer_id IN (.....)&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and/or,  could there be a way to trigger a &quot;query-join&quot; against an existing array of entities?  for example&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;$query = $em-&amp;gt;createQuery(&apos;SELECT c FROM Customers c&apos;); &lt;span class=&quot;code-comment&quot;&gt;// single query to fetch customers
&lt;/span&gt;$customers = $query-&amp;gt;getResult(); &lt;span class=&quot;code-comment&quot;&gt;// array of Customer objects
&lt;/span&gt;$em-&amp;gt;join($customers, &apos;orders&apos;); &lt;span class=&quot;code-comment&quot;&gt;// fetch and hydrate the &apos;orders&apos; association on each Customer using a single query&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Perhaps at some point in the future Doctrine/DBAL could even make use of asynchronous queries (i.e. mysqlnd supports this) to allow these query-joins to run in parallel and the result would be more efficient paginated resultsets.&lt;/p&gt;

&lt;p&gt;Thoughts/feedback?&lt;/p&gt;</description>
                <environment></environment>
            <key id="11962">DDC-821</key>
            <summary>Consider adding Query-Join as another join method for DQL</summary>
                <type id="2" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/newfeature.png">New Feature</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/open.png">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                    <security id="10000">All</security>
                        <assignee username="romanb">Roman S. Borschel</assignee>
                                <reporter username="mjh_ca">Marc Hodgins</reporter>
                        <labels>
                    </labels>
                <created>Wed, 29 Sep 2010 15:14:23 +0000</created>
                <updated>Wed, 29 Dec 2010 00:49:46 +0000</updated>
                                                    <fixVersion>2.x</fixVersion>
                                <component>ORM</component>
                        <due></due>
                    <votes>2</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="14494" author="beberlei" created="Thu, 30 Sep 2010 03:50:53 +0000"  >&lt;p&gt;There is another approach for this using several subqueries to build an IN clause, the Paginator extension supports this: &lt;a href=&quot;http://github.com/beberlei/DoctrineExtensions&quot; class=&quot;external-link&quot;&gt;http://github.com/beberlei/DoctrineExtensions&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I rather go the extension approach than changing the DQL for this feature.&lt;/p&gt;</comment>
                    <comment id="14497" author="beberlei" created="Thu, 30 Sep 2010 04:31:13 +0000"  >&lt;p&gt;I just saw your second example, that is rather cool though and gets +1 from me.&lt;/p&gt;

&lt;p&gt;I had the same idea for &quot;not initialized proxies&quot;, i.e.&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;$em-&amp;gt;getUnitOfWork()-&amp;gt;initializeProxies(&apos;Customer&apos;);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="15051" author="mjh_ca" created="Wed, 29 Dec 2010 00:49:46 +0000"  >&lt;p&gt;Second example is a duplicate of &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-734&quot; title=&quot;Possibility to fetch all outstanding proxies of an Entity&quot;&gt;&lt;del&gt;DDC-734&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>