Opened 3 years ago
Closed 3 years ago
#33493 closed Cleanup/optimization (wontfix)
It's counter-intuitive how QuerySet.iterate() works with prefetch_related
Reported by: | abetkin | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi django fellows!
I've stumbled upon this code in the main branch: (see screenshot)
The usecase is iterating through a queryset with prefetch_related lookups specified.
Do I understand correctly that multiple database queries happen upon fetching every chunk, and also that multiple database connections are required?
If so, than I think it would be better just to prohibit the use of prefetch_related with QuerySet.iterate
Attachments (1)
Change History (4)
by , 3 years ago
Attachment: | methods_that.png added |
---|
comment:1 by , 3 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Type: | Uncategorized → Bug |
comment:2 by , 3 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 3 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Type: | Bug → Cleanup/optimization |
Note:
See TracTickets
for help on using tickets.
Support for prefetching related objects with
QuerySet.iterator()
was added in edbf930287cb72e9afab1f7208c24b1146b0c4ec, and yes an extra query is necessary for each chunk, it's documented. You can check related discussions in the ticket #29984, on the mailing list, and in PR. I don't see any reason to remove this feature.