Closed
Bug 451735
Opened 16 years ago
Closed 14 years ago
Wrong index for the series table
Categories
(Bugzilla :: Database, defect)
Tracking
()
RESOLVED
FIXED
Bugzilla 4.2
People
(Reporter: LpSolit, Assigned: LpSolit)
References
Details
Attachments
(3 files, 1 obsolete file)
2.05 KB,
patch
|
mkanat
:
review+
|
Details | Diff | Splinter Review |
2.08 KB,
patch
|
mkanat
:
review+
|
Details | Diff | Splinter Review |
1.36 KB,
patch
|
mkanat
:
review+
|
Details | Diff | Splinter Review |
Currently, the series table has the following index:
series_creator_idx =>
{FIELDS => [qw(creator category subcategory name)],
TYPE => 'UNIQUE'},
But by looking at the code in Series.pm and chart.cgi, it appears that $series->existsInDatabase only makes sure that the triplet qw(category subcategory name) already exists, i.e. we don't allow another user to create exactly the same triplet. As this seems to be the desired behavior, and I understand why this behavior is the one we want, we should enforce this in the DB itself by fixing the index to:
series_creator_idx =>
{FIELDS => [qw(category subcategory name)],
TYPE => 'UNIQUE'},
Else if we get a duplicated entry, we would severely be in trouble.
![]() |
Assignee | |
Comment 1•16 years ago
|
||
Probably we should have:
series_creator_idx => ['creator'],
series_category_idx =>
{FIELDS => [qw(category subcategory name)],
TYPE => 'UNIQUE'},
![]() |
Assignee | |
Comment 2•14 years ago
|
||
Updated•14 years ago
|
Attachment #482078 -
Flags: review?(mkanat) → review+
Updated•14 years ago
|
Flags: approval+
Target Milestone: --- → Bugzilla 4.2
![]() |
Assignee | |
Comment 3•14 years ago
|
||
Committing to: bzr+ssh://lpsolit%40gmail.com@bzr.mozilla.org/bugzilla/trunk/
modified Bugzilla/DB/Schema.pm
modified Bugzilla/Install/DB.pm
Committed revision 7533.
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
![]() |
Assignee | |
Comment 4•14 years ago
|
||
My patch is causing trouble on MySQL:
Removing index 'series_creator_idx' from the series table...
Failed SQL: [DROP INDEX `series_creator_idx` ON series] Error: DBD::mysql::db do failed: Error on rename of './bugs_cvs/#sql-c1c_5' to './bugs_cvs/series' (errno: 150) [for Statement "DROP INDEX `series_creator_idx` ON series"] at Bugzilla/DB.pm line 967
eval {...} called at Bugzilla/DB.pm line 967
Bugzilla::DB::bz_drop_index_raw('Bugzilla::DB::Mysql=HASH(0xbea5ca0)', 'series', 'series_creator_idx') called at Bugzilla/DB.pm line 936
Bugzilla::DB::bz_drop_index('Bugzilla::DB::Mysql=HASH(0xbea5ca0)', 'series', 'series_creator_idx') called at Bugzilla/Install/DB.pm line 3464
Bugzilla::Install::DB::_fix_series_indexes() called at Bugzilla/Install/DB.pm line 645
Bugzilla::Install::DB::update_table_definitions('HASH(0xa3caca8)') called at ./checksetup.pl line 199
Adding new index 'series_creator_idx' to the series table ...
DBD::mysql::db do failed: Duplicate key name 'series_creator_idx' [for Statement "CREATE INDEX `series_creator_idx` ON series (creator)"] at Bugzilla/DB.pm line 752
Bugzilla::DB::bz_add_index_raw('Bugzilla::DB::Mysql=HASH(0xbea5ca0)', 'series', 'series_creator_idx', 'ARRAY(0xbee6900)') called at Bugzilla/DB.pm line 725
Bugzilla::DB::bz_add_index('Bugzilla::DB::Mysql=HASH(0xbea5ca0)', 'series', 'series_creator_idx', 'ARRAY(0xbee6900)') called at Bugzilla/Install/DB.pm line 3465
Bugzilla::Install::DB::_fix_series_indexes() called at Bugzilla/Install/DB.pm line 645
Bugzilla::Install::DB::update_table_definitions('HASH(0xa3caca8)') called at ./checksetup.pl line 199
My guess is that you cannot remove an index on a column which is involved in a FK. This would mean that the FK has to be removed first, and readded only when the new index is in place.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
![]() |
Assignee | |
Comment 5•14 years ago
|
||
http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
"InnoDB requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan. In the referencing table, there must be an index where the foreign key columns are listed as the first columns in the same order. Such an index is created on the referencing table automatically if it does not exist. (This is in contrast to some older versions, in which indexes had to be created explicitly or the creation of foreign key constraints would fail.)"
mkanat, should bz_drop_index() automatically remove FKs for us? I think they are re-added automatically by checksetup.pl, based on DB/Schema.pm.
Comment 6•14 years ago
|
||
Yeah, there should be some way for bz_drop_index (or get_drop_index_sql in Schema) to drop the FKs for us and have checksetup re-created them later. All the methods you'd need for that should already exist.
![]() |
Assignee | |
Comment 7•14 years ago
|
||
The fix in Bugzilla/Install/DB.pm is for installations which unfortunately already upgraded to current tip code. Fortunately, this check is done only once as we return earlier if indexes have already been updated/created.
Attachment #483326 -
Flags: review?(mkanat)
Comment 8•14 years ago
|
||
Comment on attachment 483326 [details] [diff] [review]
fix bz_drop_index() to first delete related FKs, v1
bz_index_info_real only actually exists on MySQL, so the new Install::DB code should go into bz_setup_database in Bugzilla::DB::Mysql instead.
Attachment #483326 -
Flags: review?(mkanat) → review-
![]() |
Assignee | |
Comment 9•14 years ago
|
||
Attachment #483326 -
Attachment is obsolete: true
Attachment #483346 -
Flags: review?(mkanat)
Comment 10•14 years ago
|
||
Comment on attachment 483346 [details] [diff] [review]
fix bz_drop_index() to first delete related FKs, v2
Beautiful. Thank you! :-)
Attachment #483346 -
Flags: review?(mkanat) → review+
![]() |
Assignee | |
Comment 11•14 years ago
|
||
I hope the problem is now fixed for real. :)
Committing to: bzr+ssh://lpsolit%40gmail.com@bzr.mozilla.org/bugzilla/trunk/
modified Bugzilla/DB.pm
modified Bugzilla/DB/Mysql.pm
Committed revision 7542.
Status: REOPENED → RESOLVED
Closed: 14 years ago → 14 years ago
Resolution: --- → FIXED
![]() |
Assignee | |
Comment 12•14 years ago
|
||
Max, I think this fix is a better approach than the previous one: we should call bz_index_info() instead of bz_drop_index(), and only fix the DB if it's actually in an inconsistent state. If the stored DB schema matches the real DB schema, then we shouldn't do anything, and let Bugzilla/Install/DB.pm do its job.
I feel much more confident with this additional fix.
Attachment #483430 -
Flags: review?(mkanat)
Comment 13•14 years ago
|
||
Comment on attachment 483430 [details] [diff] [review]
better fix, v2.1
Ah, yeah, I agree, I like this more. :-)
Attachment #483430 -
Flags: review?(mkanat) → review+
![]() |
Assignee | |
Comment 14•14 years ago
|
||
Committing to: bzr+ssh://lpsolit%40gmail.com@bzr.mozilla.org/bugzilla/trunk/
modified Bugzilla/DB.pm
modified Bugzilla/DB/Mysql.pm
Committed revision 7546.
You need to log in
before you can comment on or make changes to this bug.
Description
•