Hi! What is the best indexes for this case? (Using MySQL)
I think that I can use this index: tC = KEY tCC = KEY tPCP = KEY trFR = KEY trFT = KEY The order of the colums is the optimal? For example, in trFR I don't know if is better put the "idCont" before "idFile" because is the foreign_key to his 'left_table', or switch it because "idFile" is the foreign_key to the 'right_table'. Thanks! asked Dec 19 '11 at 12:27 Vimas |
Thanks! :) This is the current 'explain':
(Some redundant indexes in that tables :s (Simple-Column index with the same column of 1st column in a multi-column index) like IDX_tcc_idConCat -> IDX_tcc_idConCat_init (Same 1st and 2nd column, plus Date_init), etc... ) This is a "SHOW PROFILE CPU FOR QUERY 1;" result:
Version: 5.1.56-log Thanks, and enjoy your holidays! ;) answered Dec 27 '11 at 10:09 Vimas Markus Winand ♦♦ |
reg trFR: it depends on the join order. Does the database first process trFT (right table) or tcc (left table)? The database has the freedom to decide this on its own (based on statistics and assumptions). However, you can easily find out by inspecting the execution plan. Which is anyways the best way to see how the database uses (or doesn't use) indexes. Please post the execution plan with all the indexes you mentioned, so I can have a second look. http://use-the-index-luke.com/sql/explain-plan/mysql/getting-an-execution-plan -- ps.: been on holiday, therefore the late response.