Opened 3 years ago

Closed 18 months ago

Last modified 18 months ago

#16895 closed Cleanup/optimization (fixed)

documentation should warn of cost of ordering

Reported by: outofculture@… Owned by: e0ne
Component: Documentation Version:
Severity: Normal Keywords: afraid-to-commit
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In https://docs.djangoproject.com/en/dev/ref/models/options/#ordering it makes no mention of the database cost of ordering, especially for ordering on non-indexed fields, or the implicit joins of chained orderings. (It doesn't even mention that it chains orderings!) https://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by is another location where the cost might be mentioned. It could additionally go in https://docs.djangoproject.com/en/dev/topics/db/optimization/#don-t-retrieve-things-you-don-t-need as a hint for things to look for when optimizing.

Recommend for model options and querysets pages: "Warning: Ordering is not a free operation. Each field you add to the ordering will incur a cost from your database. Each foreign key you add will include all of its default orderings implicitly."

Recommend for optimization page: "==Don't order if you don't care== Ordering is not free; each field added is an operation the database has to perform."

Change History (7)

comment:1 Changed 3 years ago by ptone

  • Needs documentation set
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

I think the mention in the optimization docs has priority - but there should be some caution about the risk of having too many performance warnings in the API docs

comment:2 Changed 18 months ago by EvilDMP

  • Keywords afraid-to-commit added

comment:3 Changed 18 months ago by e0ne

  • Has patch set
  • Owner changed from nobody to e0ne
  • Status changed from new to assigned

Here is pull request with patch https://github.com/django/django/pull/1603

comment:4 Changed 18 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In cbf08c6b0ca39406cada4bd1ffc6d334a79822e8:

Fixed #16895 -- Warned about cost of QuerySet ordering

Thanks outofculture at gmail.com for the suggestion.

comment:5 Changed 18 months ago by Tim Graham <timograham@…>

In 276e053803c847ce645b1859a162a997a4ee3789:

[1.6.x] Fixed #16895 -- Warned about cost of QuerySet ordering

Thanks outofculture at gmail.com for the suggestion.

Backport of cbf08c6b0c from master

comment:6 Changed 18 months ago by Tim Graham <timograham@…>

In fb51c9a0f262eae0ebb36ba1067dc0a4db314401:

Fixed spelling; refs #16895.

Thanks Panagiotis Issaris for the report.

comment:7 Changed 18 months ago by Tim Graham <timograham@…>

In 01ad5085148bf7dcfc3af4d05cc8c262680f85d9:

[1.6.x] Fixed spelling; refs #16895.

Thanks Panagiotis Issaris for the report.

Backport of fb51c9a0f2 from master

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