Nested sql connection requires an explanation of the process

I want to understand the process of suggesting nested connections in sql queries. Can you explain this example with pseudo-codes? (What is the table join order?)

  FROM 
table1 AS t1 (nolock)
    INNER JOIN table2 AS t2 (nolock)
        INNER JOIN table3 as t3 (nolock)
        ON t2.id = t3.id
    ON t1.mainId = t2.mainId
+3
source share
3 answers

In SQl, we mainly have 3 ways to join two tables.

Nested loop (well, if one table has a small number of rows) Hash Join (Well, if both tables have very large rows, this makes expensive hash generation in memory) Merge Join (Good when we sorted the data to join).

From your question, it seems that you want to use Nested Loop.

Let's say t1 has 20 lines, t2 has 500 lines.

Now it will be like

t1   t2, t1.MainId = t2.MainId

t3.

, ..

+2

EXPLAIN query.

, .:)

, SQL Server. Razor SQLServer Explain Plan

SET SHOWPLAN_ALL

+1

SQL Server Query Analyzer, "Show " " " " .

+1

Source: https://habr.com/ru/post/1727592/


All Articles