本篇主要是上篇查詢優(yōu)化例子。
查詢優(yōu)化舉例
連接5張表(persons, mobiles, mails, addresses, bank_accounts),獲取個(gè)人全部信息。
SELECT * from PERSON, MOBILES, MAILS,ADRESSES, BANK_ACCOUNTSWHEREPERSON.PERSON_ID = MOBILES.PERSON_IDAND PERSON.PERSON_ID = MAILS.PERSON_IDAND PERSON.PERSON_ID = ADRESSES.PERSON_IDAND PERSON.PERSON_ID = BANK_ACCOUNTS.PERSON_ID
作為查詢優(yōu)化必須解決一下兩個(gè)問題:
1. What kind of join should I use for each join?
有3種join,且還應(yīng)考慮是否有索引或者有幾個(gè)索引,什么類型索引,條件不同,選擇的join都會(huì)不同。
2. What order should I choose to compute the