【Table connection method】

For three connections, Oracle we can use hint to force the optimizer to go: use_hash, use_nl, use_merge

The outline of the three connection methods is listed below:

nested loop

Extract a record from table A, traverse table B to find matching records, and then extract the next record from table a and traverse table B. . .

is a double cycle

 

hash join

Calculate a hash table from table A according to the connection key, then extract records from table B one by one, calculate the hash value, and match the eligible records according to the hash of the hash to table A

 

sort merge join

Sort the A and B tables in order, then do the merge, and select the eligible ones

 

 

 

 

 

Application of Nested Loops, Merge, Hash

 

1. Scope of Nested Loops

Two tables, one is called the outer table and the other is called the inner table.

 

Nested loop joins are especially efficient if the outer input is very small and the inner input is very large and pre-indexed.

 

Regarding which table is the outer table and which is the inner table when connecting, I found that sql server will automatically arrange it for you, regardless of where you write, it automatically selects the table with a small amount of data as the outer table, and the table with a large amount of data as the inner table surface.

 

 

2. Merge join (Merge)

It means that both tables have indexes on the filter conditions of on, and they are all ordered. In this way, when joining, sql server will use Merge join, so that the performance is better.

 

If one has an index and one has no index, the Nested Loops join will be selected.

 

 

3. Hash join (Hash)

If both tables have no index on the filter condition of on, then Hash join will be used.

 

That is, the use of the Hash join algorithm is due to the lack of ready-made indexes.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326148322&siteId=291194637