oracle收集统计信息,游标失效时间

简介: Dbms_stats Invalidates Cursors in Auto_invalidate mode

1,控制方法和命令:

DBMS_STATS Constants

Name Type Description

ADD_GLOBAL_PREFS

NUMBER

Copies global preferences

AUTO_CASCADE

BOOLEAN

Lets Oracle decide whether to collect statistics for indexes or not

AUTO_DEGREE

NUMBER

Lets Oracle select the degree of parallelism based on size of the object, number of CPUs and initialization parameters

AUTO_INVALIDATE

BOOLEAN

Lets Oracle decide when to invalidate dependent cursors

AUTO_SAMPLE_SIZE

NUMBER

Indicates that auto-sample size algorithms should be used

PURGE_ALL

TIMESTAMP WITH TIME ZONE

A flag that can be passed to the PURGE_STATS Procedure and unconditionally deletes all the history statistics. The deletion uses TRUNCATE statements on the various dictionary statistics tables holding the history of statistics.

RECLAIM_SYNOPSIS

TIMESTAMP WITH TIME ZONE

A constant used for reclaiming synopsis table space.


2,失效时间

  • when DBMS_STATS modifies statistics for an object, all current cached cursors depending on this object are marked for rolling invalidation. Let's call this time T0.
  • the next time a session executes a cursor marked for rolling invalidation, it sets a timestamp. This timestamp can take a (pseudo-)random value up to _optimizer_invalidation_period sec from the time of this parse. The reason it does this is to randomly distribute the actual invalidation so as to avoid multiple parses occurring at the same time as much as possible.The default for this parameter is 18000 sec i.e. 5 hours. Let's call the time of this parse T1 and the timestamp value Tmax. On this (first) execution and parse we reuse the existing cursor i.e. we do not hard-parse and do not use the modified statistics to generate a new plan (it is a soft parse.)
  • on every subsequent execution and  parse of this cursor (which is now marked for rolling invalidation and timestamped) we check whether the current time T2 exceeds the timestamp Tmax. If not, we reuse the existing cursor again, as happened on the first (soft) parse at time T1. If Tmax has been exceeded, we invalidate the cached cursor and create a new version of it (a new child cursor) which uses the new statistics of the object to generate its execution plan. The new child is marked ROLL_INVALID_MISMATCH in V$SQL_SHARED_CURSOR to explain why we could not share the previous child.
  • the next time a session executes a cursor marked for rolling invalidation, it sets a timestamp. This timestamp can take a (pseudo-)random value up to _optimizer_invalidation_period sec from the time of this parse. The reason it does this is to randomly distribute the actual invalidation so as to avoid multiple parses occurring at the same time as much as possible.The default for this parameter is 18000 sec i.e. 5 hours. Let's call the time of this parse T1 and the timestamp value Tmax. On this (first) execution and parse we reuse the existing cursor i.e. we do not hard-parse and do not use the modified statistics to generate a new plan (it is a soft parse.)



Resolving Issues Where Dbms_stats Invalidates Cursors in Auto_invalidate mode (Doc ID 1477717.1)

Rolling Cursor Invalidations with DBMS_STATS.AUTO_INVALIDATE (Doc ID 557661.1)
























相关文章
|
6天前
|
SQL Oracle 关系型数据库
Oracle游标的使用和优化技巧
Oracle游标的使用和优化技巧
|
2天前
|
SQL 存储 Oracle
Oracle数据库中游标的工作原理与优化方法
Oracle数据库中游标的工作原理与优化方法
|
4天前
|
SQL Oracle 关系型数据库
Oracle游标的使用和优化技巧
Oracle游标的使用和优化技巧
|
7天前
|
SQL Oracle 关系型数据库
Oracle游标的定义与使用
Oracle游标的定义与使用
|
7天前
|
SQL Oracle 关系型数据库
Oracle游标的定义与使用技巧
Oracle游标的定义与使用技巧
|
2天前
|
Oracle 关系型数据库
oracle收集统计信息,游标失效时间
Dbms_stats Invalidates Cursors in Auto_invalidate mode
5 0
|
4天前
|
SQL 存储 Oracle
Oracle数据库中游标的工作原理与优化方法
Oracle数据库中游标的工作原理与优化方法
|
12天前
|
SQL Oracle 关系型数据库
Oracle中的游标用法总结
Oracle中的游标用法总结
|
12天前
|
SQL Oracle 关系型数据库
Oracle游标深入探讨
Oracle游标深入探讨
|
2月前
|
SQL Oracle 关系型数据库
Oracle的PL/SQL游标自定义异常:数据探险家的“专属警示灯”
【4月更文挑战第19天】Oracle PL/SQL中的游标自定义异常是处理数据异常的有效工具,犹如数据探险家的警示灯。通过声明异常名(如`LOW_SALARY_EXCEPTION`)并在满足特定条件(如薪资低于阈值)时使用`RAISE`抛出异常,能灵活应对复杂业务规则。示例代码展示了如何在游标操作中定义和捕获自定义异常,提升代码可读性和维护性,确保在面对数据挑战时能及时响应。掌握自定义异常,让数据管理更从容。

推荐镜像

更多