DDC-1656: fetch mode EXTRA_LAZY does not do a IN(1, 2, 3, ...) merge type query to fetch OneToMany results #2080

Closed
opened 2026-01-22 13:39:51 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 17, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user des.hymers:

Using the fetch mode EXTRA_LAZY does not produce a SQL query to fetch all OneToMany relationship results via a IN(1, 2, 3, ...) type merged query, instead it does one query per row in the result set.

First query to obtain all the pages

SELECT t0.page_id AS page_id1, t0.name AS name2, t0.text AS text3, t0.url AS url4, t0.revision_id AS revision_id5, t0.owner_id AS owner_id6, t0.is_active AS is_active7 FROM pages t0

then for each row in that result set

SELECT t0.attribute_id AS attribute_id1, t0.page_id AS page_id2, t0.key AS key3, t0.value AS value4, t0.page_id AS page_id5 FROM page_attributes t0 WHERE t0.page_id = ?

What is desired is a query like this,

SELECT t0.attribute_id AS attribute_id1, t0.page_id AS page_id2, t0.key AS key3, t0.value AS value4, t0.page_id AS page_id5 FROM page_attributes t0 WHERE t0.page_id IN(1, 2, 3, ...)

to obtain all the attributes for the pages, after the first original page query.

Originally created by @doctrinebot on GitHub (Feb 17, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user des.hymers: Using the fetch mode EXTRA_LAZY does not produce a SQL query to fetch all OneToMany relationship results via a IN(1, 2, 3, ...) type merged query, instead it does one query per row in the result set. First query to obtain all the pages SELECT t0.page_id AS page_id1, t0.name AS name2, t0.text AS text3, t0.url AS url4, t0.revision_id AS revision_id5, t0.owner_id AS owner_id6, t0.is_active AS is_active7 FROM pages t0 then for each row in that result set SELECT t0.attribute_id AS attribute_id1, t0.page_id AS page_id2, t0.key AS key3, t0.value AS value4, t0.page_id AS page_id5 FROM page_attributes t0 WHERE t0.page_id = ? What is desired is a query like this, SELECT t0.attribute_id AS attribute_id1, t0.page_id AS page_id2, t0.key AS key3, t0.value AS value4, t0.page_id AS page_id5 FROM page_attributes t0 WHERE t0.page_id IN(1, 2, 3, ...) to obtain all the attributes for the pages, after the first original page query.
admin added the Bug label 2026-01-22 13:39:51 +01:00
admin closed this issue 2026-01-22 13:39:53 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 17, 2012):

Comment created by des.hymers:

had a typo in the file I uploaded, corrected now

@doctrinebot commented on GitHub (Feb 17, 2012): Comment created by des.hymers: had a typo in the file I uploaded, corrected now
Author
Owner

@doctrinebot commented on GitHub (Feb 17, 2012):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Feb 17, 2012): Issue was closed with resolution "Invalid"
Author
Owner

@doctrinebot commented on GitHub (Feb 17, 2012):

Comment created by @asm89:

Closed as invalid, because this is the ORM working as intended. First all the PageEntity objects are loaded. Next there is a loop over all the objects, with an inner loop on the "attributes" association. These attributes are lazy loaded for each individual page, hence 1 query for all the pages and n queries for all the attributes of the pages.

@doctrinebot commented on GitHub (Feb 17, 2012): Comment created by @asm89: Closed as invalid, because this is the ORM working as intended. First all the PageEntity objects are loaded. Next there is a loop over all the objects, with an inner loop on the "attributes" association. These attributes are lazy loaded for each individual page, hence 1 query for all the pages and n queries for all the attributes of the pages.
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 2 attachments from Jira into https://gist.github.com/16d842e82e39d51e9e98

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 2 attachments from Jira into https://gist.github.com/16d842e82e39d51e9e98 - [11162_d2_bugreportcode.txt](https://gist.github.com/16d842e82e39d51e9e98#file-11162_d2_bugreportcode-txt) - [11163_d2_bugreportcode.txt](https://gist.github.com/16d842e82e39d51e9e98#file-11163_d2_bugreportcode-txt)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2080