mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-821: Consider adding Query-Join as another join method for DQL #1011
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Sep 29, 2010).
Originally assigned to: @guilhermeblanco on GitHub.
Jira issue originally created by user mjh_ca:
Some ORM systems support an alternative to fetch-join queries, called a "query-join". See [http://www.avaje.org/ebean/introquery_joinquery.html].
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.
In some cases this approach is more efficient to a fetch-join:
(1) No data duplication in the SQL result 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.
(2) setFirstResult() and setMaxResult() are again effective (for pagination) 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 -- which often triggers filesorts, temporary tables, etc (at least on MySQL) and greatly slows down the query. Query joins would not require this.
Possible implementation example:
and/or, could there be a way to trigger a "query-join" against an existing array of entities? for example
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.
Thoughts/feedback?
@doctrinebot commented on GitHub (Sep 30, 2010):
Comment created by @beberlei:
There is another approach for this using several subqueries to build an IN clause, the Paginator extension supports this: http://github.com/beberlei/DoctrineExtensions
I rather go the extension approach than changing the DQL for this feature.
@doctrinebot commented on GitHub (Sep 30, 2010):
Comment created by @beberlei:
I just saw your second example, that is rather cool though and gets +1 from me.
I had the same idea for "not initialized proxies", i.e.
@doctrinebot commented on GitHub (Dec 29, 2010):
Comment created by mjh_ca:
Second example is a duplicate of DDC-734
@doctrinebot commented on GitHub (Jul 30, 2013):
Comment created by @guilhermeblanco:
Fixed based on this related issue: http://www.doctrine-project.org/jira/browse/DDC-734
@doctrinebot commented on GitHub (Jul 30, 2013):
Issue was closed with resolution "Fixed"