IDbCommand - CommandType.StoredProcedure

发布于 2024-11-26 18:11:13 字数 736 浏览 2 评论 0原文

我只是好奇 IDbCommand.CommandType 的值会对性能产生影响吗?

基本上,我可以将其设置为 CommandType.Text 并传入 SQL 查询“EXEC sp_my_stored_procedure ...”作为 CommandText。或者,我可以将其设置为 CommandType.StoredProcedure并传入存储过程名称“my_stored_procedure”作为CommandText。

我想知道这里是否有任何性能差异,或者只是传递调用 SP 的查询与传递 SP 的名称的问题?


附带说明,我意识到它可能取决于驱动程序,但我不确定。那么,如果是这样的话,我也想知道。谢谢!

I'm just curious if the IDbCommand.CommandType's value makes a difference in terms of performance?

Basically, I could do either set it as CommandType.Text and pass in a SQL query "EXEC sp_my_stored_procedure ..." as the CommandText. Or, I could set it as CommandType.StoredProcedure and pass in a stored procedure name "my_stored_procedure" as the CommandText.

I'm wondering if there is any performance difference here, or is it just a matter of passing in a query calling the SP vs passing in the name of the SP?


A side note, I realize that it could depend on the driver, but am not sure. So, if that's the case, I'd like to know that as well. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑看君怀她人 2024-12-03 18:11:13

使用 CommandType.StoredProcedure 效率更高。所感受到的影响取决于应用程序的负载。

在我看来,它也更干净。如果需要在运行时构建命令(即 SELECT id, name FROM Table WHERE.......),我通常会使用 CommandType.Text。

希望这有帮助,
凯文

Using the CommandType.StoredProcedure is more efficient. The impact would be felt dependent on your app's load.

In my opinion it is also cleaner. I would generally use CommandType.Text if there was a need to build the command at runtime (i.e. SELECT id, name FROM Table WHERE.......).

Hope this helps,
Kevin

回梦 2024-12-03 18:11:13

我反映到 Informix 对象:IfxCommand,它有一个名为 AdjustedCommandText 的内部属性。看来此方法根据 CommandType 格式化要发送到驱动程序的字符串值。

有趣的是,它要么为 TableDirect 返回一个值,要么为 StoredProcedure 返回另一个值。或者,只是存储的文本。现在,存储过程更加深入。如果没有命令参数,它只返回“EXECUTE PROCEDURE ...”,但如果涉及命令参数,那么它会构建以“{?=CALL ...”或{CALL ...”开头的字符串。

所以,我可以说就 Informix 而言,除了清晰度和整洁性之外没有任何区别。至于其他数据库驱动程序,我还没有研究过它们。

I reflected into the Informix object: IfxCommand which has an internal property named AdjustedCommandText. It seems that this method formats the string value to send to the driver based upon the CommandType.

What's interesting is that it either returns one thing for TableDirect or another for StoredProcedure. Or, just the stored text. Now, the StoredProcedure one goes deeper. If there are no command paramters it just returns "EXECUTE PROCEDURE ...", but if there are command parameters involved then it builds the string up starting with "{?=CALL ..." or {CALL ...".

So, I can say as far as Informix is concerned there is no difference except for clarity and cleanliness. As far as other database drivers, I don't haven't looked into them yet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文