通过sp_executeSQL过程执行时,为什么使用完全不同的执行计划会得到完全相同的SQL查询? [英] Why would the exact same SQL query result with a different execution plan when executed via the sp_executeSQL procedure?

查看:115
本文介绍了通过sp_executeSQL过程执行时,为什么使用完全不同的执行计划会得到完全相同的SQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我不明白为什么sp_executeSQL会生成与从Sql Management Studio中运行查询相比完全不同的执行计划.

As the title states, I don't understand why the sp_executeSQL would generate a completely different execution plan than running the query from Sql Management Studio.

从SQL Management Studio运行时,我所查询的查询将花费3秒,而通过sp_executeSQL在Management Studio中运行的查询将花费5分钟.

My query in question will take 3 seconds when run from SQL management Studio, where as the query run in management studio via sp_executeSQL will take 5 minutes.

我已经更新了统计信息,并查看了索引,但事实仍然是,sp_executeSQL的执行计划远比直接从我的管理工作室运行sql更糟糕.

I've updated statistics, and reviewed indexes, but the fact remained in my head that the execution plan from sp_executeSQL was FAR worse than running the sql directly from my management studio.

这是我的问题:为什么执行计划在以两种不同方式运行查询之间会有如此大的差异?

So here is my question: Why would the execution plans differ SO much between running the query in these two different ways?

谢谢

推荐答案

请参见

基本上, 同一过程可以有多个[执行]计划

这篇关于通过sp_executeSQL过程执行时,为什么使用完全不同的执行计划会得到完全相同的SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