<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Neil的備忘錄

    just do it
    posts - 66, comments - 8, trackbacks - 0, articles - 0

    Cost Based Optimizer (CBO) and Database Statistics

    Posted on 2009-01-19 16:00 Neil's NoteBook 閱讀(303) 評論(0)  編輯  收藏 所屬分類: ORACLE
    Whenever a valid SQL statement is processed Oracle has to decide how to retrieve the necessary data. This decision can be made using one of two methods:
    • Rule Based Optimizer (RBO) - This method is used if the server has no internal statistics relating to the objects referenced by the statement. This method is no longer favoured by Oracle and will be desupported in future releases.
    • Cost Based Optimizer (CBO) - This method is used if internal statistics are present. The CBO checks several possible execution plans and selects the one with the lowest cost, where cost relates to system resources.
    If new objects are created, or the amount of data in the database changes the statistics will no longer represent the real state of the database so the CBO decision process may be seriously impaired. The mechanisms and issues relating to maintenance of internal statistics are explained below:

    Analyze Statement

    The ANALYZE statement can be used to gather statistics for a specific table, index or cluster. The statistics can be computed exactly, or estimated based on a specific number of rows, or a percentage of rows:
    ANALYZE TABLE employees COMPUTE STATISTICS;
    ANALYZE INDEX employees_pk COMPUTE STATISTICS;

    ANALYZE TABLE employees ESTIMATE STATISTICS SAMPLE 100 ROWS;
    ANALYZE TABLE employees ESTIMATE STATISTICS SAMPLE 15 PERCENT;

    DBMS_UTILITY

    The DBMS_UTILITY package can be used to gather statistics for a whole schema or database. Both methods follow the same format as the analyze statement:
    EXEC DBMS_UTILITY.analyze_schema('SCOTT','COMPUTE');
    EXEC DBMS_UTILITY.analyze_schema('SCOTT','ESTIMATE', estimate_rows => 100);
    EXEC DBMS_UTILITY.analyze_schema('SCOTT','ESTIMATE', estimate_percent => 15);

    EXEC DBMS_UTILITY.analyze_database('COMPUTE');
    EXEC DBMS_UTILITY.analyze_database('ESTIMATE', estimate_rows => 100);
    EXEC DBMS_UTILITY.analyze_database('ESTIMATE', estimate_percent => 15);

    DBMS_STATS

    The DBMS_STATS package was introduced in Oracle 8i and is Oracles preferred method of gathering object statistics. Oracle list a number of benefits to using it including parallel execution, long term storage of statistics and transfer of statistics between servers. Once again, it follows a similar format to the other methods:
    EXEC DBMS_STATS.gather_database_stats;
    EXEC DBMS_STATS.gather_database_stats(estimate_percent => 15);

    EXEC DBMS_STATS.gather_schema_stats('SCOTT');
    EXEC DBMS_STATS.gather_schema_stats('SCOTT', estimate_percent => 15);

    EXEC DBMS_STATS.gather_table_stats('SCOTT', 'EMPLOYEES');
    EXEC DBMS_STATS.gather_table_stats('SCOTT', 'EMPLOYEES', estimate_percent => 15);

    EXEC DBMS_STATS.gather_index_stats('SCOTT', 'EMPLOYEES_PK');
    EXEC DBMS_STATS.gather_index_stats('SCOTT', 'EMPLOYEES_PK', estimate_percent => 15);
    This package also gives you the ability to delete statistics:
    EXEC DBMS_STATS.delete_database_stats;
    EXEC DBMS_STATS.delete_schema_stats('SCOTT');
    EXEC DBMS_STATS.delete_table_stats('SCOTT', 'EMPLOYEES');
    EXEC DBMS_STATS.delete_index_stats('SCOTT', 'EMPLOYEES_PK');

    Scheduling Stats

    Scheduling the gathering of statistics using DBMS_Job is the easiest way to make sure they are always up to date:
    SET SERVEROUTPUT ON
    DECLARE
    l_job NUMBER;
    BEGIN

    DBMS_JOB.submit(l_job,
    'BEGIN DBMS_STATS.gather_schema_stats(''SCOTT''); END;',
    SYSDATE,
    'SYSDATE + 1');
    COMMIT;
    DBMS_OUTPUT.put_line('Job: ' || l_job);
    END;
    /
    The above code sets up a job to gather statistics for SCOTT for the current time every day. You can list the current jobs on the server using the DBS_JOBS and DBA_JOBS_RUNNING views.

    Existing jobs can be removed using:
    EXEC DBMS_JOB.remove(X);
    COMMIT;
    Where 'X' is the number of the job to be removed.

    Transfering Stats

    It is possible to transfer statistics between servers allowing consistent execution plans between servers with varying amounts of data. First the statistics must be collected into a statistics table. In the following examples the statistics for the APPSCHEMA user are collected into a new table, STATS_TABLE, which is owned by DBASCHEMA:
      SQL> EXEC DBMS_STATS.create_stat_table('DBASCHEMA','STATS_TABLE');
    SQL> EXEC DBMS_STATS.export_schema_stats('APPSCHEMA','STATS_TABLE',NULL,'DBASCHEMA');
    This table can then be transfered to another server using your preferred method (Export/Import, SQLPlus Copy etc.) and the stats imported into the data dictionary as follows:
      SQL> EXEC DBMS_STATS.import_schema_stats('APPSCHEMA','STATS_TABLE',NULL,'DBASCHEMA');
    SQL> EXEC DBMS_STATS.drop_stat_table('DBASCHEMA','STATS_TABLE');

    Issues

    • Exclude dataload tables from your regular stats gathering, unless you know they will be full at the time that stats are gathered.
    • I've found gathering stats for the SYS schema can make the system run slower, not faster.
    • Gathering statistics can be very resource intensive for the server so avoid peak workload times or gather stale stats only.
    • Even if scheduled, it may be necessary to gather fresh statistics after database maintenance or large data loads.
    For more information see:
    Hope this helps. Regards Tim...

    原文地址: http://www.oracle-base.com/articles/8i/CostBasedOptimizerAndDatabaseStatistics.php#AnalyzeStatement
    主站蜘蛛池模板: 亚洲精品女同中文字幕| 亚洲伊人色一综合网| 一级特黄色毛片免费看| 免费观看国产小粉嫩喷水| 亚洲字幕AV一区二区三区四区| 亚洲成AV人片在线观看无码| aaa毛片免费观看| 亚洲精品无码精品mV在线观看| 东方aⅴ免费观看久久av| 亚洲国产精品高清久久久| 日本免费一区二区久久人人澡| 久久综合图区亚洲综合图区| 日本免费污片中国特一级| 91情国产l精品国产亚洲区| 成年人网站免费视频| 最新亚洲卡一卡二卡三新区| 国产成人免费全部网站| 中文字幕无线码免费人妻| 亚洲av日韩av不卡在线观看| 日本免费xxxx| 亚洲国产成人精品无码区花野真一 | 老汉精品免费AV在线播放| 亚洲成a人片在线观看中文!!!| 成人女人A级毛片免费软件| 亚洲欧美日韩中文字幕一区二区三区 | 亚洲AV永久纯肉无码精品动漫| 中文字幕在线免费观看| 亚洲一区二区三区不卡在线播放| 成人午夜18免费看| 一级毛片免费不卡直观看| 亚洲αv久久久噜噜噜噜噜| 国产精品入口麻豆免费观看| 亚洲国产aⅴ成人精品无吗| 亚洲一区二区三区乱码A| 免费国产黄网站在线观看可以下载 | 国产精品无码永久免费888| 中文字幕亚洲综合精品一区| 日韩中文字幕免费| 久久久久久影院久久久久免费精品国产小说 | 亚洲国产V高清在线观看| 91视频免费网址|