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

Closed
doctrinebot opened this Issue Aug 7, 2010 · 4 comments

2 participants

@doctrinebot

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();
@doctrinebot

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

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by @guilhermeblanco:

Closed

@doctrinebot

Comment created by koc:

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

@doctrinebot doctrinebot added this to the 2.1 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment