我在 sql-server 中有两个表。
System{
AUTO_ID -- identity auto increment primary key
SYSTEM_GUID -- index created, unique key
}
File{
AUTO_ID -- identity auto increment primary key
File_path
System_Guid -- foreign key refers system.System_guid, index is created
-- on this column
}
系统表有 100,000 行。文件表有 200,000 行。文件表只有 10 个不同的值System_guid
。
我的查询如下:
Select * from
File left outer join System
on file.system_guid = system.system_guid
SQL 服务器正在使用哈希匹配连接来给我结果,这需要很长时间。
我想优化此查询以使其运行得更快。只有 10 个不同的 system_guid 的事实可能意味着哈希匹配会浪费能量。如何利用这些知识来加快查询速度?