MySQL Forums
Forum List  »  InnoDB

what is the difference between index (a,b) and (b,a)
Posted by: Bing Wu
Date: March 06, 2017 04:14AM

I have two indexes
create index idx_ab on t(a,b)
create index idx_ba on t(b,a)
And I have only one query condition one this table
select * from t where a = x and b = y

Is there any performance difference on these two indexes?

I think in B+ tree structure, (a,b) is treated as one node(with two fields), so there is no performance difference on these two indexes.
Many blogs say that we should place the field with bigger cardinality at first. I think place the field with bigger cardinality at first, the index can be used for both "where a = x and b = y" and "where b = x and a = y". However, as for the only one query "where a = x and b = y", the two indexes are the same on performance.
Am I right?

Options: ReplyQuote


Subject
Views
Written By
Posted
what is the difference between index (a,b) and (b,a)
163
March 06, 2017 04:14AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.