Condense ALTER TABLEs when possible.
Review Request #5190 — Created Jan. 3, 2014 and submitted
Condense
ALTER TABLEs when possible.When possible, multiple
ALTER TABLErules are now combined, resulting in
fewer table rebuilds. AdjacentADD COLUMN,MODIFY COLUMN, and
DELETE COLUMNoperations within a single batch of operations will be
condensed together.When processing operations,
AlterTableSQLResultwill take the various
Alter Table operations and put them into batches ofALTER TABLE
statements. Typically, all operations in a batch will be turned into one
statement, but an Alter Table entry can setindependent=Trueto ensure
it's part of its ownALTER TABLE, in the proper order.
generate_table_op_sqltakes the operations for a model and combines
their SQL into anAlterTableSQLResult. 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 TABLEstatements 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 TABLEstatements dropped by 3 (leaving 20 table-rebuilding
statements for 13 tables). Future changes should get this down to 13
for 13.