1
0
Fork 0
mirror of synced 2025-03-29 19:29:53 +03:00

#1277 DDC-3346 DDC-3531 - skipping joining of associations when limiting and fetch-joining to-many eager associations

This commit is contained in:
Marco Pivetta 2015-01-23 15:54:48 +01:00
parent 67f60f2286
commit a37fa97be3
2 changed files with 24 additions and 8 deletions

View file

@ -204,11 +204,13 @@ class BasicEntityPersister implements EntityPersister
$this->identifierFlattener = new IdentifierFlattener($em->getUnitOfWork(), $em->getMetadataFactory()); $this->identifierFlattener = new IdentifierFlattener($em->getUnitOfWork(), $em->getMetadataFactory());
$this->cachedPersisterContexts['noLimits'] = $this->currentPersisterContext = new CachedPersisterContext( $this->cachedPersisterContexts['noLimits'] = $this->currentPersisterContext = new CachedPersisterContext(
$class, $class,
new Query\ResultSetMapping() new Query\ResultSetMapping(),
false
); );
$this->cachedPersisterContexts['withLimits'] = new CachedPersisterContext( $this->cachedPersisterContexts['withLimits'] = new CachedPersisterContext(
$class, $class,
new Query\ResultSetMapping() new Query\ResultSetMapping(),
true
); );
} }
@ -1169,11 +1171,9 @@ class BasicEntityPersister implements EntityPersister
* the resulting SQL fragment is generated only once and cached in {@link selectColumnListSql}. * the resulting SQL fragment is generated only once and cached in {@link selectColumnListSql}.
* Subclasses may or may not do the same. * Subclasses may or may not do the same.
* *
* @param bool $hasLimitClause
*
* @return string The SQL fragment. * @return string The SQL fragment.
*/ */
protected function getSelectColumnsSQL(/*$hasLimitClause = false*/) protected function getSelectColumnsSQL()
{ {
//if ( ! $hasLimitClause && $this->selectColumnListSql !== null) { //if ( ! $hasLimitClause && $this->selectColumnListSql !== null) {
if ($this->currentPersisterContext->selectColumnListSql !== null) { if ($this->currentPersisterContext->selectColumnListSql !== null) {
@ -1206,6 +1206,10 @@ class BasicEntityPersister implements EntityPersister
continue; continue;
} }
if ((($assoc['type'] & ClassMetadata::TO_MANY) > 0) && $this->currentPersisterContext->handlesLimits) {
continue;
}
$eagerEntity = $this->em->getClassMetadata($assoc['targetEntity']); $eagerEntity = $this->em->getClassMetadata($assoc['targetEntity']);
if ($eagerEntity->inheritanceType != ClassMetadata::INHERITANCE_TYPE_NONE) { if ($eagerEntity->inheritanceType != ClassMetadata::INHERITANCE_TYPE_NONE) {
@ -1955,6 +1959,8 @@ class BasicEntityPersister implements EntityPersister
{ {
if (null === $offset && null === $limit) { if (null === $offset && null === $limit) {
$this->currentPersisterContext = $this->cachedPersisterContexts['noLimits']; $this->currentPersisterContext = $this->cachedPersisterContexts['noLimits'];
return;
} }
$this->currentPersisterContext = $this->cachedPersisterContexts['withLimits']; $this->currentPersisterContext = $this->cachedPersisterContexts['withLimits'];

View file

@ -78,15 +78,25 @@ class CachedPersisterContext
*/ */
public $sqlTableAliases = array(); public $sqlTableAliases = array();
/**
* Whether this persistent context is considering limit operations applied to the selection queries
*
* @var bool
*/
public $handlesLimits;
/** /**
* @param ClassMetadata $class * @param ClassMetadata $class
* @param ResultSetMapping $rsm * @param ResultSetMapping $rsm
* @param bool $handlesLimits
*/ */
public function __construct( public function __construct(
ClassMetadata $class, ClassMetadata $class,
ResultSetMapping $rsm ResultSetMapping $rsm,
$handlesLimits
) { ) {
$this->class = $class; $this->class = $class;
$this->rsm = $rsm; $this->rsm = $rsm;
$this->handlesLimits = (bool) $handlesLimits;
} }
} }