sql - Need to index column in AND statement? -
i have select on table this:
- id
- username
- speed
- is_running
the statement like:
select * mytable username = 'foo' , is_running = 1
i have index on "username". if i'm running above statement, need index "is_running" best performance? or first column of select make difference? i'm using mysql 5.0.
it depends on type of data you're storing. if it's bool, may not see gain index on column alone. may want try add composite index on 2 columns:
alter table mytable add index `idx_username_is_running` ( `username` , `is_running` );
Comments
Post a Comment