[Django] #24363: Combine ALTER TABLE .. MODIFY statements for multiple columns into one statement.

89 views
Skip to first unread message

Django

unread,
Feb 18, 2015, 9:09:48 AM2/18/15
to django-...@googlegroups.com
#24363: Combine ALTER TABLE .. MODIFY statements for multiple columns into one
statement.
-------------------------------+---------------------------------
Reporter: slachinger | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Keywords: Modify Field Column
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------
If a migration modifies multiple columns of a table for each column/field
an ALTER TABLE statement is executed. However most DBMS (all but sqlite?)
support modification of several columns at once.

For example, the consider this migration:
{{{
#!div style="font-size: 80%"
{{{#!python
class Migration(migrations.Migration):

dependencies = [
('core', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='employee',
name='salary',
field=models.BigIntegerField(),
preserve_default=True,
),
migrations.AlterField(
model_name='employee',
name='academic_degrees',
field=models.CharField(max_length=200),
preserve_default=True,
),
]
}}}
}}}

This currently results in two ALTER TABLE statments being executed:
{{{
#!div style="font-size: 80%"
{{{#!sql

ALTER TABLE employee MODIFY COLUMN salary bigint;
ALTER TABLE employee MODIFY COLUMN academic_degrees varchar(200);
}}}
}}}

But this takes twice as long as using only one ALTER TABLE statement since
the whole table is essentially recreated twice (at least in MySQL but IIRC
it is the same in PG):
{{{
#!div style="font-size: 80%"
{{{#!sql
ALTER TABLE employee MODIFY COLUMN salary bigint, MODIFY COLUMN
academic_degrees varchar(200);
}}}
}}}

This is particulary annoying because it essentially multiplies the time
the migration runs by the number of modified fields and thus causes much
longer downtimes of the service.

NOTE: this is most likely related to #24203 which refers to adding columns
instead of modifying.

--
Ticket URL: <https://code.djangoproject.com/ticket/24363>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 2, 2015, 1:43:47 PM3/2/15
to django-...@googlegroups.com
#24363: Combine ALTER TABLE .. MODIFY statements for multiple columns into one
statement.
-------------------------------------+-------------------------------------
Reporter: slachinger | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:

Keywords: Modify Field Column | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_docs: => 0
* needs_better_patch: => 0
* type: Uncategorized => New feature
* needs_tests: => 0
* stage: Unreviewed => Someday/Maybe


Comment:

As I said in #24203, some performance numbers would be useful to assess
the benefits of this versus the cost of additional code complexity.

--
Ticket URL: <https://code.djangoproject.com/ticket/24363#comment:1>

Django

unread,
Jun 10, 2015, 9:17:48 AM6/10/15
to django-...@googlegroups.com
#24363: Combine ALTER TABLE .. MODIFY statements for multiple columns into one
statement.
-------------------------------------+-------------------------------------
Reporter: slachinger | Owner:
| ambivalentno
Type: New feature | Status: assigned
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:

Keywords: Modify Field Column | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by ambivalentno):

* owner: nobody => ambivalentno
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/24363#comment:2>

Django

unread,
Jan 24, 2017, 10:23:58 AM1/24/17
to django-...@googlegroups.com
#24363: Combine ALTER TABLE .. MODIFY statements for multiple columns into one
statement.
-------------------------------------+-------------------------------------
Reporter: slachinger | Owner:
| ambivalentno
Type: New feature | Status: assigned
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:

Keywords: Modify Field Column | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ed Morley):

* cc: emorley@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/24363#comment:3>

Django

unread,
Oct 22, 2019, 12:45:26 PM10/22/19
to django-...@googlegroups.com
#24363: Combine ALTER TABLE .. MODIFY statements for multiple columns into one
statement.
-------------------------------------+-------------------------------------
Reporter: slachinger | Owner:
| ambivalentno
Type: New feature | Status: assigned
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:

Keywords: Modify Field Column | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Phil Krylov):

* cc: Phil Krylov (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/24363#comment:4>

Django

unread,
Apr 9, 2020, 5:00:59 PM4/9/20
to django-...@googlegroups.com
#24363: Combine ALTER TABLE .. MODIFY statements for multiple columns into one
statement.
-------------------------------------+-------------------------------------
Reporter: slachinger | Owner:
| ambivalentno
Type: New feature | Status: assigned
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:

Keywords: Modify Field Column | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam (Chainz) Johnson):

* cc: Adam (Chainz) Johnson (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/24363#comment:5>

Django

unread,
Aug 10, 2022, 1:13:29 PM8/10/22
to django-...@googlegroups.com
#24363: Combine ALTER TABLE .. MODIFY statements for multiple columns into one
statement.
-------------------------------------+-------------------------------------
Reporter: slachinger | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:

Keywords: Modify Field Column | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by elonzh):

* cc: elonzh (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/24363#comment:6>

Django

unread,
Jan 31, 2023, 2:22:44 PM1/31/23
to django-...@googlegroups.com
#24363: Combine ALTER TABLE .. MODIFY statements for multiple columns into one
statement.
-------------------------------------+-------------------------------------
Reporter: slachinger | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:

Keywords: Modify Field Column | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by elonzh):

* cc: elonzh (removed)


--
Ticket URL: <https://code.djangoproject.com/ticket/24363#comment:7>

Django

unread,
Jan 31, 2023, 2:23:57 PM1/31/23
to django-...@googlegroups.com
#24363: Combine ALTER TABLE .. MODIFY statements for multiple columns into one
statement.
-------------------------------------+-------------------------------------
Reporter: slachinger | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:

Keywords: Modify Field Column | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by elonzh):

* cc: elonzh (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/24363#comment:8>

Reply all
Reply to author
Forward
0 new messages