[20120905]删除直方图.txt

[20120905]删除直方图.txt
维护直方图是一个成本很高的操作,9i的缺省模式Method_Opt=> 'FOR ALL COLUMNS SIZE REPEAT ',而10g的缺省模式
Method_Opt => 'FOR ALL COLUMNS SIZE AUTO ',这样会导致在许多不必要的字段建立直方图。
我自己在维护10g的数据库也存在许多sql执行计划不稳定的情况,我后来采取的方法就是把这些控制在自己的手中。
修改10g的缺省模式为Method_Opt=> 'FOR ALL COLUMNS SIZE REPEAT ',这样把直方图的建立控制在自己管理的范围内。
SQL> column x format a30
SQL> select DBMS_STATS.get_param('METHOD_OPT') x from dual;
X
------------------------------
FOR ALL COLUMNS SIZE AUTO
SQL> exec DBMS_STATS.SET_PARAM(pname => 'METHOD_OPT', pval => 'FOR ALL COLUMNS SIZE REPEAT');

--但是删除建立的直方图,一直没有好方法。今天看书,发现11G下很容易操作:文档如下:
procedure delete_column_stats(
        ownname varchar2, tabname varchar2, colname varchar2,
        partname varchar2 default null,
        stattab varchar2 default null, statid varchar2 default null,
        cascade_parts boolean default true,
        statown varchar2 default null,
        no_invalidate boolean default
          to_no_invalidate_type(get_param('NO_INVALIDATE')),
        force boolean default FALSE,
        col_stat_type varchar2 default 'ALL');
--
-- Deletes column-related statistics
--
-- Input arguments:
--   ownname - The name of the schema
--   tabname - The name of the table to which this column belongs
--   colname - The name of the column or extension
--   partname - The name of the table partition for which to delete
--      the statistics.  If the table is partitioned and partname
--      is null, global column statistics will be deleted.
--   stattab - The user stat table identifier describing from where
--      to delete the statistics.  If stattab is null, the statistics
--      will be deleted directly from the dictionary.
--   statid - The (optional) identifier to associate with these statistics
--      within stattab (Only pertinent if stattab is not NULL).
--   cascade_parts - If the table is partitioned and partname is null,
--      setting this to true will cause the deletion of statistics for
--      this column for all underlying partitions as well.
--   statown - The schema containing stattab (if different then ownname)
--   no_invalidate - Do not invalide the dependent cursors if set to TRUE.
--      The procedure invalidates the dependent cursors immediately
--      if set to FALSE.
--      Use DBMS_STATS.AUTO_INVALIDATE to have oracle decide when to
--      invalidate dependend cursors. This is the default. The default
--      can be changed using set_param procedure.
--   force - delete statistics even if it is locked
--   col_stat_type - Type of column statitistics to be deleted.
--                   This argument takes the following values:
--                   'HISTOGRAM' - delete column histogram only
--                   'ALL' - delete base column stats and histogram
--
-- Exceptions:
--   ORA-20000: Object does not exist or insufficient privileges
--   ORA-20002: Bad user statistics table, may need to upgrade it
--   ORA-20005: object statistics are locked
--
建立测试例子操作如下:
SQL> select * from v$version ;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
create table t as select rownum id1 , mod(rownum,100)+1 id2, 'test' name from dual connect by level
select column_name,histogram from dba_tab_columns where table_name='T';
SQL> select column_name,histogram from dba_tab_columns where wner=user and table_name='T';
COLUMN_NAME                    HISTOGRAM
------------------------------ ---------------
ID1                            NONE
ID2                            NONE
NAME                           NONE

SQL> execute dbms_stats.gather_table_stats(user,'t',cascade=>true,method_opt=>'for all columns size 1');
PL/SQL procedure successfully completed.
SQL> select column_name,histogram from dba_tab_columns where wner=user and table_name='T';
COLUMN_NAME                    HISTOGRAM
------------------------------ ---------------
ID1                            NONE
ID2                            NONE
NAME                           NONE
--以前采用的方法!这样要重新分析表。太麻烦了。

