DB/Schema: Correct use of indexes on mail_items table. Prevents deadlocks in operations on this table.

This commit is contained in:
Machiavelli
2011-05-29 00:32:18 +02:00
parent 4fe5388be8
commit f8bd56e219
2 changed files with 10 additions and 2 deletions

View File

@@ -1966,8 +1966,9 @@ CREATE TABLE `mail_items` (
`mail_id` int(10) unsigned NOT NULL DEFAULT '0',
`item_guid` int(10) unsigned NOT NULL DEFAULT '0',
`receiver` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Character Global Unique Identifier',
PRIMARY KEY (`mail_id`,`item_guid`),
KEY `idx_receiver` (`receiver`)
PRIMARY KEY (`item_guid`),
KEY `idx_receiver` (`receiver`),
KEY `idx_mail_id` (`mail_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
/*!40101 SET character_set_client = @saved_cs_client */;

View File

@@ -0,0 +1,7 @@
-- Uncomment this query if the second query gives you primary key violation errors
-- DELETE FROM `mail_items` WHERE `item_guid` IN (SELECT `item_guid` FROM `mail_items` GROUP BY `item_guid` HAVING COUNT(`item_guid`) > 1);
ALTER TABLE `mail_items`
DROP PRIMARY KEY,
ADD PRIMARY KEY(`item_guid`),
ADD KEY `idx_mail_id` (`mail_id`);