Condense ALTER TABLEs when possible.

Review Request #5190 — Created Jan. 3, 2014 and submitted

Information

Django Evolution
master

Reviewers

Condense ALTER TABLEs when possible.

When possible, multiple ALTER TABLE rules are now combined, resulting in
fewer table rebuilds. Adjacent ADD COLUMN, MODIFY COLUMN, and
DELETE COLUMN operations within a single batch of operations will be
condensed together.

When processing operations, AlterTableSQLResult will take the various
Alter Table operations and put them into batches of ALTER TABLE
statements. Typically, all operations in a batch will be turned into one
statement, but an Alter Table entry can set independent=True to ensure
it's part of its own ALTER TABLE, in the proper order.

generate_table_op_sql takes the operations for a model and combines
their SQL into an AlterTableSQLResult. If there are multiple adjacent
operations in a row that can be merged together (add_column,
change_column, delete_column), they'll be placed into the same
AlterTableSQLResult.

The result is a fairly compact list of ALTER TABLE statements that
trigger table rebuilds. It's still dependent on the ordering of
mutations, though.

Unit tests pass for all databases.

Checked SQL output for an RB 1.7.x to 2.0 upgrade. The number of
ALTER TABLE statements dropped by 3 (leaving 20 table-rebuilding
statements for 13 tables). Future changes should get this down to 13
for 13.

david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Loading...