天天看點

【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1) 【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1)

【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1)

APPLIES TO:

Oracle Database - Personal Edition - Version 7.1.4.0 and later

Oracle Database - Enterprise Edition - Version 6.0.0.0 and later

Oracle Database - Standard Edition - Version 7.0.16.0 and later

Information in this document applies to any platform.

PURPOSE

This Document outlines some of the limitations that may be encountered when using the Cost Based Optimizer.

SCOPE

Cost Based Optimizer Limitations

The Cost Based Optimizer (CBO) uses a complex and comprehensive model to choose the plan with the lowest cost overall. In most cases the model picks the best access methods for accessing the data in the most efficient manner. However, even with computed statistics and column histograms it is possible for the Cost Based Optimizer to choose a sub-optimal plan. There are limitations to the Cost model that can affect queries in some circumstances. Some of these are listed and explained below:

DETAILS

  • Potential for incorrect estimation of intermediate result set cardinality

    Cardinality is the CBO estimate of the number of rows produced by a row source or combination of row sources. In some cases, the cardinality of result sets can be miscalculated. This is most common with complex predicates where the statistics do not accurately reflect the data or where predicate values are correlated. The following is an illustration of a statement featuring correlated predicates:

    select ename from emp where sal >= 25000 and job = 'PRESIDENT';

    In this example there is a hidden correlation between the data values in the sal and job columns. Only the president earns more than $25,000. There are no employees with a "sal >= 25000" who are not 'PRESIDENT'. The optimizer has no way of determining that such a correlation exists and would treat the 2 columns as though their values were independent of each other. This would result in an underestimation of the selectivity of the predicates and thus an inaccurate cardinality estimate. 

    NOTE:  11g and above addresses this issue by providing the facility to create extended statistics in the form of column groups . See:

    Note:452883.1  MultiColumn/Column Group Statistics Examples (Doc ID 452883.1) 

    This only addresses cases where there is a correlation between columns in the same table. Correlation in different tables is not resolved by this.  

  • Assumption that all statements run standalone

    Since the CBO assumes that all statements run standalone, it may underestimate the volume of data that has been cached as a result of other statements running previously or concurrently. This can result in significant over estimation of the cost of index accesses which can read from cached data rather than having to retrieve the data from disk. The parameters <Parameter:OPTIMIZER_INDEX_CACHING> and <Parameter:OPTIMIZER_INDEX_COST_ADJ> can be used to modify these costs to reflect the characteristics of the system in question. 

    Another example of the situation not taken into account by the optimizer is block contention, which occurs at times of heavy concurrent access to the same blocks from SQLs running in other sessions. Such contention may be seen for example as 'buffer busy waits' and/or 'latch free' waits for 'cache buffers chains' latches. At this stage of the CBO evolution it is not clear how the 'run time' database statistics can be accounted by the CBO and whether at all it may be useful.

  • Histogram bucket limitations

    Histograms are limited to 254 buckets so if there are more than 254 distinct values and there is no single value that dominates the column's dataset then histograms may not provide helpful statistics. With large numbers of distinct values, histogram usage can be further impacted because differences in non popular values cannot be recorded. The choice of 254 buckets per column histogram was a balance between accuracy of the statistics and the speed of histogram collection/amount of space required to store the information.

    As of 12c, the maximum possible number of buckets in a histogram increases from 254 to 2,048.

  • Limitations of Histogram on Character Columns

    Histograms only store the first 32 characters of a character string (5 characters pre 8.1.6 See Bug:598799 ). If histograms are gathered on character columns that have data that is longer than 31 characters and the first 31 characters are identical then column histograms may not reflect the cardinality of these columns correctly as these values will all be treated as if they are identical. There are also similar limits with numeric data which is normalised to 15 digits in histogram endpoints.

    As of 12c, the maximum possible number of characters considered for a histogram on a string column increases from thirty-two to sixty-four.

  • Bind Variables

    Bind variables are recommended for situations where cursors are frequently executed with different column values and would otherwise cause shared pool fragmentation and contention. 

    Historically, the optimizer generated a single access path for an identical shared query featuring bind variables. 

    Prior to 9i, the optimizer did not know the value of the bind variable when the plan was determined which could result in a sub-optimal plan, since the 'average' statistic may not reflect the actuality of the data in all cases. 

    Since Bind variable peeking was introduced in Oracle 9i, the plan is based upon the first value that is bound to the variable. However, where column data is non-uniform a non-representative value can deliver inconsistent performance for queries using different bind variable values. 

    From the optimizer point of view, it is recommended to use literal values where there is the possibility of significant performance differences associated with using different bind variable values and applying the same plan for all executions. In these cases the choice of a good plan usually significantly outweighs the potential usage of shared pool space (assuming that the shared pool usage is not excessive). See:

    Note:70075.1  Use of bind variables in queries

    In later versions, features such as Adaptive Cursor Sharing and SQL Plan Management can be used to manage queries utilizing bind variables in a more flexible manner and make better decisions on what execution plans should and should not be shared. See:

    Note:1359841.1  Plan Stability Features (Including SPM) Start Point

    Note:1115994.1  Introduction to Adaptive Cursor Sharing concepts in 11G and mutimedia demo [Video]

    Note:836256.1  Adaptive Cursor Sharing in 11G

    Note:740052.1  Adaptive Cursor Sharing Overview

  • Subquery Unnesting and View Merging

    Oracle exhaustively attempts to transform statements containing subqueries and views in to simpler statements. The goal of this activity is to make more access paths accessible and find the optimal plan. However, Subquery Unnesting and View Merging is a heuristic process. Subqueries are unnested and views are merged based upon a set of rules. No costs are generated and compared back to the unchanged statement. This could mean that the transformed statement does not perform as well as the untransformed one.

    N.B. Oracle 10G introduces Costed Subquery Unnesting and View Merging which should go some way to alleviating the effects of this limitation

  • Join Permutations

    The CBO evaluates each permutation of tables up to a predefined limit (<Parameter:optimizer_max_permutations>). As the number of tables involved in a query increases, so the total number of permutations increases. Soon the number that can be evaluated in a realistic timeframe is a minute proportion of the total. There are a large number of adjustments that occur within the optimization process to attempt to minimise the possibility of a good candidate being overlooked, but it is possible that the optimizer may not even consider the most optimal join order and method in large queries. The following article has more detail on optimizer permutations: 

    Note:73489.1  Affect of Number of Tables on Join Order Permutations

Potential workarounds for these issues

Workarounds for these issues typically include hinting the correct plan or using stored outlines. Enhancements to alleviate the affects of some of these issues are expected in future versions.

REFERENCES

NOTE:70075.1  - Use of Bind Variables in Queries (Pre-9i)

NOTE:73489.1  - Effect of Number of Tables on Join Order Permutations

NOTE:740052.1  - Adaptive Cursor Sharing: Overview

NOTE:836256.1  - Adaptive Cursor Sharing: Worked Example

BUG:598799  - INCORRECT CARDINALITY AFTER COMPUTING HISTOGRAMS

NOTE:1115994.1  - Introduction to Adaptive Cursor Sharing Concepts and Multimedia Demo [Video]

NOTE:1359841.1  - Master Note: Plan Stability Features (Including SQL Plan Management (SPM))

NOTE:163563.1  - * TROUBLESHOOTING: Advanced Query Tuning

NOTE:452883.1  - MultiColumn/Column Group Statistics Examples

About Me

...............................................................................................................................

● 本文來自MOS, (文檔 ID 212809.1)

● 本文在itpub(http://blog.itpub.net/26736162)、部落格園(http://www.cnblogs.com/lhrbest)和個人微信公衆号(xiaomaimiaolhr)上有同步更新

● 本文itpub位址:http://blog.itpub.net/26736162/abstract/1/

● 本文部落格園位址:http://www.cnblogs.com/lhrbest

● 本文pdf版及小麥苗雲盤位址:http://blog.itpub.net/26736162/viewspace-1624453/

● 資料庫筆試面試題庫及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● QQ群:230161599     微信群:私聊

● 聯系我請加QQ好友(646634621),注明添加緣由

● 于 2017-06-02 09:00 ~ 2017-06-30 22:00 在魔都完成

● 文章内容來源于小麥苗的學習筆記,部分整理自網絡,若有侵權或不當之處還請諒解

● 版權所有,歡迎分享本文,轉載請保留出處

...............................................................................................................................

拿起手機使用微信用戶端掃描下邊的左邊圖檔來關注小麥苗的微信公衆号:xiaomaimiaolhr,掃描右邊的二維碼加入小麥苗的QQ群,學習最實用的資料庫技術。

【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1) 【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1)
【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1) 【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1)
【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1) 【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1)
【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1) 【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1)
【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1) 【MOS】Limitations of the Oracle Cost Based Optimizer (文檔 ID 212809.1)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2140620/,如需轉載,請注明出處,否則将追究法律責任。

轉載于:http://blog.itpub.net/26736162/viewspace-2140620/