DDC-734: Possibility to fetch all outstanding proxies of an Entity #902

Closed
opened 2026-01-22 12:54:48 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Aug 7, 2010).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user @beberlei:

For performance reasons (solving the N1 problem) it might be necessary to load all proxy instances of a given type:

$orders = $em->getRepository('Order')->findAll();
foreach ($orders AS $order) {
   $order->getCustomer()->getId(); // n</ins>1
}

However say we could do something like:

$orders = $em->getRepository('Order')->findAll();
$em->getUnitOfWork()->loadProxies("Customer");

foreach ($orders AS $order) {
   $order->getCustomer()->getId(); // n+1
}

This doesnt make too much sense in this case because we could use a fetch join with DQL. However you easily get to the point where you have a query like:

SELECT b, e, r, p FROM Bug b JOIN b.engineer e 
JOIN b.reporter r JOIN b.products p ORDER BY b.created DESC

In this case the SQL generated is VERY huge and just the number of joins could cause an performance overhead. In general its better to keep the number of joins as small as possible, a solution here would optimize for the engineer and reporter being both instances of User:

$bugs = $em->createQuery("SELECT b, p FROM Bug b JOIN b.products p ORDER BY b.created DESC")->getResult();
$em->getUnitOfWork()->loadProxies("User"); // will load all engineers and reporters in one query

We could even make this nicer for using Queries:

$bugs = $em->createQuery("SELECT b, p FROM Bug b JOIN b.products p ORDER BY b.created DESC")
                        ->setQueryHint(Query::LOAD_PROXIES, array("User"))
                        ->getResult();
Originally created by @doctrinebot on GitHub (Aug 7, 2010). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user @beberlei: For performance reasons (solving the N<ins>1 problem) it might be necessary to load all proxy instances of a given type: ``` $orders = $em->getRepository('Order')->findAll(); foreach ($orders AS $order) { $order->getCustomer()->getId(); // n</ins>1 } ``` However say we could do something like: ``` $orders = $em->getRepository('Order')->findAll(); $em->getUnitOfWork()->loadProxies("Customer"); foreach ($orders AS $order) { $order->getCustomer()->getId(); // n+1 } ``` This doesnt make too much sense in this case because we could use a fetch join with DQL. However you easily get to the point where you have a query like: ``` SELECT b, e, r, p FROM Bug b JOIN b.engineer e JOIN b.reporter r JOIN b.products p ORDER BY b.created DESC ``` In this case the SQL generated is VERY huge and just the number of joins could cause an performance overhead. In general its better to keep the number of joins as small as possible, a solution here would optimize for the engineer and reporter being both instances of User: ``` $bugs = $em->createQuery("SELECT b, p FROM Bug b JOIN b.products p ORDER BY b.created DESC")->getResult(); $em->getUnitOfWork()->loadProxies("User"); // will load all engineers and reporters in one query ``` We could even make this nicer for using Queries: ``` $bugs = $em->createQuery("SELECT b, p FROM Bug b JOIN b.products p ORDER BY b.created DESC") ->setQueryHint(Query::LOAD_PROXIES, array("User")) ->getResult(); ```
admin closed this issue 2026-01-22 12:54:49 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 16, 2011):

Comment created by @beberlei:

Implemented, but in another semantical way. Batching of eager loads of FETCH=EAGER associations aswell as AbstactQuery::setFetchMode($className, $assocName, $fetchMode) function to set this case-by-case for DQL.

@doctrinebot commented on GitHub (Mar 16, 2011): Comment created by @beberlei: Implemented, but in another semantical way. Batching of eager loads of FETCH=EAGER associations aswell as AbstactQuery::setFetchMode($className, $assocName, $fetchMode) function to set this case-by-case for DQL.
Author
Owner

@doctrinebot commented on GitHub (Mar 16, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Mar 16, 2011): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Jul 30, 2013):

Comment created by @guilhermeblanco:

Closed

@doctrinebot commented on GitHub (Jul 30, 2013): Comment created by @guilhermeblanco: Closed
Author
Owner

@doctrinebot commented on GitHub (Jul 30, 2013):

Comment created by koc:

I cann't find commit/branch where it was fixed

@doctrinebot commented on GitHub (Jul 30, 2013): Comment created by koc: I cann't find commit/branch where it was fixed
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#902