討論Oracle文檔學(xué)習(xí)經(jīng)驗(yàn)
Oracle有很多值得學(xué)習(xí)的地方,這里我們主要介紹Oracle文檔,包括介紹RBO優(yōu)化器等方面。在Oracle文檔上說:對于RBO來說,以from 子句中從右到左的順序選擇驅(qū)動表,即最右邊的表為第一個驅(qū)動表,這是其英文原文:All things being equal RBO chooses the driving order by taking the tables in the FROM clause RIGHT to LEFT。
不過,在我做的測試中,從來也沒有驗(yàn)證過這種說法是正確的。我認(rèn)為,即使在RBO中,也是有一套規(guī)則來決定使用哪種連接類型和哪個表作為驅(qū)動表,在選擇時肯定會考慮當(dāng)前索引的情況,還可能會考慮where 中的限制條件,但是肯定是與where中限制條件的位置無關(guān)。
如果我創(chuàng)建3個表:
- 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
通過上面的這些例子,使我對Oracle文檔上的” All things being equal RBO chooses the driving order by taking the tables in the FROM clause RIGHT to LEFT”這句話持懷疑態(tài)度。此時,我也不能使用hints來強(qiáng)制優(yōu)化器使用nested loop,如果使用了hints,這樣就自動使用CBO優(yōu)化器,而不是RBO優(yōu)化器了。
【編輯推薦】