什么時候應該在內部連接上使用交叉應用?使用的主要目的是什么?交叉應用?我(隱約地,通過互聯網上的帖子)讀到cross apply如果要進行分區,則在對大型數據集進行選擇時,效率可能更高。(想到尋呼)我也知道CROSS APPLY 不需要將udf作為正確的表。在大多數INNER JOIN查詢(一對多的關系),我可以重寫它們以使用CROSS APPLY但他們總是給我同等的執行計劃。誰能給我舉個很好的例子CROSS APPLY在那些情況下INNER JOIN也會起作用嗎?編輯:下面是一個簡單的例子,其中的執行計劃是完全相同的。(給我看看它們的不同之處cross apply更快/更有效率)create table Company (
companyId int identity(1,1), companyName varchar(100), zipcode varchar(10) , constraint PK_Company primary key (companyId))GOcreate table Person (
personId int identity(1,1), personName varchar(100), companyId int, constraint FK_Person_CompanyId foreign key (companyId) references dbo.Company(companyId), constraint PK_Person primary key (personId))GOinsert Companyselect 'ABC Company', '19808' unionselect 'XYZ Company', '08534' unionselect '123 Company', '10016'insert Personselect 'Alan', 1 unionselect 'Bobby', 1 unionselect 'Chris', 1 unionselect 'Xavier', 2 unionselect 'Yoshi', 2 unionselect 'Zambrano', 2 unionselect 'Player 1', 3 unionselect 'Player 2', 3 unionselect 'Player 3', 3 /* using CROSS APPLY */select *from Person pcross apply (
select *
from Company c where p.companyid = c.companyId) Czip/* the equivalent query using INNER JOIN */select *from Person pinner join Company c on p.companyid = c.companyId
什么時候應該在內部連接上使用交叉應用?
犯罪嫌疑人X
2019-06-27 15:57:58