我刚刚发现以下两个选择语句之间的执行计划性能差异巨大:
select * from your_large_table
where LEFT(some_string_field, 4) = 2505
select * from your_large_table
where some_string_field like 2505%
执行计划分别为98%和2%。速度上确实有些差异。当我看到这个时,我感到非常震惊。
I ve always done LEFT(xxx) = yyy as it reads well. I actually found this out by checking the LINQ generated SQL against my hand crafted SQL. I assumed the LIKE command would be slower, but is in fact much much faster.
我的问题是为什么LEFT()比LIKE%..慢呢?它们毕竟是相同的吗?
此外,使用LEFT()是否会影响CPU?