#  ƼŴ

-- Ƽ 並    Base ̺ . 
create table p1 as select * from emp where deptno = 10;
create table p2 as select * from emp where deptno = 20;
create table p3 as select * from emp where deptno = 30;

-- üũ  ݵ ؾ 
alter table p1 add constraint c_deptno_10 check(deptno < 20);
alter table p2 add constraint c_deptno_20 check(deptno >= 20 and deptno < 30);
alter table p3 add constraint c_deptno_30 check(deptno >= 30 and deptno < 40);


create index p1_empno_idx on p1(empno);
create index p2_empno_idx on p2(empno);
create index p3_empno_idx on p3(empno);

analyze table p1 compute statistics;
analyze table p2 compute statistics;
analyze table p3 compute statistics;

-- Ƽ 並 Ѵ. 
create or replace view partition_view 
as
select * from p1
union all
select * from p2
union all
select * from p3 ;


explain plan for
select * from partition_view
where  deptno = :deptno ;

@?/rdbms/admin/utlxpls


explain plan for
select * from partition_view
where  deptno = :deptno
and    empno = :empno ;

@?/rdbms/admin/utlxpls


# Ƽ ̺
create table partition_table
partition by range(deptno) (
  partition p1 values less than(20)
, partition p2 values less than(30)
, partition p3 values less than(40)
)
as
select * from emp ;

create index ptable_empno_idx on partition_table(empno) LOCAL;


