Opened 2 years ago

Closed 13 days ago

Last modified 13 days ago

#35596 closed Bug (fixed)

Database access optimization warning that get() can retrieve hundreds or thousands of records is outdated

Reported by: Francisco Couzo Owned by: Codequiver
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Francisco Couzo Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Second, the lookup doesn’t guarantee that only one object will be returned. If the query matches more than one object, it will retrieve and transfer all of them from the database. This penalty could be substantial if hundreds or thousands of records are returned. The penalty will be compounded if the database lives on a separate server, where network overhead and latency also play a factor.

This was modified 5 years ago in commit 330638b89f14e1fb06e9d313ccc9768ae167c53f

There is one specific case when get() can return all the result set, which is when using the oracle db and select_for_update

Change History (7)

comment:1 by Ripoohann S Kumar, 2 years ago

Owner: set to Ripoohann S Kumar
Status: newassigned

comment:2 by Sarah Boyce, 2 years ago

Summary: Database access optimization page has outdated infoDatabase access optimization warning that get() can retrieve hundreds or thousands of records is outdated
Triage Stage: UnreviewedAccepted

A docs link for reference: https://docs.djangoproject.com/en/5.0/topics/db/optimization/#retrieve-individual-objects-using-a-unique-indexed-column

Agreed an update here would be nice, thank you for the report 👍 refs #6785

comment:3 by Codequiver, 3 weeks ago

Owner: changed from Ripoohann S Kumar to Codequiver

comment:4 by Codequiver, 3 weeks ago

Has patch: set

comment:5 by Jacob Walls, 13 days ago

Triage Stage: AcceptedReady for checkin
Version: dev

comment:6 by Jacob Walls <jacobtylerwalls@…>, 13 days ago

Resolution: fixed
Status: assignedclosed

In 525e51f6:

Fixed #35596 -- Removed mention of unlimited results from QuerySet.get().

Obsolete since 330638b89f14e1fb06e9d313ccc9768ae167c53f.

comment:7 by Jacob Walls <jacobtylerwalls@…>, 13 days ago

In acbd510:

[6.1.x] Fixed #35596 -- Removed mention of unlimited results from QuerySet.get().

Obsolete since 330638b89f14e1fb06e9d313ccc9768ae167c53f.

Backport of 525e51f6ce7d77012b60a9bdbd098322f94bdd3f from main.

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