Home Database Mysql Tutorial 分区的操作类型

分区的操作类型

Jun 07, 2016 pm 03:54 PM
Partition Partition Table definition operate data type

一、分区的定义: 分区表是将大表的数据分成许多小的子集,而这些小的子集便称为分区。 二、分区的优点: 1 、增强可用性:如果表的一个分区由于系统故障而不能使用,表的其余好的分区仍然可以使用; 2 、减少关闭时间:如果系统故障只影响表的一部分分区,

一、分区的定义:

分区表是将大表的数据分成许多小的子集,而这些小的子集便称为分区。

二、分区的优点:

1 、增强可用性:如果表的一个分区由于系统故障而不能使用,表的其余好的分区仍然可以使用;

2 、减少关闭时间:如果系统故障只影响表的一部分分区,那么只有这部分分区需要修复,故能比整个大表修复花的时间更少;

3 、维护轻松:如果需要重建表,独立管理每个分区比管理单个大表要轻松得多;

4 、均衡I/O:可以把表的不同分区分配到不同的磁盘来平衡I/O改善性能;

5 、改善性能:对大表的查询、增加、修改等操作可以分解到表的不同分区来并行执行,可使运行速度更快;

6 、分区对用户透明,最终用户感觉不到分区的存在。

三、分区的管理: 分区的很多操作都会导致索引的失效,需要重建索引。不过如果带上update indexes 可以避免。

1 、分区表一共分为三类即range、list、hash,而各自的创建语句如下:

--range分区

CREATE TABLE p_range

(sale_date DATE NOT NULL )

PARTITION BY RANGE (sale_date)

(PARTITION p1 VALUES LESS THAN (TO_DATE('1999-04-01','YYYY-MM-DD')) TABLESPACE system,

PARTITION p2 VALUES LESS THAN (TO_DATE('1999-07-01','YYYY-MM-DD')) TABLESPACE system,

PARTITION pmax VALUES LESS THAN (maxvalue) TABLESPACE system);

--list分区

CREATE TABLE p_list

(sale_date varchar2(10) NOT NULL ) PARTITION BY list (sale_date)

(PARTITION p1 VALUES ('20121111') TABLESPACE system,

PARTITION p2 VALUES ('20121112') TABLESPACE system,

partition pdefault values (default) TABLESPACE system);

--hash分区

CREATE TABLE p_hash

(sale_date DATE NOT NULL ) PARTITION BY hash (sale_date)

(PARTITION p1 TABLESPACE system,

PARTITION p2 TABLESPACE system,

PARTITION p3 TABLESPACE system);

--复合分区

CREATE TABLE p_box (i NUMBER, j NUMBER)

PARTITION BY RANGE(j)

SUBPARTITION BY HASH(i)

(PARTITION p1 VALUES LESS THAN (10) SUBPARTITION t2_pls1 SUBPARTITION t2_pls2,

PARTITION p2 VALUES LESS THAN (20) SUBPARTITION t2_p2s1 SUBPARTITION t2_p2s2));

从上面的实例看出,我们介绍了一种复合索引,而复合索引在ORACLE10G 中仅限于range-hash和range- list两中复合分区,但是到11G中,ORACLE边在其中加入了四种新的组合,充分发挥了复合索引的作用:range-range、list-range、list-hash、list-list。

2 、如何增加分区(ADD):

如果list分区有default或者range分区有maxvalue,则不能进行add partition操作 ;add partition的值必须大于所有分区的值。。

alter table p_list add partition p_3 values('20121113');

3 、截断分区(TRUNCATE):

alter table p_list truncate partition p_3

4、删除分区(DROP)

alter table p_list drop partition p_3

删除子分区;alter table p_list drop subpartition xxx;

5、分裂分区(split)

通常我们会用来拆分MAXVALUE/DEFAULT分区。

alter table p_range split partition pmax at (to_date('2012-11-13','yyyy-mm-dd')) into (partition p_3,partition p_max);

alter table p_list split partition pdefault values ('20121113') into(partition p_3,partition p_defalut);

此时会将pmax或pdefault中的'20121113'值放入P_3,其他的数据会放入p_max或p_defalut。

6、交换分区(exchange) (简介)

速度很快,可以是分区跟非分区表交换,子分区跟非分区表交换,组合分区跟分区表交换。

create table p_u_list(sale_date1 varchar2(10) NOT NULL )

insert into p_u_list values('20121111');

