使用 TableAdapter 调用 Oracle SP 非常慢

发布于 2024-07-09 20:09:53 字数 376 浏览 6 评论 0原文

我有一个查询在 sql 编辑器 (oracle) 中执行时运行速度超快:1 毫秒。

由 DataSet-TableAdapter 执行相同的查询(作为存储过程)需要 2 秒。 我只是检索 20 行。

由于我使用的是 TableAdapter,因此返回值存储在引用游标中。

如果我要获取 2'000 行,我可以理解构建数据集需要一些时间,但 2 秒只获取 20 行对我来说似乎太多了。

有更好的方法在oracle上执行SP还是这是唯一的方法? 我可以尝试做些什么来提高性能?

感谢您的帮助!


google了一下,好像是refcursor的问题。 其他人也面临同样的性能问题,但没有提供解决方案。

I have a query that runs super fast when executed in the sql editor (oracle): 1ms.

The same query (as stored procedure) when executed by a DataSet-TableAdapter takes 2 seconds. I'm just retrieving 20rows.

Since I'm using a TableAdapter, the return values are stored in a ref cursor.

If I was fetching 2'000 rows I could understand that some time is needed to build the DataSet, but 2 seconds for only 20 rows seems too much for me.

There is a better way to execute SP on oracle or this is the only way?
What could I try to do to improve the performances?

Thanks for your help!


Searching in google, it seems that the problem is with the refcursor. Others people faced the same performance issue, but no solution is provided.

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

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

发布评论

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

评论(4

多孤肩上扛 2024-07-16 20:09:54

确保将 CommandType 设置为 CommandType.StoredProcedure

例如(来自 MSDN):

OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "COUNT_JOB_HISTORY";
cmd.CommandType = CommandType.StoredProcedure;

Make sure you're setting the CommandType to CommandType.StoredProcedure.

For example (from MSDN):

OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "COUNT_JOB_HISTORY";
cmd.CommandType = CommandType.StoredProcedure;
橪书 2024-07-16 20:09:54

好的。 我发现问题是什么了。

一开始我以为是DataProvided的问题,其实不是。 我在 SQLServer 2000 中发现了同样的问题......

在 google 中搜索我发现了一些关于执行计划的信息。 通过这种方式,我将查询性能提高了 50%。

问题的简要概述是,当通过代码执行 SP 时,DBMS 在执行计划上遇到一些问题,并且不使用索引......

这篇文章中有更好的答案:
SQL Server 中的参数嗅探(或欺骗)

我希望这会有所帮助你。

Ok. I found what's the problem.

At the beginning I thought it was a problem of DataProvided, but it wasnt. I discovered the same issue in SQLServer 2000....

Searching in google I found out something about the execution plan. Taking this way, I boosted the query performance of 50%.

Brief resume of the problem is that when executing a SP by code, the DBMS has some trouble with the execution plan, and doesn't use the indexes...

A better answer is in this post:
Parameter Sniffing (or Spoofing) in SQL Server

I hope this will help you.

梦言归人 2024-07-16 20:09:53

您使用哪个数据提供商?

您是否引用 System.Data.OracleClient 还是使用 odp.net(Oracle 用于将 .NET 应用程序与 Oracle 连接的数据提供程序)还是使用 devart(以前称为 corelab)提供程序。

我在 odp.net 与 Oracle 9 结合方面拥有良好的经验。您可以在 oracle 网站上免费下载 odp.net。 请参阅:http://www.oracle.com/technology/tech/ windows/odpnet/index.html

您可以使用最新版本(11.1.0.6.20)连接Oracle 9数据库。

Which data provider do you use?

Do you reference System.Data.OracleClient or do you use odp.net (Oracle's data provider for connecting .NET apps with Oracle) or do you use devart's (formerly known as corelab) provider.

I have good experiences with odp.net in combination with Oracle 9. You can download odp.net for free on the oracle site. See: http://www.oracle.com/technology/tech/windows/odpnet/index.html

You can use the latest version (11.1.0.6.20) to connect to an Oracle 9 database.

旧话新听 2024-07-16 20:09:53

使用数据读取器而不是 TableAdaptor 需要多长时间? 我会尝试数据读取器。 我从未遇到过数据读取器的问题。

How long does it take when you use a datareader instead of a TableAdaptor? I would try the datareader. I have never encountered problems with the datareader.

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