The OraclePartition partition is summarized in detail. The partition field is updated and the partition to which the data belongs is changed. The data changes internally after the source data is inserted into new partitions, new data updates, and old source data.
The Oracle Partition is summarized in detail. The Partition field is updated and the Partition to which the data belongs is changed. The data changes internally after the source data is inserted into new partitions, new data updates, and old source data.
This article describes the concepts and operations of Partitioned Tables from the following aspects:
1. Concepts of tablespaces and partition tables
2. Specific functions of table partitions
3. Advantages and Disadvantages of table partitions
4. Table partition types and operation methods
5. maintenance operations on table partitions.
(1) concepts of tablespaces and partition tables
Table space: A table space is a collection of one or more data files. All data objects are stored in the specified table space.
Partition Table:
When the amount of data in a table increases, the speed of data query slows down, and the performance of applications degrades. In this case, you should consider partitioning the table. After the table is partitioned, the logical table is still a complete table, but the data in the table is physically stored in multiple tablespaces (physical files, it does not scan the entire table every time.
(2) specific functions of table partitions
The Table Partitioning function of Oracle brings great benefits to various applications by improving manageability, performance, and availability. In general, partitions can greatly improve the performance of some queries and maintenance operations. In addition, partitioning can greatly simplify common management tasks. Partitioning is a key tool for building a gigabit data system or a super high availability system.
The partition function further segments a table, index, or index organization table into segments. The segments of these database objects are called partitions. Each partition has its own name, and you can select its own storage features. From the perspective of the database administrator, the objects in a partition have multiple segments, which can be managed collectively or separately, this makes the database administrator quite flexible in managing the objects after the partition. However, from the perspective of the application, the partitioned table is exactly the same as the non-partitioned table. You do not need to modify it when using the SQL DML command to access the partitioned table.
When to use a partition table:
1. The table size exceeds 2 GB.
2. The table contains historical data. New data is added to new partitions.
(3) Advantages and Disadvantages of table partitions
Table partitions have the following advantages:
1. Improved query performance: You can query partition objects by searching only the partitions you are concerned about, improving the search speed.
2. Enhanced availability: If a partition of the table fails, the data of the table in other partitions is still available;
3. Easy Maintenance: If a partition of the table fails, you only need to fix the partition to fix the data;
4. Balanced I/O: You can map different partitions to disks to balance I/O and improve the overall system performance.
Disadvantages:
Partition Table: an existing table cannot be directly converted to a partition table. However, Oracle provides the online table redefinition function.
(4). Table partition types and operation methods
I. Range partitioning:
Range partitions map data to each partition based on the range. This range is determined by the partition key you specified when creating the partition. This partitioning method is the most commonly used, and the partition key usually uses the date. For example, you may partition the sales data by month.
When using range partitioning, consider the following rules:
1. Each partition must have a values less then clause, which specifies an upper limit not included in the partition. Any record with the partition key value equal to or greater than the upper limit will be added to the next higher partition.
2. All partitions except the first partition have an implicit lower limit. This value is the upper limit of the previous partition.
3. MAXVALUE is defined in the highest partition. MAXVALUE indicates an uncertain value. This VALUE is higher than the VALUE of any partition key in other partitions. It can also be understood as a VALUE higher than the value less then specified in any partition and a null VALUE.
Example 1:
Suppose there is a CUSTOMER table with 200000 rows of data. We partition this table using mermer_id. Each partition stores 100000 rows. We save each partition to a separate tablespace, in this way, data files can span across multiple physical disks. The following code creates a table and a partition:
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
)