您的位置:首页 > 数据库

sql 2005 强制使用执行计划 T—SQl

2010-04-27 14:46 447 查看
select * from tt t inner loop join ss s with(nolock) on s.c=t.c

使用 nested join
select * from tt t inner merge join ss s with(nolock) on s.c=t.c

使用 merge join

select * from tt t inner hash join ss s with(nolock) on s.c=t.c

使用 hash jion

nolock 不允许锁

Microsoft SQL Server sometimes uses hash and merge joins when querying large tables when uncomplicated nested loop joins would result in better performance and less server impact. In many such cases, query times go from many milliseconds to many seconds because hash table joins require that large amounts of data be processed and temporarily stored, and merge joins require sorting and then processing similarly large amounts of data.

This is fine for one-time administrative "fact finding" queries where you don't have or want the indices needed to optimize the query, and you're willing to wait the seconds or minutes it takes to get results.
For day-in-and-day-out application queries, however, you don't want your database engine to be hashing or sorting hundreds of thousands or millions of rows, especially when the end result is only a small number of rows.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: