mysql - Does creating an index on two columns x and y makes queries faster when searching on column x only? -
mysql - Does creating an index on two columns x and y makes queries faster when searching on column x only? -
does creating index on 2 columns 'x' , 'y' makes queries faster when searching on column x only? illustration have table columns 'id', 'x' , 'y'. , have 2 questions:
when create 2 separate indexes 'x' , 'y', help (make things faster) query this:
select * `table` x=1 , y=2 ? believe not. not sure.
when create 1 index on 2 colums 'x' , 'y' help query like:
select * `table` x=1 ? is, searching on 1 of these columns.
it might speed query. there exists feature called "index merge", can merge 2 separate indexes fulfill needs of 1 query. explain show if used. if not, 1 must add together combined index. when 2 indexes can merged depends heavily on used mysql version. whereas 5.1 not , ignored (a lot?) cases, feature more mutual used in e.g. version 5.6. this depends on order of columns within key. can create (x,y) key , (y,x). rear part of combined index can used, if parts before used. select...where x=1 index (x,y) can used, whereas index (y,x) cannot.
mysql
Comments
Post a Comment