sql - MySQL primary key type becomes "index" after inner join -
I am working with a large database (500+ million entries), and trying to optimize the search engine I am here.
item_terms (id, data,
item_term_results (id, item_term_id, ITEM_ID)
item_terms.id is a unique index, and item_term_id is an index.
When trying the following query, everything goes well and I actually know what I want, the item I'm searching for, with the good performance being the id .
Select from DISTINCT item_term_results.item_id inside item_terms.id = item_term_results.item_term_id item_term_results contain item_terms where item_terms.term = 'Jason'
and return That query is a type "constant" on item_terms and "referee" to explain on item_term_results Great
But , now I want to add another where:.
DISTINCT item_term_results.item_id Select item_term_results combination based on item_terms from item_terms. Id = item_term_results.item_term_id Where item_terms.term = 'Jason' or item_terms.term = 'Bourne'
Surprise ! In the query item_terms is now a type of "index", even if item_term is a unique index
Any ideas why? How can I solve this problem? I can not go from mysql to second db at this point, and in every case I will need many WHERE cases.
Any help is appreciated, thanks!
You do not need many places where segment, use IN if it is the same area: < / P> And one FYI, the item_terms.term key is always indexed as primary.
Comments
Post a Comment