一、分区的定义: 分区表是将大表的数据分成许多小的子集,而这些小的子集便称为分区。 二、分区的优点: 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 ();

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software