DDC-1573: Simple relation hydratation not working properly #1975

Closed
opened 2026-01-22 13:35:06 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 29, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user jeremy.c:

    I'm not sure if i'm in the right place but i'm talking about this : https://github.com/doctrine/doctrine2

The following code trigger a lot more queries than it should and than it used to :

--- code ---

$qb = $em->createQueryBuilder()
->select('t, c, p')
->from('Task', 't')
->leftJoin('t.children', 'c')
->leftJoin('t.parent', 'p')
->orderBy('t.root, t.lft')
;

foreach( $qb->getQuery()->getResult() as $task)
{
$task->getChildren()->count();
}


edit: The code doesn't seems to be very nice in this editor, here is a pastbin version : http://pastebin.com/LCRfBCcV

With doctrine 2.1.2, only one query is needed.

Since doctrine 2.1.3, i almost have one query per loop iteration. It's the same with all next versions.

I'm using a NestedSet extension and Symfony 2.0.8, if i force doctrine version to 2.1.2 it works again with one query (with doctrine-common 2.1.4 and doctrine-dbal 2.1.5) so i think the problem is clearly introduced by doctrine itself (2.1.3).

I hope i was clear enough.

Originally created by @doctrinebot on GitHub (Dec 29, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user jeremy.c: ``` I'm not sure if i'm in the right place but i'm talking about this : https://github.com/doctrine/doctrine2 ``` The following code trigger a lot more queries than it should and than it used to : --- code --- $qb = $em->createQueryBuilder() ->select('t, c, p') ->from('Task', 't') ->leftJoin('t.children', 'c') ->leftJoin('t.parent', 'p') ->orderBy('t.root, t.lft') ; foreach( $qb->getQuery()->getResult() as $task) { $task->getChildren()->count(); } --- edit: The code doesn't seems to be very nice in this editor, here is a pastbin version : http://pastebin.com/LCRfBCcV With doctrine 2.1.2, only one query is needed. Since doctrine 2.1.3, i almost have one query per loop iteration. It's the same with all next versions. I'm using a NestedSet extension and Symfony 2.0.8, if i force doctrine version to 2.1.2 it works again with one query (with doctrine-common 2.1.4 and doctrine-dbal 2.1.5) so i think the problem is clearly introduced by doctrine itself (2.1.3). I hope i was clear enough.
admin added the Bug label 2026-01-22 13:35:06 +01:00
admin closed this issue 2026-01-22 13:35:11 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 29, 2011):

@doctrinebot commented on GitHub (Dec 29, 2011): - duplicates [DDC-1526: Unecessary queries with LEFT JOIN](http://www.doctrine-project.org/jira/browse/DDC-1526)
Author
Owner

@doctrinebot commented on GitHub (Dec 29, 2011):

Comment created by @beberlei:

Duplicate of DDC-1526

@doctrinebot commented on GitHub (Dec 29, 2011): Comment created by @beberlei: Duplicate of [DDC-1526](http://www.doctrine-project.org/jira/browse/DDC-1526)
Author
Owner

@doctrinebot commented on GitHub (Dec 29, 2011):

Issue was closed with resolution "Duplicate"

@doctrinebot commented on GitHub (Dec 29, 2011): Issue was closed with resolution "Duplicate"
Author
Owner

@doctrinebot commented on GitHub (Dec 29, 2011):

Comment created by @beberlei:

Can you disable the nested set extension? the other ticket uses it too and i want to rule out that its the extensions fault.

@doctrinebot commented on GitHub (Dec 29, 2011): Comment created by @beberlei: Can you disable the nested set extension? the other ticket uses it too and i want to rule out that its the extensions fault.
Author
Owner

@doctrinebot commented on GitHub (Dec 29, 2011):

Comment created by jeremy.c:

I just tried without the nested set extension but it still triggers the same amount of unecessary queries.

@doctrinebot commented on GitHub (Dec 29, 2011): Comment created by jeremy.c: I just tried without the nested set extension but it still triggers the same amount of unecessary queries.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1975