The concept and function of database table space partition table

This article organizes the concepts and operations of partition tables from the following aspects:
1. The concept of table space and partition table
2. The specific role of
table partition 3. The advantages and disadvantages of
table partition 4. Several types and operations of table partition Method
5. Maintenance operations on table partitions.
(1.) Concept of table space and partition table
Table space:
  is a collection of one or more data files, all data objects are stored in the specified table space, but the main The table is stored, so it is called a table space.

Partitioned table:
When the amount of data in the table continues to increase, the speed of querying data will slow down, and the performance of the application will decrease. At this time, you should consider partitioning the table. After the table is partitioned, the table is still a complete table logically, but the data in the table is physically stored in multiple table spaces (physical files), so that when querying data, the entire table will not be scanned every time. surface.

(2). The specific role
of table partitioning Oracle's table partitioning function brings great benefits to various applications by improving manageability, performance and availability. In general, partitioning can greatly improve the performance of certain queries as well as maintenance operations. In addition, partitioning can greatly simplify common administrative tasks, and partitioning is a key tool in building gigabyte data systems or ultra-high-availability systems.

Partitioning can further subdivide a table, index, or index-organized table into segments. The segments of these database objects are called partitions. Each partition has its own name and can also choose its own storage characteristics. From the database administrator's point of view, a partitioned object has multiple segments, which can be managed collectively or individually, which gives the database administrator considerable flexibility in managing the partitioned objects sex. However, from an application perspective, a partitioned table is exactly the same as a non-partitioned table, and no modification is required when accessing the partitioned table using SQL DML commands.

When to use a partition table:
1. The size of the table exceeds 2GB.
2. The table contains historical data, and new data is added to the new partition.

(3) Advantages and disadvantages of
table partitioning Table partitioning has the following advantages:
1. Improve query performance: You can search only the partitions you care about when querying partitioned objects, which improves retrieval speed.
2. Enhanced availability: If a partition of the table fails, the data in other partitions of the table is still available;
3. Easy maintenance: If a partition of the table fails and data needs to be repaired, only the partition can be repaired;
4. Balanced I/O: Different partitions can be mapped to disks to balance I/O and improve overall system performance.

Disadvantages:
Partitioned table related: There is no way for an existing table to be directly converted to a partitioned table. However, Oracle provides the function of redefining tables online.

(4) Several types and operation methods of table partitioning
1. Range partitioning:
Range partitioning maps data to each partition based on a range, which is determined by the partition key you specify when creating the partition. This partitioning method is the most common, and the partition key is often date. For example: you might partition your sales data by month.
When using range partitioning, please consider the following rules:
1. Each partition must have a VALUES LESS THEN clause, which specifies an upper limit value that is not included in the partition. Any records with a partition key equal to or greater than this upper limit will be added to the next higher partition.
2. All partitions, except the first one, will have an implicit lower limit value, which is the upper limit value of the previous partition of this partition.
3. In the highest partition, MAXVALUE is defined. MAXVALUE represents an indeterminate value. This value is higher than the value of any partition key in other partitions, and can also be understood as higher than the value of VALUE LESS THEN specified in any partition, including null values.
Example 1:
Suppose there is a CUSTOMER table with 200,000 rows of data. We partition this table by CUSTOMER_ID, and each partition stores 100,000 rows. We save each partition to a separate tablespace, so that data files can span multiple physical disk. Here is the code to create the table and partition as follows:
CREATE TABLE CUSTOMER
(
CUSTOMER_ID NUMBER NOT NULL PRIMARY KEY,
FIRST_NAME VARCHAR2(30) NOT NULL,
LAST_NAME VARCHAR2(30) NOT NULL,
PHONE VARCHAR2(15) NOT NULL,
EMAIL VARCHAR2(80 ),
STATUS CHAR(1)
)
PARTITION BY RANGE (CUSTOMER_ID)
(
PARTITION CUS_PART1 VALUES LESS THAN (100000) TABLESPACE CUS_TS01,
PARTITION CUS_PART2 VALUES LESS THAN (200000) TABLESPACE CUS_TS02
)
Example 2:
CREATE TABLE ORDER_ACTIVITIES
(
ORDER_ID NUMBER( 7) NOT NULL,
ORDER_DATE DATE,
TOTAL_AMOUNT NUMBER,
CUSTOTMER_ID NUMBER(7),
PAID CHAR(1)
)
PARTITION BY RANGE (ORDER_DATE)
(
PARTITION ORD_ACT_PART01 VALUES LESS THAN (TO_DATE('01- MAY -2003','DD-MON-YYYY')) TABLESPACEORD_TS01,
PARTITION ORD_ACT_PART02 VALUES LESS THAN (TO_DATE('01-JUN-2003','DD-MON-YYYY')) TABLESPACE ORD_TS02,
PARTITION ORD_ACT_PART02 VALUES LESS THAN (TO_DATE('01-JUL-2003','DD-MON-YYYY')) TABLESPACE ORD_TS03
)
例三:MAXVALUE
CREATE TABLE RangeTable
(
idd INT PRIMARY KEY ,
iNAME VARCHAR(10),
grade INT
)
PARTITION BY RANGE (grade)
(
PARTITION part1 VALUES LESS THEN (1000) TABLESPACE Part1_tb,
PARTITION part2 VALUES LESS THEN (MAXVALUE) TABLESPACE Part2_tb
);

2. List partition:
The feature of this partition is that there are only a few values ​​in a certain column. Based on this feature, we can use list partition.
Example 1
CREATE TABLE PROBLEM_TICKETS
(
PROBLEM_ID NUMBER(7) NOT NULL PRIMARY KEY,
DESCRIPTION VARCHAR2(2000),
CUSTOMER_ID NUMBER(7) NOT NULL,
DATE_ENTERED DATE NOT NULL,
STATUS VARCHAR2(20)
)
PARTITION BY LIST (STATUS)
(
PARTITION PROB_ACTIVE VALUES ('ACTIVE') TABLESPACE PROB_TS01,
PARTITION PROB_INACTIVE VALUES ('INACTIVE') TABLESPACE PROB_TS02
Example 2
CREATE TABLE ListTable
(
id INT PRIMARY KEY ,
name VARCHAR (20),
area VARCHAR (10)
)
PARTITION BY LIST (area)
(
PARTITION part1 VALUES ('guangdong','beijing') TABLESPACE Part1_tb, PARTITION part2
VALUES ('shanghai','nanjing') TABLESPACE Part2_tb )
; A hashing algorithm is used on the column values ​​to determine which partition to put the row into. Hash partitioning is recommended when column values ​​do not have suitable conditions. Hash partitioning is a type of partitioning that distributes data evenly by specifying partition numbers because the partitions are made uniform in size by hashing partitions on I/O devices. Example 1: CREATE TABLE HASH_TABLE ( COL NUMBER(8), INF VARCHAR2(100) ) PARTITION BY HASH (COL) ( PARTITION PART01 TABLESPACE HASH_TS01, PARTITION PART02 TABLESPACE HASH_TS02, PARTITION PART03 TABLESPACE HASH_TS03 ) Shorthand : CREATE TABLE emp ( empno NUMBER ( 4),





















ename VARCHAR2 (30),
sal NUMBER
)
PARTITION BY HASH (empno) PARTITIONS 8
STORE IN (emp1,emp2,emp3,emp4,emp5,emp6,emp7,emp8)

; In which partition a record should be inserted, the most important thing in the hash algorithm is the hash function. If you want to use hash partitions in Oracle, you only need to specify the number of partitions. It is recommended that the number of partitions be 2 to the nth power, which can make the data distribution among the partitions more uniform.

4. Combined range hash partitioning
This partitioning is based on range partitioning and list partitioning. The table first performs range partitioning by a certain column, and then performs list partitioning by a certain column. The partitions among the partitions are called sub-partitions.
CREATE TABLE SALES
(
PRODUCT_ID VARCHAR2(5),
SALES_DATE DATE,
SALES_COST NUMBER(10),
STATUS VARCHAR2(20)
)
PARTITION BY RANGE(SALES_DATE) SUBPARTITION BY LIST (STATUS)
(
PARTITION P1 VALUES LESS THAN(TO_DATE('2003-01 -01','YYYY-MM-DD')) TABLESPACE rptfact2009
(
SUBPARTITION P1SUB1 VALUES ('ACTIVE') TABLESPACE rptfact2009,
SUBPARTITION P1SUB2 VALUES ('INACTIVE') TABLESPACE rptfact2009
),
PARTITION P2 VALUES LESS THAN (TO_DATE('2003-03-01','YYYY-MM-DD')) TABLESPACE rptfact2009
(
SUBPARTITION P2SUB1 VALUES ('ACTIVE') TABLESPACE rptfact2009,
SUBPARTITION P2SUB2 VALUES ('INACTIVE') TABLESPACE rptfact2009
)
)

5. Compound range hash partitioning:
This partitioning is based on range partitioning and hash partitioning, and the table is first processed by a certain column Range partitioning and then hash partitioning by a column.
create table dinya_test
(
transaction_id number primary key,
item_id number(8) not null,
item_description varchar2(300),
transaction_date date
)
partition by range(transaction_date)subpartition by hash(transaction_id) subpartitions 3 store in (dinya_space01,dinya_space02,dinya_space03)
(
partition part_01 values less than(to_date(‘2006-01-01’,’yyyy-mm-dd’)),
partition part_02 values less than(to_date(‘2010-01-01’,’yyyy-mm-dd’)),
partition part_03 values less than(maxvalue)
);

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327082460&siteId=291194637
Recommended