简体   繁体   English

Oracle存储过程是否比Microsoft.NET应用程序的内联SQL快?

[英]Are Oracle stored procedures faster than in line SQL for a Microsoft.NET application?

We are developing a Visual Studio.NET 2008 application with Oracle 9i as backend. 我们正在开发一个以Oracle 9i为后端的Visual Studio.NET 2008应用程序。 Is it true that the usage of Stored procedures would be faster than Inline SQL ? 的确,存储过程的使用会比内联SQL快吗? This is a debate with my co-programmers. 这是与我的联合程序员的辩论。

We are using ODP.NET (Oracle Data Provider for .NET) from Oracle. 我们正在使用Oracle的ODP.NET(.NET的Oracle数据提供程序)。

Thanks. 谢谢。

While I am tempted to answer "no" or "I don't think so", the only real way to know the answer to this question is to go and measure it yourself . 虽然我很想回答“否”或“我不这么认为”,但知道该问题答案的唯一真实方法是自己去测量 Use a profiler like JetBrains dotTrace, and TOAD's own profiler, to find out. 使用诸如JetBrains dotTrace之类的探查器以及TOAD自己的探查器来查找。

All other answers are speculative. 所有其他答案都是推测性的。

It should be. 它应该是。 When you send inline SQL to database, the engine must parse it and execute. 当您将内联SQL发送到数据库时,引擎必须解析它并执行。 Stored procedures are being parsed (and compiled) at creation time. 存储过程在创建时正在解析(和编译)。 So at least you are gaining parsing time. 因此,至少您正在获得解析时间。

I would expect stored procedures to be faster in almost all cases. 我希望几乎在所有情况下存储过程都可以更快。
But it mainly depends on your code. 但这主要取决于您的代码。
If for example you get a resultset from your database and then use this data to perform other queries, you'll end up with a lot of overhead in your network traffic. 例如,如果您从数据库中获得一个结果集,然后使用该数据执行其他查询,那么网络流量将导致大量开销。 This is especially true if you forget to use a single connection for the requests. 如果您忘记为请求使用单个连接,则尤其如此。
It could then be more efficient to use a single stored procedure to return the agregated data (if possible of course). 这样,使用单个存储过程返回聚合数据可能会更有效率(当然,如果可能的话)。

如果以这样的方式构建存储的procs(PL / SQL包),它将使数据库和客户端之间传输的数据更少,从而更快。

Jon Limjap said: "All other answers are speculative." 乔恩·林贾普说:“所有其他答案都是推测性的。”

There's much truth to this statement. 这个说法有很多道理。 There are so many factors: how's the DB server set up? 有很多因素:数据库服务器如何设置? How's the network speed/reliability? 网络速度/可靠性如何? How's the SQL? SQL怎么样? How's the PL/SQL? PL / SQL怎么样? I could write really slow SQL and/or PL/SQL if I wanted to (and have, inadvertently, on past projects!). 如果我愿意的话,我可以编写速度很慢的SQL和/或PL / SQL(并且无意间在过去的项目中!)。 So if you can, try both out. 因此,如果可以,请尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM