分区表

创建分区表

SQL> create tablespace t1 datafile '/home/oracle/t1.dbf' size 10M;
Tablespace created.

SQL> create tablespace t2 datafile '/home/oracle/t2.dbf' size 10M;
Tablespace created.

SQL> create tablespace t3 datafile '/home/oracle/t3.dbf' size 10M;
Tablespace created.

SQL> create table t_chen(id number) partition by range(id)
  2  (partition part_01 values less than(10) tablespace t1,
  3   partition part_02 values less than(20) tablespace t2,
  4   partition part_03 values less than(maxvalue) tablespace t3);
Table created.

SQL> declare
  2  begin
  3  for i in 1..35 loop
  4  insert into t_chen id values(i);
  5  end loop;
  6  end;
  7  /

PL/SQL procedure successfully completed.

SQL> select * from t_chen where id between 0 and 9;
Execution Plan
----------------------------------------------------------
Plan hash value: 4068516938
-------------------------------------------------------------------------------------------------
| Id  | Operation              | Name   | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
-------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |        |     9 |   117 |     3   (0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE SINGLE|        |     9 |   117 |     3   (0)| 00:00:01 |     1 |     1 |
|*  2 |   TABLE ACCESS FULL    | T_CHEN |     9 |   117 |     3   (0)| 00:00:01 |     1 |     1 |
-------------------------------------------------------------------------------------------------


SQL> select * from t_chen where id between 11 and 19;
Execution Plan
----------------------------------------------------------
Plan hash value: 4068516938

-------------------------------------------------------------------------------------------------
| Id  | Operation              | Name   | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
-------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |        |     9 |   117 |     3   (0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE SINGLE|        |     9 |   117 |     3   (0)| 00:00:01 |     2 |     2 |
|*  2 |   TABLE ACCESS FULL    | T_CHEN |     9 |   117 |     3   (0)| 00:00:01 |     2 |     2 |
-------------------------------------------------------------------------------------------------

SQL> select * from t_chen where id between 21 and 33;

Execution Plan
----------------------------------------------------------
Plan hash value: 4068516938

-------------------------------------------------------------------------------------------------
| Id  | Operation              | Name   | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
-------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |        |    13 |   169 |     3   (0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE SINGLE|        |    13 |   169 |     3   (0)| 00:00:01 |     3 |     3 |
|*  2 |   TABLE ACCESS FULL    | T_CHEN |    13 |   169 |     3   (0)| 00:00:01 |     3 |     3 |
-------------------------------------------------------------------------------------------------

SQL> select * from t_chen where id between 11 and 35;
Execution Plan
----------------------------------------------------------
Plan hash value: 2158609430

---------------------------------------------------------------------------------------------------
| Id  | Operation                | Name   | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
---------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT         |        |    25 |   325 |     4   (0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE ITERATOR|        |    25 |   325 |     4   (0)| 00:00:01 |     2 |     3 |
|*  2 |   TABLE ACCESS FULL      | T_CHEN |    25 |   325 |     4   (0)| 00:00:01 |     2 |     3 |
---------------------------------------------------------------------------------------------------

SQL> select * from t_chen where id between 1 and 35;
Execution Plan
----------------------------------------------------------
Plan hash value: 1640523490

----------------------------------------------------------------------------------------------
| Id  | Operation           | Name   | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
----------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |        |    35 |   455 |     6   (0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE ALL|        |    35 |   455 |     6   (0)| 00:00:01 |     1 |     3 |
|*  2 |   TABLE ACCESS FULL | T_CHEN |    35 |   455 |     6   (0)| 00:00:01 |     1 |     3 |
----------------------------------------------------------------------------------------------
欢迎关注我的微信公众号"IT小Chen",共同学习,共同成长!!!




请使用浏览器的分享功能分享到微信等