.net - Oracle - 参数化查询有 EXECUTIONS = PARSE_CALLS

标签 .net sql oracle oracle10g

我们有一个与 Oracle 10g 通信的 .NET 应用程序。我们的 DBA 最近提取了一个查询列表,其中执行次数等于 parse_calls。我们假设这将帮助我们找到代码中所有未参数化的查询。

出乎意料的是,以下查询出现在该列表的顶部附近,执行次数为 1,436,169 次,解析次数为 1,436,151 次:

SELECT bar.foocolumn
  FROM bartable bar,
       baztable baz
 WHERE bar.some_id = :someId
   AND baz.another_id = :anotherId
   AND baz.some_date BETWEEN bar.start_date AND (nvl(bar.end_date, baz.some_date + (1/84600)) - (1/84600))

为什么此查询的执行次数等于 parse_calls?

最佳答案

解析查询的次数完全取决于调用应用程序。每次应用程序要求数据库解析查询时,都会解析一次查询。

服务器端,有different kinds of parse :

  • HARD parse -- the query has never been seen before, isn't in the shared pool. We must parse it, hash it, look in the shared pool for it, don't find it, security check it, optimize it, etc (lots of work).

  • SOFT parse -- the query has been seen before, is in the shared pool. We have to parse it, hash it, look in the shared pool for it and find it (less work then a hard parse but work none the less)

在您的情况下,您很可能在每个 session 中创建一次语句,然后将其丢弃,因此 Oracle 每次都必须解析它。然而,由于参数化,这种解析是一种软解析,Oracle 只进行一次优化它的昂贵步骤。

不过,您可以在应用程序中缓存该语句并重用它,以便每个 session 仅(软)解析一次。

关于.net - Oracle - 参数化查询有 EXECUTIONS = PARSE_CALLS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2811164/

相关文章:

.net - 在表单应用程序和 Windows 服务(或任何 n 层,真的)之间保持设置同步

mysql - 想要 Mysql SELECT 查询返回字符串而不是数字

java - tomcat jdbc 池超时不工作

sql - 使用 ROWNUM 在 Oracle 中获取质数记录

sql oracle更新日期

c# - C# 的设计模式和基于字符串参数调用不同的方法

c# - BinaryWriter Endian 问题

sql - 将数据从一个表复制到另一个表并同时添加另一列

mysql - 子查询使用 JOINS 返回多于 1 行的问题

.net - 如何通过类型名称获取泛型接口(interface)的类型?