我在理解为什么此代码在组表 400000 行中返回数百万行时遇到了一些问题。RID 循环和 t2 上的索引查找应返回 1 行,它们返回组表中的所有行。
Create table #group (IDperson uniqueidentifier, MGroup_Idx int,
NGroup_Idx int)
create index i1 on #group (NGroup_Idx);
-- insert some data
SELECT * FROM #group t
LEFT JOIN #group t2 ON t.NGroup_Idx = t2.NGroup_Idx
AND t2.MGroup_Idx IS not NULL
WHERE ISNULL(t.MGroup_Idx, t2.MGroup_Idx) IS NOT NULL
Run Code Online (Sandbox Code Playgroud)