Opened 5 years ago

Last modified 5 years ago

#11280 new Cleanup/optimization

model.m2m = [pk, list] Performs unnecessary SELECT

Reported by: Zulq Alam <me@…> Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Normal Keywords: m2m, bulk
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When assigning a collection to an m2m relationship using a list of PKs an unnecessary SELECT is performed.

DELETE FROM model_m2m WHERE model_pk = %s
SELECT FROM model_m2m WHERE model_pk = %s AND m2m_pk IN (%s, %s, %s, ...)
INSERT INTO model_m2m (model_pk, m2m_pk) VALUES (%s, %s)
INSERT INTO model_m2m (model_pk, m2m_pk) VALUES (%s, %s)

The DELETE will remove any rows the SELECT might have found.

Attachments (0)

Change History (4)

comment:1 Changed 5 years ago by Alex

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

comment:2 Changed 3 years ago by julien

  • Severity set to Normal
  • Type set to Cleanup/optimization

comment:3 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

Add Comment

Modify Ticket

Change Properties
<Author field>
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.