Commit d59420c8 authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 508186: Speed up UTF-8 table conversion in checksetup

Patch by Max Kanat-Alexander <mkanat@bugzilla.org> (module owner) a=mkanat
parent 5539de9f
...@@ -717,6 +717,7 @@ EOT ...@@ -717,6 +717,7 @@ EOT
foreach my $table ($self->bz_table_list_real) { foreach my $table ($self->bz_table_list_real) {
my $info_sth = $self->prepare("SHOW FULL COLUMNS FROM $table"); my $info_sth = $self->prepare("SHOW FULL COLUMNS FROM $table");
$info_sth->execute(); $info_sth->execute();
my (@binary_sql, @utf8_sql);
while (my $column = $info_sth->fetchrow_hashref) { while (my $column = $info_sth->fetchrow_hashref) {
# Our conversion code doesn't work on enum fields, but they # Our conversion code doesn't work on enum fields, but they
# all go away later in checksetup anyway. # all go away later in checksetup anyway.
...@@ -729,31 +730,13 @@ EOT ...@@ -729,31 +730,13 @@ EOT
{ {
my $name = $column->{Field}; my $name = $column->{Field};
# The code below doesn't work on a field with a FULLTEXT print "$table.$name needs to be converted to UTF-8...\n";
# index. So we drop it, which we'd do later anyway.
if ($table eq 'longdescs' && $name eq 'thetext') {
$self->bz_drop_index('longdescs',
'longdescs_thetext_idx');
}
if ($table eq 'bugs' && $name eq 'short_desc') {
$self->bz_drop_index('bugs', 'bugs_short_desc_idx');
}
my %ft_indexes;
if ($table eq 'bugs_fulltext') {
%ft_indexes = $self->_bz_real_schema->get_indexes_on_column_abstract(
'bugs_fulltext', $name);
foreach my $index (keys %ft_indexes) {
$self->bz_drop_index('bugs_fulltext', $index);
}
}
my $dropped = $self->bz_drop_related_fks($table, $name); my $dropped = $self->bz_drop_related_fks($table, $name);
push(@dropped_fks, @$dropped); push(@dropped_fks, @$dropped);
print "Converting $table.$name to be stored as UTF-8...\n";
my $col_info = my $col_info =
$self->bz_column_info_real($table, $name); $self->bz_column_info_real($table, $name);
# CHANGE COLUMN doesn't take PRIMARY KEY # CHANGE COLUMN doesn't take PRIMARY KEY
delete $col_info->{PRIMARYKEY}; delete $col_info->{PRIMARYKEY};
my $sql_def = $self->_bz_schema->get_type_ddl($col_info); my $sql_def = $self->_bz_schema->get_type_ddl($col_info);
...@@ -765,19 +748,32 @@ EOT ...@@ -765,19 +748,32 @@ EOT
# right after the type, which will always come first. # right after the type, which will always come first.
my ($binary, $utf8) = ($sql_def, $sql_def); my ($binary, $utf8) = ($sql_def, $sql_def);
my $type = $self->_bz_schema->convert_type($col_info->{TYPE}); my $type = $self->_bz_schema->convert_type($col_info->{TYPE});
$binary =~ s/(\Q$type\E)/$1 CHARACTER SET binary/; push(@binary_sql, "MODIFY COLUMN $name $binary");
$utf8 =~ s/(\Q$type\E)/$1 CHARACTER SET utf8/; push(@utf8_sql, "MODIFY COLUMN $name $utf8");
$self->do("ALTER TABLE $table CHANGE COLUMN $name $name }
$binary"); } # foreach column
$self->do("ALTER TABLE $table CHANGE COLUMN $name $name
$utf8");
if ($table eq 'bugs_fulltext') { if (@binary_sql) {
foreach my $index (keys %ft_indexes) { my %indexes = %{ $self->bz_table_indexes($table) };
$self->bz_add_index('bugs_fulltext', $index, foreach my $index_name (keys %indexes) {
$ft_indexes{$index}); my $index = $indexes{$index_name};
if ($index->{TYPE} and $index->{TYPE} eq 'FULLTEXT') {
$self->bz_drop_index($table, $index_name);
}
else {
delete $indexes{$index_name};
} }
} }
print "Converting the $table table to UTF-8...\n";
my $bin = "ALTER TABLE $table " . join(', ', @binary_sql);
my $utf = "ALTER TABLE $table " . join(', ', @utf8_sql);
$self->do($bin);
$self->do($utf);
# Re-add any removed FULLTEXT indexes.
foreach my $index (keys %indexes) {
$self->bz_add_index($table, $index, $indexes{$index});
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment