prompt
prompt 创建表eoda.t
declare 
    num number;
begin
    select count(1) into num from all_tables where table_name = upper( 't' ) and owner = upper( 'eoda' );
    if num = 1 then
        execute immediate 'drop table eoda.t';
    end if;
    execute immediate '
        create table eoda.t
        (
            x   int   constraint  x_not_null not null deferrable,
            y   int   constraint  y_not_null not null,
            z   varchar2(30)
        )
    ';
end;
/

prompt
prompt 插入数据到eoda.t
begin
    insert into eoda.t( x,y,z ) select rownum,rownum,rpad( 'x',30,'x' ) from all_users;
    commit;
end;
/
prompt
prompt 收集数据
begin 
    dbms_stats.gather_table_stats ( user,'T' );
end;
/

prompt
prompt 创建索引eoda.t_index在edoa.t(y)
declare
    num number;
begin
    select count(1) into num from user_indexes where index_name = upper( 't_index' ) and table_name = upper( 't' ) and table_owner = upper( 'eoda' );
    if num = 1 then
        execute immediate 'drop index eoda.t_index';
    end if;
    execute immediate '
        create index eoda.t_index on eoda.t(y)
    ';
end;
/

explain plan for select count(*) from eoda.t;
select * from table(dbms_xplan.display( null,null,'BASIC' )); 

prompt
prompt 创建索引eoda.t_index在edoa.t(x)
declare
    num number;
begin
    select count(1) into num from user_indexes where index_name = upper( 't_index' ) and table_name = upper( 't' ) and table_owner = upper( 'eoda' );
    if num = 1 then
        execute immediate 'drop index eoda.t_index';
    end if;
    execute immediate '
        create index eoda.t_index on eoda.t(x)
    ';
end;
/

explain plan for select count(*) from eoda.t;
select * from table(dbms_xplan.display( null,null,'BASIC' )); 

prompt
prompt 修改eoda.t中x列的约束是不可延迟约束x_not_null
begin
    alter table eoda.t drop constraint x_not_null;
    alter table eoda.t modify x constraint x_not_null not null;
end;
/

explain plan for select count(*) from eoda.t;
select * from table(dbms_xplan.display( null,null,'BASIC' )); 
