查询提示主要用来手动改变执行计划,这里要讲的关联提示,主要是用来指定2个表关联时,用何种关联算法。
创建测试表:
if object_id('t1') is not null drop table t1
if object_id('t2') is not null drop table t2
go
select * into t1
from sys.objects
select * into t2
from sys.tables
关联提示:hash | merge | loop join
下面是具体的例子:
select t1.object_id,
t2.name,
t2.type_desc
from t1
inner hash join t2
on t1.object_id = t2.object_id
select t1.object_id,
t2.name,
t2.type_desc
from t1
inner merge join t2
on t1.object_id = t2.object_id
select t1.object_id,
t2.name,
t2.type_desc
from t1
inner loop join t2
on t1.object_id = t2.object_id
对应的执行计划: