Adaptive Cursor Sharing: Overview (文档 ID 740052.1)

In this Document

 Purpose
 Scope
 Details
 Introduction
 Advantages and Disadvantages of Adaptive Cursor Sharing
 Advantages of Adaptive Cursor Sharing
 Disadvantages of Adaptive Cursor Sharing
 Extended Cursor Sharing (Bind Sensitivity)
 Adaptive Cursor Sharing (Bind Aware)
 Monitoring
 Known Issues with Excessive Child Cursors
 References

APPLIES TO:

Oracle Database - Enterprise Edition - Version 11.1.0.6 and later
Information in this document applies to any platform.

PURPOSE

The purpose of this document is to provide an overview to the Adaptive Cursor Sharing (ACS) feature that was introduced in 11g

SCOPE

The document contains a basic overview and background as well as issues that customers should be aware of.

DETAILS

Introduction

With the introduction of the Cost Based Optimizer (CBO) a number of changes were made to calculate the selectivity of a predicate, which in turn affected how the query was optimized.  The selectivity was based on the number of distinct values for a given column or a predefined percentage of rows depending on the relational operator that was used. For more details on predicate selectivity see:

Document 68992.1  Predicate Selectivity

This worked well for data that was evenly distributed but had limitations in applications where data was skewed.

With 9i, a new feature "Bind Peeking" was introduced to try to get around the issues associated with the selectivity of a bind variable. During hard parsing of a query using bind variables, the binds are "peeked at" and selectivity is generated based on the bind and the underlying column statistics. This method is successful but if the bind selectivity of the initial execution of a statement varied from the selectivity of subsequent executions with different sets of binds this could sometimes lead to plans being generated that were not representative of the general query usage and which performed poorly.

In Oracle 10g, this was especially noticeable since the default statistic gathering methodology changed to gather histograms automatically. This meant that selectivity previously generated based on the number of distinct values was now generated based on histograms. This gave the optimizer better information about the distribution of skewed data, the impact of which being that the first execution of a query using binds that were representative of the general query usage was particularly important. For more information on this see:

Document 387394.1 Query using Bind Variables is suddenly slow
Document 430208.1 Bind Peeking By Example

In Oracle 11g, Adaptive Cursor Sharing was introduced to provide a solution to these issues. Adaptive Cursor Sharing monitors the execution statistics for candidates queries and makes it possible for the same query to generate and use different execution plans for different set of binds values. See:

 

Advantages and Disadvantages of Adaptive Cursor Sharing

Advantages of Adaptive Cursor Sharing

Adaptive cursor sharing is a solution to provide the shareability of binds, with the plan adaptability of literals. 
With adaptive cursor sharing the database can adapt execution plans based on the selectivity of values used in bind variables. This resolves the situation where the plan used for one set of bind variables is inappropriate for another set.

Previously, workarounds employed would either use literal values instead of binds, which could lead to excessive hard parsing, or apply a fixed plan that could cause performance issues.

Disadvantages of Adaptive Cursor Sharing

There may be some extra overhead associated with Adaptive Cursor Sharing:

  • More Hard Parses (CPU) - Extra Hard Parses will be required when a cursor becomes "Bind Aware" as we attempt to generate the better matched execution plans for the bind selectivity.
  • More Child Cursors (SGA) - It is recommended that some consideration be taken to increase the size of the shared_pool on upgrade from 10g to 11g, given the extra cursors that may be required to accommodate this feature.
  • More Work to Match the Cursor (CPU) - More Child Cursors and the requirement to match a query to the best execution plan for its predicate selectivity.
  • If you encounter an issue with query performance, in some cases ACS may make the issue more difficult to identify and repeat if a new plan is generated and accepted that then makes the problem "disappear". The other side to this is that the query now performs better without user intervention.

Extended Cursor Sharing (Bind Sensitivity)

The first step towards ACS is Extended Cursor Sharing - where a query is recognised as "Bind Sensitive". This means that the best plan for a query has potential to be different according to the bind variables supplied to it. In effect this just means the cursor is being monitored to see if it should be made bind aware.

A cursor is marked as Bind Sensitive if:

  • query is executed with bind peeking

  • binds using any of the following relational operators = < > <= >= != or a user defined bind operator e.g. contains(e.job,:job,1)>0, 
    From 11.2.0.2 the "LIKE" operator is also supported.

  • A histogram exists on the column containing the bind value.

In other words, a cursor is marked Bind Sensitive if a change in the bind variable value may lead to a different plan.

