In my Mariadb table I have two id-columns (A,B), which combined are unique, but not individually. This table is quite large. To speed up queries like
SELECT B WHERE A=?
I have added a primary key (A,B), which worked fine. However sometimes I also need queries
SELECT A WHERE B=?
which are rather slow. What is the optimal way improve performance here? Is it reasonable to create a second unique index (B,A) on the table?
Moreover, if I do create that second index, does inserting entries into the table become slower, since both indexes are checked? In theory, checking that (A,B) is unique implies that (B,A) is unique, but does Mariadb know that, or does it check both?