Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
bugzilla
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
bugzilla
Commits
620f4ea2
Commit
620f4ea2
authored
May 17, 2005
by
mkanat%kerio.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug 290677: Index rename time estimate is too short on large sites
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=jouni, a=justdave
parent
7dc732e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
10 deletions
+43
-10
Mysql.pm
Bugzilla/DB/Mysql.pm
+19
-10
Mysql.pm
Bugzilla/DB/Schema/Mysql.pm
+24
-0
No files found.
Bugzilla/DB/Mysql.pm
View file @
620f4ea2
...
@@ -260,6 +260,10 @@ sub bz_setup_database {
...
@@ -260,6 +260,10 @@ sub bz_setup_database {
# We estimate one minute for each 3000 bugs, plus 3 minutes just
# We estimate one minute for each 3000 bugs, plus 3 minutes just
# to handle basic MySQL stuff.
# to handle basic MySQL stuff.
my
$rename_time
=
int
(
$bug_count
/
3000
)
+
3
;
my
$rename_time
=
int
(
$bug_count
/
3000
)
+
3
;
# And 45 minutes for every 15,000 attachments, per some experiments.
my
(
$attachment_count
)
=
$self
->
selectrow_array
(
"SELECT COUNT(*) FROM attachments"
);
$rename_time
+=
int
((
$attachment_count
*
45
)
/
15000
);
# If we're going to take longer than 5 minutes, we let the user know
# If we're going to take longer than 5 minutes, we let the user know
# and allow them to abort.
# and allow them to abort.
if
(
$rename_time
>
5
)
{
if
(
$rename_time
>
5
)
{
...
@@ -337,6 +341,11 @@ sub bz_setup_database {
...
@@ -337,6 +341,11 @@ sub bz_setup_database {
# Go through all the tables.
# Go through all the tables.
foreach
my
$table
(
@tables
)
{
foreach
my
$table
(
@tables
)
{
# Will contain the names of old indexes as keys, and the
# definition of the new indexes as a value. The values
# include an extra hash key, NAME, with the new name of
# the index.
my
%
rename_indexes
;
# And go through all the columns on each table.
# And go through all the columns on each table.
my
@columns
=
$self
->
bz_table_columns_real
(
$table
);
my
@columns
=
$self
->
bz_table_columns_real
(
$table
);
...
@@ -359,20 +368,20 @@ sub bz_setup_database {
...
@@ -359,20 +368,20 @@ sub bz_setup_database {
foreach
my
$column
(
@columns
)
{
foreach
my
$column
(
@columns
)
{
# If we have an index named after this column, it's an
# If we have an index named after this column, it's an
# old-style-name index.
# old-style-name index.
# This will miss PRIMARY KEY indexes, but that's OK
# because we aren't renaming them.
if
(
my
$index
=
$self
->
bz_index_info_real
(
$table
,
$column
))
{
if
(
my
$index
=
$self
->
bz_index_info_real
(
$table
,
$column
))
{
# Fix the name to fit in with the new naming scheme.
# Fix the name to fit in with the new naming scheme.
my
$new_name
=
$table
.
"_"
.
$index
->
{
NAME
}
=
$table
.
"_"
.
$index
->
{
FIELDS
}
->
[
0
]
.
"_idx"
;
$index
->
{
FIELDS
}
->
[
0
]
.
"_idx"
;
print
"Renaming index $column to $new_name...\n"
;
print
"Renaming index $column to "
# Unfortunately, MySQL has no way to rename an index. :-(
.
$index
->
{
NAME
}
.
"...\n"
;
# So we have to drop and recreate the indexes.
$rename_indexes
{
$column
}
=
$index
;
$self
->
bz_drop_index_raw
(
$table
,
$column
,
"silent"
);
$self
->
bz_add_index_raw
(
$table
,
$new_name
,
$index
,
"silent"
);
}
# if
}
# if
}
# foreach column
}
# foreach column
my
@rename_sql
=
$self
->
_bz_schema
->
get_rename_indexes_ddl
(
$table
,
%
rename_indexes
);
$self
->
do
(
$_
)
foreach
(
@rename_sql
);
}
# foreach table
}
# foreach table
}
# if old-name indexes
}
# if old-name indexes
...
...
Bugzilla/DB/Schema/Mysql.pm
View file @
620f4ea2
...
@@ -166,6 +166,30 @@ sub get_drop_index_ddl {
...
@@ -166,6 +166,30 @@ sub get_drop_index_ddl {
return
(
"DROP INDEX \`$name\` ON $table"
);
return
(
"DROP INDEX \`$name\` ON $table"
);
}
}
# A special function for MySQL, for renaming a lot of indexes.
# Index renames is a hash, where the key is a string - the
# old names of the index, and the value is a hash - the index
# definition that we're renaming to, with an extra key of "NAME"
# that contains the new index name.
# The indexes in %indexes must be in hashref format.
sub
get_rename_indexes_ddl
{
my
(
$self
,
$table
,
%
indexes
)
=
@_
;
my
@keys
=
keys
%
indexes
or
return
();
my
$sql
=
"ALTER TABLE $table "
;
foreach
my
$old_name
(
@keys
)
{
my
$name
=
$indexes
{
$old_name
}
->
{
NAME
};
my
$type
=
$indexes
{
$old_name
}
->
{
TYPE
};
$type
||=
'INDEX'
;
my
$fields
=
join
(
','
,
@
{
$indexes
{
$old_name
}
->
{
FIELDS
}});
$sql
.=
" ADD $type $name ($fields), DROP INDEX $old_name,"
;
}
# Remove the last comma.
chop
(
$sql
);
return
(
$sql
);
}
# Converts a DBI column_info output to an abstract column definition.
# Converts a DBI column_info output to an abstract column definition.
# Expects to only be called by Bugzila::DB::Mysql::_bz_build_schema_from_disk,
# Expects to only be called by Bugzila::DB::Mysql::_bz_build_schema_from_disk,
# although there's a chance that it will also work properly if called
# although there's a chance that it will also work properly if called
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment