Details

    • Type: Sub-task Sub-task
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      For performance reasons (solving the N+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+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();
      

        Activity

        Hide
        Benjamin Eberlei added a comment -

        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.

        Show
        Benjamin Eberlei added a comment - 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.
        Hide
        Guilherme Blanco added a comment -

        Closed

        Show
        Guilherme Blanco added a comment - Closed
        Hide
        Konstantin added a comment -

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

        Show
        Konstantin added a comment - I cann't find commit/branch where it was fixed

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Benjamin Eberlei
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: