php - How to speed up slow MySQL UPDATE queries with InnoDB tables -


i have simple mysql update query on innodb table.

update `players_teams` set t_last_active=now() t_player_id=11225 , t_team_id=6912 , t_season_id=2002 limit 1 

my table structured so:

create table `players_teams` (   `id` int(11) unsigned not null auto_increment,   `t_player_id` int(11) default null,   `t_team_id` int(11) default null,   `t_league_id` int(11) default null,   `t_season_id` int(11) default null,   `t_div` varchar(64) default null,   `t_player_number` varchar(3) default null,   `t_player_jersey_size` enum('unknown','xs','s','m','l','xl','xxl','xxxl') default 'unknown',   `t_player_registration_number` varchar(64) default null,   `t_player_class` enum('roster','spare','coach','injured','holiday','suspended','scorekeeper') default 'roster',   `t_access_level` enum('player','manager','assistant') default 'player',   `t_player_position` enum('any','forward','defence','goalie','pitcher','catcher','first base','second base','third base','shortstop','left field','center field','right field') default 'any',   `t_spare_status` enum('invited','in','out') default null,   `t_drink_next` int(1) default '0',   `t_no_fees` tinyint(1) default '0',   `t_no_drink` tinyint(1) default '0',   `t_auto_check_in` tinyint(1) default '0',   `t_print_reminder` tinyint(1) default '0',   `t_notes` text,   `t_last_chatter_id` int(11) default null,   `t_last_history_id` int(11) default null,   `t_last_active` timestamp null default null,   `t_status` enum('active','inactive','archived') default 'active',   `t_added` timestamp null default current_timestamp,   primary key (`id`),   key `t_player_id` (`t_player_id`),   key `t_team_id` (`t_team_id`),   key `t_season_id` (`t_season_id`),   key `t_player_id_2` (`t_player_id`,`t_team_id`,`t_season_id`),   key `team/player id` (`t_team_id`,`t_player_id`),   key `updateplayersdiv` (`t_team_id`,`t_season_id`) ) engine=innodb auto_increment=23454 default charset=latin1; 

this simple update query takes on average, 3.5 seconds? i'm running on mediatemple mysql grid container.

here result of explain when switching update select.

results of explain

can provide insight on how i'm not doing correctly?

[edit: added list of indexes]

so big mess of indexes? have bunch of redundant indexes in here?

enter image description here

cheers, jon

it's using wrong key instead of index on 3 columns. can hint @ indexes use key ... syntax.

https://dev.mysql.com/doc/refman/5.1/en/index-hints.html

you may want try reordering key on 3 columns. generally, want restricting column first in index, next restricting , on.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -