DDC-2842: Leave out discriminator part of Doctrine' generated SQL #3548

Open
opened 2026-01-22 14:22:10 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 6, 2013).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user roelvd:

Assume the following AbstractPage model:

/*
 *     @ORM\Entity
 *     @ORM\Table(name="page")
 *     @ORM\InheritanceType("SINGLE_TABLE")
 *     @ORM\DiscriminatorColumn(name="type", type="string")
 *     @ORM\DiscriminatorMap
 *     ({
 *         "page" = "Page",
 *         "link" = "Link"
 *     })
 */

And the following DQL query:

SELECT p FROM \Page\Model\AbstractPage

The generated SQL will be:

SELECT ... FROM page p0* WHERE p0*.type IN ('page', 'link')

Now to the question: how can I remove the WHERE clause from this query. On more complex queries this part of the WHERE clause makes it not possible to use some indexes that are defined. This can be resolved by adding type to the indexes, but this makes my indexes larger and I feel this is not necessary.

The AbstractPage is the root in the inheritance tree. Thus we are interested in ALL records in the table. Omiting the WHERE part does precisely that.

So the question is: how can I make Doctrine remove this WHERE part where it is not necessary.

Originally created by @doctrinebot on GitHub (Dec 6, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user roelvd: Assume the following AbstractPage model: ``` /* * @ORM\Entity * @ORM\Table(name="page") * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="type", type="string") * @ORM\DiscriminatorMap * ({ * "page" = "Page", * "link" = "Link" * }) */ ``` And the following DQL query: ``` SELECT p FROM \Page\Model\AbstractPage ``` The generated SQL will be: ``` SELECT ... FROM page p0* WHERE p0*.type IN ('page', 'link') ``` Now to the question: how can I remove the WHERE clause from this query. On more complex queries this part of the WHERE clause makes it not possible to use some indexes that are defined. This can be resolved by adding type to the indexes, but this makes my indexes larger and I feel this is not necessary. The AbstractPage is the root in the inheritance tree. Thus we are interested in ALL records in the table. Omiting the WHERE part does precisely that. So the question is: how can I make Doctrine remove this WHERE part where it is not necessary.
admin added the Improvement label 2026-01-22 14:22:10 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3548