使用mssql server 2008.我需要比较性能。直到下周我才能访问查询分析器。这只是一个疯狂的想法,我想知道哪个脚本将表现最好。哪个示例最适合使用索引
我想知道哪些脚本可以使用txt上的索引以及为什么。
该2代表具有总共3个索引和两个表具有近似为1点密耳的行
table1(id int(clustered index), name varchar(10))
table2(t1_id int(non-clustered index), txt varchar(10)(non-clustered index))
SQL1:(2 *联接)
SELECT *
FROM table1 t1 LEFT JOIN
table2 t2 ON t1.id = t2.t1_id
AND NOT t2.txt LIKE 'blue%'
AND NOT t2.txt LIKE 'green%'
INNER JOIN table2 t3 ON t1.id = t3.t1_id
WHERE t2.id is NULL
SQL2:(1 *加入1 * '或')
SELECT *
FROM table1 t1 LEFT JOIN
table2 t2 ON t1.id = t2.t1_id
AND (t2.txt LIKE 'blue%' or t2.txt LIKE 'green%')
AFAI记得Stack Exchange Data Explorer有一个“View Execution Plan”选项。对我来说,SQL2看起来更可怕,尽管它没有任何否定。 –
顺便说一句,请提供正确的DDL(你错过了有关't1_id'的任何信息,并且未能准确解释你有什么索引 - 是否有2个单独的索引在t2或只有1个组合索引。 ) –
@MartinSmith纠正了t1_id,总共3个索引,我加了哪些索引是聚集的,而不是。唯一有趣的索引是txt上的索引 –