DDC-1234: With class table inheritance, SqlWalker always joins subclass tables even when they are not used #1552

Closed
opened 2026-01-22 13:17:46 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 27, 2011).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user pschwisow:

When using class table inheritance, it is not possible to avoid joining subclass tables even if they are not needed. For example, when selecting only scalar fields of the parent class and using array hydration.

Classes:

/****
 * @Entity
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"employee" = "Employee", "customer" = "Customer"})
 */
class Person
{
    ...
    /*** @Column(name="name", type="string") **/
    protected $name;
    ...
}

/*** @Entity **/
class Employee extends Person
{
    ...
}

Test code:

$entityManager->createQueryBuilder()->select('p.name')->from('Person', 'p')->getQuery()->getArrayResult();

The generated SQL includes 'employee' table even though it is not used.

Originally created by @doctrinebot on GitHub (Jun 27, 2011). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user pschwisow: When using class table inheritance, it is not possible to avoid joining subclass tables even if they are not needed. For example, when selecting only scalar fields of the parent class and using array hydration. Classes: ``` /**** * @Entity * @InheritanceType("JOINED") * @DiscriminatorColumn(name="discr", type="string") * @DiscriminatorMap({"employee" = "Employee", "customer" = "Customer"}) */ class Person { ... /*** @Column(name="name", type="string") **/ protected $name; ... } /*** @Entity **/ class Employee extends Person { ... } ``` Test code: ``` $entityManager->createQueryBuilder()->select('p.name')->from('Person', 'p')->getQuery()->getArrayResult(); ``` The generated SQL includes 'employee' table even though it is not used.
admin added the Improvement label 2026-01-22 13:17:46 +01:00
admin closed this issue 2026-01-22 13:17:46 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 28, 2011):

Comment created by @beberlei:

A change that detects this would be considered an improvement, the functionality works, its just not very efficient in this case.

I doubt there is a simple and good way to implement this though, i assign this to Guilherme for evaluation.

@doctrinebot commented on GitHub (Jun 28, 2011): Comment created by @beberlei: A change that detects this would be considered an improvement, the functionality works, its just not very efficient in this case. I doubt there is a simple and good way to implement this though, i assign this to Guilherme for evaluation.
Author
Owner

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

Comment created by @guilhermeblanco:

That would require almost a complete rewrite of DQL parser to be able to be done.
An alternative would be a 2-step parser, but it would slowdown the performance of DQL => SQL translation so much that I consider it's better to mark as can't fix.

@doctrinebot commented on GitHub (Oct 16, 2011): Comment created by @guilhermeblanco: That would require almost a complete rewrite of DQL parser to be able to be done. An alternative would be a 2-step parser, but it would slowdown the performance of DQL => SQL translation so much that I consider it's better to mark as can't fix.
Author
Owner

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

Issue was closed with resolution "Can't Fix"

@doctrinebot commented on GitHub (Oct 16, 2011): Issue was closed with resolution "Can't Fix"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1552