Apart from checking for a valid operator there are also a number of subsequent bind sensitivity checks that need to be performed before it can be marked as bind sensitive. If any of these checks fail, the cursor will not be marked as bind sensitive and adaptive cursor sharing will not occur and Extended Cursor Sharing will be disabled :-

  • Extended cursor sharing has been disabled
  • The query has no binds
  • Parallel query is used
  • Certain parameters like ("_optim_peek_user_binds"=false) are set
  • You are using a /*+ NO_BIND_AWARE */ hint
  • Outlines are being used
  • Query is recursive
  • The number of binds in a given sql statement is greater than 14.

SQL Plan Baselines are designed to work with Adaptive Cursor Sharing.  Any valid enabled SQL Plan Baselines Plans can be used by Adaptive Cursor Sharing.  This means if you have more than one enabled baseline for a given SQL statement ACS can use one or more of those baselines at the same time. 

 

When all the criteria are met the cursor is marked as bind sensitive and a "sharing context" containing information about execution statistics of the cursor is created and stored against the cursor.

Cursors that are marked as bind-sensitive can been identified by the column IS_BIND_SENSITIVE having a value "Y" in V$SQL or V$SQLAREA.

Adaptive Cursor Sharing (Bind Aware)

If there is significant variation in the row source cardinality for executions of the same sql statement in consecutive executions a cursor will be marked as bind aware.
For more information about this please see :-

Document 836256.1 Adaptive Cursor Sharing: Worked Example
Document 1115994.1 Introduction to Adaptive Cursor Sharing Concepts and Multimedia Demo [Video]

https://blogs.oracle.com/optimizer/entry/why_are_there_more_cursors_in_11g_for_my_query_containing_bind_variables_1

 

Monitoring

V$SQL can be used to see whether  a cursor is_bind_sensitive, is_bind_aware, or is_shareable.
Bind context information can be viewed via V$SQL_CS_SELECTIVITY, V$SQL_CS_STATISTICS and V$SQL_CS_HISTOGRAM

V$SQL_CS_SELECTIVITY displays  the valid selectivity ranges for a child cursor in extended cursor sharing mode. 
A valid range consists of a low and high value for each predicate containing binds. Each predicate's selectivity (with the current bind value) must fall between the corresponding low and high values in order for the child cursor to be shared.

V$SQL_CS_STATISTICS contains the raw execution statistics used by the monitoring component of adaptive cursor sharing. 
A sample of the executions is monitored. This view shows which executions were sampled, and what the statistics were for those executions. The statistics are cumulative for each distinct set of bind values.

V$SQL_CS_HISTOGRAM summarizes the monitoring information stored by adaptive cursor sharing.
This information is used to decide whether to enable extended cursor sharing for a query. It  is stored in a histogram, whose bucket's contents are exposed by this view.

Known Issues with Excessive Child Cursors

There is a possibility that Adaptive Cursor Sharing may compound problems in which excessive numbers of child cursors are generated.  This may lead to performance degradation as large numbers of child cursor can put space pressure on the shared pool and may also lead to an increase in mutex X waits for that cursor.

Checklist to avoid known issues
1. Ensure that cursor_sharing is not set to SIMILAR. In 11g  this setting is not recommended and is deprecated in future releases.

Document 1169017.1:ANNOUNCEMENT: Deprecating the cursor_sharing = 'SIMILAR' setting

2. If there are high version counts check v$sql_shared_cursor and search My Oracle Support for notes that may allude to the cause of the excessive cursors.

Document 438755.1 : Formated V$SQL_SHARED_CURSOR Report by SQLID or Hash Value

If there are still excessive child cursors, then Oracle Support should be contacted to assist with diagnosing the issue.

REFERENCES

NOTE:1518681.1 - FAQ: Adaptive Cursor Sharing (ACS) Frequently Asked Questions
NOTE:13456573.8 - Bug 13456573 - Many child cursors / ORA-4031 with large allocation in KGLH0 using extended cursor sharing
NOTE:6644714.8 - Bug 6644714 - High number of child cursors with adaptive cursor sharing

NOTE:430208.1 - Bind Peeking By Example
NOTE:68992.1 - Predicate Selectivity
NOTE:1169017.1 - ANNOUNCEMENT: Deprecating the cursor_sharing = 'SIMILAR' setting
NOTE:387394.1 - Query using Bind Variables is suddenly slow
NOTE:1115994.1 - Introduction to Adaptive Cursor Sharing Concepts and Multimedia Demo [Video]
NOTE:836256.1 - Adaptive Cursor Sharing: Worked Example
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值