Opened 8 years ago

Closed 4 months ago

#24296 closed Cleanup/optimization (fixed)

clear select fields for `.exists()` of distinct, non-sliced querysets

Reported by: Martin Chase Owned by: Marcelo Galigniana
Component: Database layer (models, ORM) Version: 1.7
Severity: Normal Keywords:
Cc: 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

The fix (93cc6dcdac6fc3e506640fa38dd1798c3cd61cff) for bug #18414 introduced an inefficiency in .exists() on distinct querysets in that now all distinct querysets are selecting all their fields. I propose the fields should be left on the queryset only if (q.distinct and (q.high_mark is not None or q.low_mark is not None)).

As I started writing the test for this, I realized I would have to inspect the query itself, which seems... like a bad idea for a test. Would this be reasonable to submit the (one-line-change) patch without a test, or does someone have a suggestion for a way to make the test that's less brittle?

Change History (5)

comment:1 Changed 7 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

A test that inspects the query is likely fine. See if you can find an existing test that does something similar.

comment:2 Changed 4 months ago by Marcelo Galigniana

Owner: changed from nobody to Marcelo Galigniana
Status: newassigned

comment:3 Changed 4 months ago by Marcelo Galigniana

comment:4 Changed 4 months ago by Mariusz Felisiak

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:5 Changed 4 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 0ad5316f:

Fixed #24296 -- Made QuerySet.exists() clear selected columns for not sliced distinct querysets.

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