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)

methods_that.png (41.1 KB ) - added by abetkin 3 years ago.

Download all attachments as: .zip

Change History (4)

by abetkin, 3 years ago

Attachment: methods_that.png added

comment:1 by abetkin, 3 years ago

Component: UncategorizedDatabase layer (models, ORM)
Type: UncategorizedBug

comment:2 by abetkin, 3 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Mariusz Felisiak, 3 years ago

Resolution: wontfix
Status: newclosed
Type: BugCleanup/optimization

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.

Note: See TracTickets for help on using tickets.
Back to Top