Home Database Mysql Tutorial Oracle 11g维护分区(一)Adding Partitions

Oracle 11g维护分区(一)Adding Partitions

Jun 07, 2016 pm 03:53 PM

本节将介绍如何手动添加新的分区到分区表,并解释了为什么分区不能被指定添加到大部分分区索引。

添加分区

本节将介绍如何手动添加新的分区到分区表,并解释了为什么分区不能被指定添加到大部分分区索引。

向范围分区表添加一个分区

使用ALTER TABLE ... ADD PARTITION语句来添加一个新的分区到“高”端(表中最后一个分区的’HighValue’)。要在开始或在表的中间添加一个分区,使用SPLIT PARTITION子句。

例如,考虑这么一张表,sales,除了包含当前月份的数据,还包含之前12个月份的数据。 1999年1月1日,你增加一个分区月份,存储在表空间TSX。

ALTER TABLE sales

      ADD PARTITION jan99 VALUES LESS THAN ( '01-FEB-1999' )

      TABLESPACE tsx;

另外,和范围分区表相关的本地索引和全局索引仍然可用。

向哈希分区表添加一个分区

当你向一个哈希分区表添加分区时,数据库会对一个现有分区(由数据库选择)的所有数据行按照哈希函数进行重新排列,并将数据填充到新增的分区中。因此,如果表非空的话,添加一个哈希分区可能比较费时。

下面的语句显示了向scubagear表添加一个哈希分区的两种方式。选择第一条语句来添加哈希分区,分区名称由系统自动生成,并且分区存放在默认表空间。第二条语句同样也是增加一个分区,但是,明确指定了分区名称p_named和表空间名称gear5。

ALTER TABLE scubagear ADD PARTITION;

ALTER TABLE scubagear

      ADD PARTITION p_named TABLESPACE gear5;

索引可能被标识为UNUSABLE,如下表所述:

表类型

索引操作

普通表(堆表)

索引组织表

对于本地索引,和普通表的处理方式一样。

所有全局索引保持可用;

向列表分区表添加一个分区

下面的语句说明了如何向列表分区表添加一个新的分区,在示例中,指定了新增分区的存储属性和NOLOGGING属性。

ALTER TABLE q1_sales_by_region

  ADD PARTITION q1_nonmainland VALUES ('HI', 'PR')

      STORAGE (INITIAL 20K NEXT 20K) TABLESPACE tbs_3

      NOLOGGING;

描述新增分区的集合内的所有值不能存在于表的其他分区。

如果一个列表分区表包含默认分区,那么你不能给它添加新的分区,但是你可以拆分默认分区。通过这样做,你不仅有效地创建了一个你指定值的新分区,并且第二个分区保留为默认分区。

与列表分区表相关的本地和全局索引均保持可用。

向间隔分区表添加一个分区

你不能显式地向间隔分区表中添加一个分区,除非你西安锁定分区,这将触发创建分区。当该间隔的数据被插入时,数据库会自动创建一个间隔分区。一般情况下,只有在分区交换负载场景中,你才必须显式创建间隔分区。

要改变将来分区的间隔,我们可以在ALTER TABLE中使用SET INTERVAL子句。该子句将会改变超过当前最高边界的所有物化间隔分区的间隔。

你也可以使用SET INTERVAL子句来迁移一个存在的范围分区表或者符合范围分区表到间隔分区表或复合间隔分区表。如果要禁止创建新的分区,有效的恢复回一个范围分区表,在SET INTERVAL子句中指定一个空值即可。已创建的间隔分区将被转化为范围分区,对应的HighValue为当前最大值。

如果要提高日期的间隔范围,你必须确保你在新分区的相应边界。例如,在你的日常间隔分区表transactions的最高间隔分区边界是January 30, 2007,你想把间隔修改为一个月,那么下面的语句将会导致一个错误:

ALTER TABLE transactions SET INTERVAL (NUMTOYMINTERVAL(1,'MONTH');

ORA-14767: Cannot specify this interval with existing high bounds

你必须创建另外一个以February 1, 2007为边界的日常间隔分区,这样才能成功修改间隔。

LOCK TABLE transactions PARTITION FOR(TO_DATE('31-JAN-2007','dd-MON-yyyy') IN SHARE MODE;

ALTER TABLE transactions SET INTERVAL (NUMTOYMINTERVAL(1,'MONTH');

间隔分区表的第一个分区其实是一个范围分区,你可以拆分范围分区,在间隔分区表中添加更多的分区。

如果要禁用transactions表的间隔分区,使用以下语句:

ALTER TABLE transactions SET INTERVAL ();

向哈希复合分区表添加分区

可以在分区和哈希子分区两个级别来添加分区。

添加一个分区

向一个【范围|列表|间隔】-哈希复合分区表添加一个分区如前所述。对于一个间隔-哈希分区表,间隔分区是自动创建的。你可以指定SUBPARTITIONS子句来指定子分区的数量,或者指定SUBPARTITION子句来命名具体子分区。如果没有指定SUBPARTITIONS子句或者SUBPARTITION子句,那么分区将继承表级别的默认属性。对于一个间隔-哈希分区表,你只能向范围或者已经物化的间隔分区添加子分区。

这个例子向一个范围-哈希分区表sales添加了一个范围分区q1_2000,该分区用来存储2000年第一季度的数据。其中,有8个子分区存储在tbs5表空间。子分区不能显式使用表压缩。在这个例子中,子分区会继承分区级别的压缩属性并以压缩形式存储。

ALTER TABLE sales ADD PARTITION q1_2000

      VALUES LESS THAN (2000, 04, 01) COMPRESS

      SUBPARTITIONS 8 STORE IN tbs5;

添加一个子分区

你可以在ALTER TABLE语句中使用MODIFY PARTITION ... ADD SUBPARTITION子句来向一个【范围|列表|间隔】-哈希复合分区表添加一个哈希子分区。数据库将会根据哈希函数,对同一分区内的一个已有子分区的所有数据行重新进行哈希排列,并将其中部分数据填充到新增子分区中。对于一个间隔-哈希分区表,你只能向范围分区或者已经物化的间隔分区添加子分区。

在下面的示例中,一个存储在us1表空间的新哈希子分区us_loc5, 被添加到diving表的范围分区locations_us中。

ALTER TABLE diving MODIFY PARTITION locations_us

      ADD SUBPARTITION us_locs5 TABLESPACE us1;

除非你指定了UPDATE INDEXES子句,否则,必须重建和新增子分区以及重新进行哈希排列子分区相关的索引子分区。

向列表复合分区表添加分区

可以在分区和列表子分区两个级别来添加分区。

添加一个分区

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Apr 02, 2025 pm 07:05 PM

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

Can mysql and mariadb coexist Can mysql and mariadb coexist Apr 08, 2025 pm 02:27 PM

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

See all articles