#34534 closed Cleanup/optimization (fixed)

Reduce index/constraints operations.

Reported by: David Sanders Owned by: bcail
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: bcail 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 (last modified by Mariusz Felisiak)

From https://github.com/django/django/pull/16819#issuecomment-1529913703

  • RenameIndex can be reduced into AddIndex
  • DropConstraint can be reduced with AddConstraint
  • A question was raised whether constraints could be reduced into create model though some databases do not support deferrable constraints (eg MySQL)
  • It's worth going over the operations to see if there are any other potential reductions to add

Change History (19)

comment:1 by Mariusz Felisiak, 19 months ago

Component: Database layer (models, ORM)Migrations
Easy pickings: unset
Summary: Migration operation optimisationsReduce index/constraints operations.
Triage Stage: UnreviewedAccepted

Thanks for the ticket.

  • It's worth going over the operations to see if there are any other potential reductions to add

This point it too generic. Please open a new ticket when you will find something more. We don't want to keep this ticket to be open forever.

comment:2 by Mariusz Felisiak, 19 months ago

Description: modified (diff)

comment:3 by Akash Kumar Sen, 19 months ago

Owner: changed from nobody to Akash Kumar Sen
Status: newassigned

comment:4 by David Sanders, 19 months ago

Hi Akash,

Please see this PR for context & "prior art": https://github.com/django/django/pull/16819 👍

Version 0, edited 19 months ago by David Sanders (next)

comment:5 by David Sanders, 19 months ago

Has patch: set
Patch needs improvement: set

comment:6 by Akash Kumar Sen, 19 months ago

Thanks for the review David. Updated the patch accordingly.

comment:7 by Mariusz Felisiak, 19 months ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 19 months ago

In 92f0017:

Refs #34534 -- Reduced Add/RemoveConstraint and Add/RenameIndex operations when optimizing migrations.

comment:9 by Mariusz Felisiak, 19 months ago

Has patch: unset
Triage Stage: Ready for checkinAccepted

comment:10 by Mariusz Felisiak, 18 months ago

Owner: Akash Kumar Sen removed
Status: assignednew

comment:11 by Adam Johnson, 18 months ago

Thank you for reporting this David, making the PR Akash, and reviewing Mariusz. 👏

I was just looking at a migration with consecutive add + remove operations for the same constraints, wondering why they weren't optimized. Glad to see they will be in the future.

comment:12 by bcail, 10 months ago

Cc: bcail added

Should this ticket be closed, or is there something else that's supposed to be done here?

in reply to:  12 comment:13 by Mariusz Felisiak, 10 months ago

Replying to bcail:

Should this ticket be closed, or is there something else that's supposed to be done here?

Two points remain unresolved:

  • A question was raised whether constraints could be reduced into create model though some databases do not support deferrable constraints (eg MySQL)
  • It's worth going over the operations to see if there are any other potential reductions to add

comment:14 by bcail, 10 months ago

A question was raised whether constraints could be reduced into create model though some databases do not support deferrable constraints (eg MySQL)

I opened a PR for this part. Is that on the right track?

comment:15 by bcail, 10 months ago

Has patch: set

comment:16 by bcail, 10 months ago

Owner: set to bcail
Status: newassigned

comment:17 by Mariusz Felisiak, 10 months ago

Triage Stage: AcceptedReady for checkin

comment:18 by Mariusz Felisiak <felisiak.mariusz@…>, 10 months ago

In 8b7ddd1:

Refs #34534 -- Reduced constraint operations with Meta.constraints when optimizing migrations.

comment:19 by Mariusz Felisiak, 10 months ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.
Back to Top