我有两张桌子:
playerstatstable,入口表(见下文)
playerstatstable 有 100,000 行,entrytable 有 1 百万行
我想要做的是更新 playerstatstable 如下
UPDATE playerstatstable set totalScore = totalScore+1000 where PlayerID = (Select PlayerID from entrytable where score = 1 and entryState = 5 and playerstatstable.PlayerID = entrytable.PlayerID);
大约 1/10 的条目将处于状态 5,其中大约 1/5 的分数 = 1;
所以我有大约 20,000 个条目与需要更新的 20,000 个 playerstatstable 行相关联。
1)有更好的更新声明吗?
2)是否有任何索引/键安排可以改善这一点?
CREATE TABLE `playerstatstable` (
`PlayerID` int(11) NOT NULL,
`totalScore` int(11) DEFAULT '0',
PRIMARY KEY (`PlayerID`),
UNIQUE KEY `PlayerID_UNIQUE` (`PlayerID`),
KEY `idx_m` (`monthTime`),
KEY `idx_w` (`weekTime`),
KEY `idx_d` (`dayTime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `entrytable` (
`EntryID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`PlayerID` int(10) unsigned DEFAULT '0',
`entryType` bit(1) DEFAULT b'0',
`entryState` int(11) DEFAULT '1',
`score` int(11) DEFAULT '0',
`rank` int(11) DEFAULT '0',
PRIMARY KEY (`EntryID`),
UNIQUE KEY `EntryID_UNIQUE` (`EntryID`)
) ENGINE=InnoDB