SQL> execute dbms_stats.gather_table_stats(user,'t',cascade=>true,method_opt=>'for all columns size 1,for columns id1 size 254 ,for columns id2 size 254');
PL/SQL procedure successfully completed.
SQL> select column_name,num_distinct,histogram from dba_tab_columns where wner=user and table_name='T';
COLUMN_NAME                    NUM_DISTINCT HISTOGRAM
------------------------------ ------------ ---------------
ID1                                   10000 HEIGHT BALANCED
ID2                                     100 FREQUENCY
NAME                                      1 NONE

--如果执行如下命令,统计信息也删除了。因为缺省是col_stat_type varchar2 default 'ALL'。
SQL> execute dbms_stats.delete_column_stats(ownname=>user,tabname=>'t',colname=>'id2');
PL/SQL procedure successfully completed.
SQL> select column_name,num_distinct,histogram from dba_tab_columns where wner=user and table_name='T';
COLUMN_NAME                    NUM_DISTINCT HISTOGRAM
------------------------------ ------------ ---------------
ID1                                   10000 HEIGHT BALANCED
ID2                                         NONE
NAME                                      1 NONE
--删除直方图id2字段。
SQL> execute dbms_stats.gather_table_stats(user,'t',cascade=>true,method_opt=>'for all columns size 1,for columns id1 size 254 ,for columns id2 size 254');
PL/SQL procedure successfully completed.
SQL> execute dbms_stats.delete_column_stats(ownname=>user,tabname=>'t',colname=>'id2',col_stat_type=>'histogram');
PL/SQL procedure successfully completed.
SQL> select column_name,num_distinct,histogram from dba_tab_columns where wner=user and table_name='T';
COLUMN_NAME                    NUM_DISTINCT HISTOGRAM
------------------------------ ------------ ---------------
ID1                                   10000 HEIGHT BALANCED
ID2                                     100 NONE
NAME                                      1 NONE
--听说还有另外一种方法,就是人为地修改统计字段的一些属性,比如distcnt。测试如下:
SQL> select column_name,num_distinct,histogram from dba_tab_columns where wner=user and table_name='T';
COLUMN_NAME                    NUM_DISTINCT HISTOGRAM
------------------------------ ------------ ---------------
ID1                                   10000 HEIGHT BALANCED
ID2                                     100 NONE
NAME                                      1 NONE
SQL> execute dbms_stats.set_column_stats(ownname=>user,tabname=>'T',colname=> 'id1',distcnt=>1e4);
PL/SQL procedure successfully completed.
SQL> select column_name,num_distinct,histogram from dba_tab_columns where wner=user and table_name='T';
COLUMN_NAME                    NUM_DISTINCT HISTOGRAM
------------------------------ ------------ ---------------
ID1                                   10000 NONE
ID2                                     100 NONE
NAME                                      1 NONE
--可以发现直方图ID1也删除了.
SQL> column ENDPOINT_ACTUAL_VALUE noprint
SQL> select * from dba_tab_histograms where wner=user and table_name='T' and column_name='ID1';
OWNER                          TABLE_NAME COLUMN_NAM ENDPOINT_NUMBER ENDPOINT_VALUE
------------------------------ ---------- ---------- --------------- --------------
SCOTT                          T          ID1                      0              1
SCOTT                          T          ID1                      1          10000
--这个在10g也许是最快的方法!
				
时间: 2024-08-30 11:57:31

[20120905]删除直方图.txt的相关文章

[20140505]删除直方图_delete histogram

[20140505]删除直方图_delete histogram.txt   昨天看了https://jonathanlewis.wordpress.com/2014/05/01/delete-histogram/ 介绍删除直方图的方法,这样比较快捷. SCOTT@test> @ver BANNER -------------------------------------------------------------------------------- Oracle Database 11

