Opened 9 years ago

Closed 4 years ago

#11280 closed Cleanup/optimization (wontfix)

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: cmawebsite@… 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.

Change History (6)

comment:1 Changed 9 years ago by Alex Gaynor

Triage Stage: UnreviewedAccepted

comment:2 Changed 7 years ago by Julien Phalip

Severity: Normal
Type: Cleanup/optimization

comment:3 Changed 6 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 Changed 6 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 Changed 4 years ago by Collin Anderson

Cc: cmawebsite@… added

This select will likely become necessary for #6707

comment:6 Changed 4 years ago by Collin Anderson

Resolution: wontfix
Status: newclosed

To be clear: if we fix #6707 (which we should do), we shouldn't fix this ticket, so I think we should close in the meantime. Feel free to reopen if anyone thinks we should fix this anyway in the meantime.

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