alter table p_list exchange partition p1 with table p_u_list WITH VALIDATION ;

insert into p_u_list values('20121115');

alter table p_list exchange partition p1 with table p_u_list WITH VALIDATION; --此时会出错,因为20121115不属于分区平p1,而且做了 WITH VALIDATION检查,如果想成功交换,需加上WITHOUT VALIDATION ,如果指定WITH VALIDATION(默认) 会对交换进来的数据进行合法检查,看是否符合该分区的规则,WITHOUT VALIDATION 会忽略合法检查(比如ID=12的记录此时可以交换到ID VALUES LESS THAN (10)的分区里),但如果表上有primary key 或unique 约束的话,指定without validation会被忽略。

7、 合并分区(merge和coalesce)

coalesce 仅仅适用于hash分区和复合分区的hash子分区--自动收缩当前的表分区,比如某表当前有5个hash分区,执行coalesce后就变成4个,再执行一次就变成3 个...直至一个。 merge 不适用hash分区--如果list分区有default或者range分区有maxvalue,则不能进行merge操作

alter table p_hash coalesce partition;

alter table p_list merge partitions p1,p2 into partition P0;

8 重命名分区(rename)

Alter table xxx rename partition/subpartition p1 to p1_new;

9.移动分区(move)

改变分区的表空间

alter table p_list move partition p1 tablespace sysaux;

10.EXPORT分区:

exp sales/sales_password tables=sales:sales1999_q1 rows=Y file=sales1999_q1.dmp

11.IMPORT分区:

imp sales/sales_password FILE =sales1999_q1.dmp TABLES = (sales:sales1999_q1) IGNORE=y

12. 修改分区默认属性(modify default attributes)

修改表属性:alter table xxx modify default attributes …

修改分区属性(适用于组合分区):alter table xxx modify default attributes for partition p1 …

只对以后添加的分区产生影响,适用于所有分区,其中hash分区只能修改表空间属性。 如:

Alter table xxx modify default attributes tablespace users;

13. 修改子分区模板属(set subpartition template)

Alter table xxx set subpartition template (…);

仅影响以后的子分区,当前的子分区属性不会改变 如:

Alter table xxx set subpartition template (partition p1 tablespace tbs_1, Partition p2 tablespace tbs_2);

如果要取消掉子分区模板:

Alter table xxx set subpartition template ();

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)

Use ddrescue to recover data on Linux Use ddrescue to recover data on Linux Mar 20, 2024 pm 01:37 PM

DDREASE is a tool for recovering data from file or block devices such as hard drives, SSDs, RAM disks, CDs, DVDs and USB storage devices. It copies data from one block device to another, leaving corrupted data blocks behind and moving only good data blocks. ddreasue is a powerful recovery tool that is fully automated as it does not require any interference during recovery operations. Additionally, thanks to the ddasue map file, it can be stopped and resumed at any time. Other key features of DDREASE are as follows: It does not overwrite recovered data but fills the gaps in case of iterative recovery. However, it can be truncated if the tool is instructed to do so explicitly. Recover data from multiple files or blocks to a single

Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Apr 03, 2024 pm 12:04 PM

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Apr 01, 2024 pm 07:46 PM

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

Slow Cellular Data Internet Speeds on iPhone: Fixes Slow Cellular Data Internet Speeds on iPhone: Fixes May 03, 2024 pm 09:01 PM

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks Apr 29, 2024 pm 06:55 PM

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! May 06, 2024 pm 04:13 PM

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. May 07, 2024 pm 05:00 PM

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,

Alibaba 7B multi-modal document understanding large model wins new SOTA Alibaba 7B multi-modal document understanding large model wins new SOTA Apr 02, 2024 am 11:31 AM

New SOTA for multimodal document understanding capabilities! Alibaba's mPLUG team released the latest open source work mPLUG-DocOwl1.5, which proposed a series of solutions to address the four major challenges of high-resolution image text recognition, general document structure understanding, instruction following, and introduction of external knowledge. Without further ado, let’s look at the effects first. One-click recognition and conversion of charts with complex structures into Markdown format: Charts of different styles are available: More detailed text recognition and positioning can also be easily handled: Detailed explanations of document understanding can also be given: You know, "Document Understanding" is currently An important scenario for the implementation of large language models. There are many products on the market to assist document reading. Some of them mainly use OCR systems for text recognition and cooperate with LLM for text processing.

See all articles