簡(jiǎn)單介紹Oracle驅(qū)動(dòng)表
Oracle有很多值得學(xué)習(xí)的地方,這里我們主要介紹Oracle驅(qū)動(dòng)表,包括介紹hints的用法等方面。CBO根據(jù)統(tǒng)計(jì)信息選擇Oracle驅(qū)動(dòng)表,假如沒有統(tǒng)計(jì)信息,則在from 子句中從左到右的順序選擇Oracle驅(qū)動(dòng)表。這與RBO選擇的順序正好相反。這是英文原文(CBO determines join order from costs derived from gathered statistics. If there are no stats then CBO chooses the driving order of tables from LEFT to RIGHT in the FROM clause. This is OPPOSITE to the RBO) 。
我還是沒法證實(shí)這句話的正確性。不過經(jīng)過驗(yàn)證:“如果用ordered 提示(此時(shí)肯定用CBO),則以from 子句中按從左到右的順序選擇Oracle驅(qū)動(dòng)表”這句話是正確的。實(shí)際上在CBO中,如果有統(tǒng)計(jì)數(shù)據(jù)(即對(duì)表與索引進(jìn)行了分析),則優(yōu)化器會(huì)自動(dòng)根據(jù)cost值決定采用哪種連接類型,并選擇合適的Oracle驅(qū)動(dòng)表,這與where子句中各個(gè)限制條件的位置沒有任何關(guān)系。如果我們要改變優(yōu)化器選擇的連接類型或Oracle驅(qū)動(dòng)表,則就需要使用 hints了,具體hints的用法在后面會(huì)給予介紹。
如果我創(chuàng)建的3個(gè)表:
- create table A(col1 number(4,0),col2 number(4,0), col4 char(30));
- create table B(col1 number(4,0),col3 number(4,0), name_b char(30));
- create table C(col2 number(4,0),col3 number(4,0), name_c char(30));
- create index inx_col12A on a(col1,col2);
執(zhí)行查詢:
- select A.col4
- from B, A, C
- where B.col3 = 10
- and A.col1 = B.col1
- and A.col2 = C.col2
- and C.col3 = 5;
- Execution Plan
【編輯推薦】