mysql - alternative / efficient / optimized query -
i want alternative / efficient / optimized query following query:
table:
create table `bartco_web_vms_studio`.`table_name` ( `index` int( 10 ) not null auto_increment , `id1` int( 10 ) not null default '0', `id2` varchar( 10 ) not null, `f3` tinyint( 4 ) not null default '0', primary key ( `index` ) ) engine = myisam ;
composite index:
create index id1_id2 on tablename (id1, id2);
number of rows = 7891
update query:
update table_name set f3=1 id1=1 , id2='a' or id1=2 , id2='b' or id1=3 , id2='c'
basically have update field's value based on 2 fields (id1, id2) values. these 2 fields can in more 1 pair.
output explain select f3 table_name ...
:
id -> 1, select type -> simple, table -> table_name, type -> range, possible_keys -> id1_id2, key -> id1_id2, key_len -> 261, ref -> null, rows -> 2, -> using
thanks lot help
regards
composite index id1 + id2
, query
where (id1, id2) in ((1, 'a'), (2, 'b'), (3, 'c'))
should help
also, when you're testing - add more rows table.
since you're selecting 3 rows of 9 - mysql can decide never use index @ all.
upd:
if nothing our answers - can split query 3:
select * table id1 .. , id2 .. union select * table id1 .. , id2 .. ...
Comments
Post a Comment