[20170114]12c varchar2类型直方图.txt

[20170114]12c varchar2类型直方图.txt --我曾经提到慎用nvarchar2数据类型,链接:http://blog.itpub.net/267265/viewspace-2120925/ --我那里提到数据类型nvarchar2类型,因为1个字符占用2个字节,这样如果前面16个字符重复很多,直方图的建立就是鸡肋, --毫无用处(因为分析仅仅对前面32个字节有效),12c 直方图支持更多类型: 高度直方图,频率直方图.混和类型(HYBRID). --看看12c关于直方图方面

[20160526]bbed修复删除记录.txt

[20160526]bbed修复删除记录.txt --以前也做过,链接: http://blog.itpub.net/267265/viewspace-745944/ --自己当时完全是依葫芦画瓢,许多东西理解不深刻,重新做一次. 1.环境: 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ------------------------------ --------------

[20160722]对象C_OBJ#_INTCOL#有坏块.txt

[20160722]对象C_OBJ#_INTCOL#有坏块.txt --前几天看到的帖子,一直没时间测试,链接如下: http://www.itpub.net/thread-2063836-1-1.html --我以前按照eygle的链接http://www.eygle.com/archives/2012/05/event_38003_c_obj_intcol.html做过测试,测试在11.2.0.2下做的. --通过设置alter system set event='38003 trace n

[20160516]统计分析参数method_opt.txt

[20160516]统计分析参数method_opt.txt --统计分析参数method_opt我个人感觉是最能折腾人的参数.我自己曾经在这个参数上栽过跟头,通过例子来说明看看. 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- ------------------------------

[20130528]dbms_stats.gather_table_stats的method_opt.txt

[20130528]dbms_stats.gather_table_stats的method_opt.txt 同事想删除某个表的直方图信息,结果老是删除不掉.问我,我看了一下,马上明白使用参数错误,他使用的是method_opt=>'for columns size 1'.缺少了all参数.应该写成method_opt=>'for all columns size 1'. 实际上这个问题我以前做一些测试的时候我就发现,一直没有好好的总结.找个机会总结一下. 1.测试环境: SQL> @v

GOOGLE网站管理员工具删除网址功能一定要慎用

由于网站改版,以前GOOGLE收录的网址不想要了,前段时间通过GOOGLE管理员工具删除了所有网址,想让GOOGLE重新收录,结果改版完了导致GOOGLE一个多星期不收录我的站.   以上是四天百度和GOOGLE收录数量记录,前几天的查不到了,改版前谷歌收录大概是7000左右. 以下是改版完以后的操作与大家分享一下: 因为怕网站未改版期间未完成的页面被收录,所以在网站根目录上传了robots.txt禁止所有搜索引擎收录,大概一个星期左右百度就把旧页面删除了,就留了3个页面,效率还是很快的,4月2

Java:文件的建立与删除

文件的建立与删除 首先取得当前的磁盘路径,指定要建立的文件的路径,再进行检查,如果文件不存在,如果文件不存在,则建立这个文件,如果文件存在,则删除这个文件. CreateDelete.jsp <%@ page contentType="text/html; charset=GB2312"%> <%@ page import="java.io.*" %> <%@ page language="java" %> &

Linux如何使用inode删除文件

  文件的inode定义了文件的大小.所有人等文件的特征.每个文件和目录都有自己唯一的inode数字.但是为什么用inode来删除文件,而不是用常用的rm -rf命令呢?原因是,如果你不小心创建了含有特殊字符的文件和目录,比如带有 ? * ^ 的文件名,就会很难删除.下面我们就来介绍一下:1)如何找出文件和目录的inode;2)配合find命令,删除特定的inode文件;3)其他有用的删除顽固文件的方法. * 如何找出文件的inode? 用stat 或者ls -il .带有 -i 参数的ls命令