0

属性にインデックスを作成すると、インデックスがツリーであり、ソートされた順序で値をナビゲートするため、レコードをより速く見つけることができます。
たとえばSELECT * from branches where name='Washington、インデックスを介して、ログ時間内にレコードに到達するために辞書順でナビゲートします。
しかし、結合で使用する列にインデックスを付ける場合、これはどのように機能するのでしょうか?
例えば

SELECT BILLS.NAME NAME, BILLS.AMOUNT AMOUNT FROM BILLS,BANK_ACCOUNTS WHERE BILLS.ACCOUNT_ID = BANK_ACCOUNTS.ACCOUNT_ID  

BILLS(ACCOUNT_ID)とのインデックスを作成した場合BANK_ACCOUNTS(ACCOUNT_ID)、ナビゲーションはどのように速くなりますか? の各値を取得BANK_ACCOUNTS.ACCOUNT_IDし、インデックスのツリーを使用してBILLS一致するレコードを見つけるだけですか?
これが機能する方法である場合、結合で使用される列にインデックスを作成することを通常推奨するのはなぜですか。
1 つのインデックスのみが作成され、それは等価コンパレータの左側のテーブル、つまりBILLS. それとも私が間違っていますか?

4

1 に答える 1

0

The example code you provide perfomr an INNER JOIN between BILLS and BANK_ACCOUNTS, so only rows from BILLS that exist in BANK_ACCOUNTS will be returned. This is checked while the query is running, by performing the join only to the non-clustered index on BANK_ACCOUNTS, because all fields from BANK_ACCOUNTS that are referenced by the query (ie BANK_ACCOUNTS.ACCOUNT_ID) are part of the index, and thus "covered" by it.

Looking BANK_ACCOUNTS.ACCOUNT_ID in the index is O(log N), whereas scanning BANK_ACCOUNTS for each lookup would be O(N).

Does that help?

于 2013-03-11T22:01:31.340 に答える