summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2009-08-03 16:44:00 +0200
committermkanat%bugzilla.org <>2009-08-03 16:44:00 +0200
commit4d94e4169a9aeb1f2ccde25b2c7debffe6f82cbe (patch)
treed4e4217a35a16263f242940716391ef086d28ac0 /Bugzilla/DB
parent6f4d125ade02836e24101a1e8a4ae40920d176ac (diff)
downloadbugzilla-4d94e4169a9aeb1f2ccde25b2c7debffe6f82cbe.tar.gz
bugzilla-4d94e4169a9aeb1f2ccde25b2c7debffe6f82cbe.tar.xz
Bug 508023: Speed up MySQL's bz_alter_column for when we're just adding or removing a DEFAULT
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> (module owner) a=mkanat
Diffstat (limited to 'Bugzilla/DB')
-rw-r--r--Bugzilla/DB/Schema/Mysql.pm24
1 files changed, 22 insertions, 2 deletions
diff --git a/Bugzilla/DB/Schema/Mysql.pm b/Bugzilla/DB/Schema/Mysql.pm
index 627716970..49e6add1a 100644
--- a/Bugzilla/DB/Schema/Mysql.pm
+++ b/Bugzilla/DB/Schema/Mysql.pm
@@ -178,13 +178,33 @@ sub get_alter_column_ddl {
delete $new_def_copy{PRIMARYKEY};
}
- my $new_ddl = $self->get_type_ddl(\%new_def_copy);
my @statements;
push(@statements, "UPDATE $table SET $column = $set_nulls_to
WHERE $column IS NULL") if defined $set_nulls_to;
- push(@statements, "ALTER TABLE $table CHANGE COLUMN
+
+ # Calling SET DEFAULT or DROP DEFAULT is *way* faster than calling
+ # CHANGE COLUMN, so just do that if we're just changing the default.
+ my %old_defaultless = %$old_def;
+ my %new_defaultless = %$new_def;
+ delete $old_defaultless{DEFAULT};
+ delete $new_defaultless{DEFAULT};
+ if ($self->columns_equal(\%new_defaultless, \%old_defaultless)) {
+ if (defined $old_def->{DEFAULT} and !defined $new_def->{DEFAULT}) {
+ push(@statements,
+ "ALTER TABLE $table ALTER COLUMN $column DROP DEFAULT");
+ }
+ else {
+ push(@statements, "ALTER TABLE $table ALTER COLUMN $column
+ SET DEFAULT " . $new_def->{DEFAULT});
+ }
+ }
+ else {
+ my $new_ddl = $self->get_type_ddl(\%new_def_copy);
+ push(@statements, "ALTER TABLE $table CHANGE COLUMN
$column $column $new_ddl");
+ }
+
if ($old_def->{PRIMARYKEY} && !$new_def->{PRIMARYKEY}) {
# Dropping a PRIMARY KEY needs an explicit DROP PRIMARY KEY
push(@statements, "ALTER TABLE $table DROP PRIMARY KEY");