Home Database Mysql Tutorial Oracle学习:分区表和索引

Oracle学习:分区表和索引

Jun 07, 2016 pm 04:55 PM
oracle database

什么时候使用Oracle分区: 1、 大数据量的表,比如大于2GB。一方面2GB文件对于32位os是一个上限,另外备份时间长。 2、

   什么时候使用Oracle分区:
    1、 大数据量的表,比如大于2GB。一方面2GB文件对于32位os是一个上限,另外备份时间长。
    2、 包括历史数据的表,比如最新的数据放入到最新的分区中。典型的例子:历史表,只有当前月份的数据可以被修改,而其他月份只能read-only
    ORACLE只支持以下分区:tables, indexes on tables, materialized views, and indexes on materialized views
    分区对SQL和DML是透明的(应用程序不必知道已经作了分区),但是DDL可以对不同的分区进行管理。
    不同的分区之间必须有相同的逻辑属性,比如共同的表名,列名,数据类型,约束;
    但是可以有不同的物理属性,比如pctfree, pctused, and tablespaces.
    分区独立性:即使某些分区不可用,其他分区仍然可用。
    最多可以分成64000个分区,但是具有LONG or LONG RAW列的表不可以,,但是有CLOB or BLOB列的表可以。
    可以不用to_date函数,比如:
    alter session set nls_date_format='mm/dd/yyyy';
    CREATE TABLE sales_range
    (salesman_id NUMBER(5),
    salesman_name VARCHAR2(30),
    sales_amount NUMBER(10),
    sales_date DATE)
    PARTITION BY RANGE(sales_date)
    (
    PARTITION sales_jan2000 VALUES LESS THAN('02/01/2000'),
    PARTITION sales_feb2000 VALUES LESS THAN('03/01/2000'),
    PARTITION sales_mar2000 VALUES LESS THAN('04/01/2000'),
    PARTITION sales_apr2000 VALUES LESS THAN('05/01/2000')
    );
    Partition Key:最多16个columns,可以是nullable的
    非分区的表可以有分区或者非分区的索引;
    分区表可以有分区或者非分区的索引;
    Partitioning 方法:
    Range Partitioning
    List Partitioning
    Hash Partitioning
    Composite Partitioning
    Composite Partitioning:组合,以及 range-hash and range-list composite partitioning
    Range Partitioning:
    每个分区都有VALUES LESS THAN子句,表示这个分区小于(=)前一个分区的VALUES LESS THAN值。
    MAXVALUE定义最高的分区,他表示一个虚拟的无限大的值。这个分区包括null值。
    CREATE TABLE sales_range
    (salesman_id NUMBER(5),
    salesman_name VARCHAR2(30),
    sales_amount NUMBER(10),
    sales_date DATE)
    PARTITION BY RANGE(sales_date)
    (
    PARTITION sales_jan2000 VALUES LESS THAN(TO_DATE('01/02/2000','DD/MM/YYYY')),
    PARTITION sales_feb2000 VALUES LESS THAN(TO_DATE('01/03/2000','DD/MM/YYYY')),
    PARTITION sales_mar2000 VALUES LESS THAN(TO_DATE('01/04/2000','DD/MM/YYYY')),
    PARTITION sales_apr2000 VALUES LESS THAN(TO_DATE('01/05/2000','DD/MM/YYYY')),
    PARTITION sales_2000 VALUES LESS THAN(MAXVALUE)
    );
    插入数据:
    Insert into sales_range values(1,2,3,to_date('21-04-2000','DD-MM-YYYY'));
    Insert into sales_range values(1,2,3,sysdate);
    选择数据:
    select * from sales_range;
    select * from sales_range partition(sales_apr2000);
    select * from sales_range partition(sales_mar2000);
    select * from sales_range partition(sales_2000);
    按照多个列分区:
    CREATE TABLE sales_range1
    (salesman_id NUMBER(5),
    salesman_name VARCHAR2(30),
    sales_amount NUMBER(10),
    sales_date DATE)
    PARTITION BY RANGE(sales_date, sales_amount)
    (
    PARTITION sales_jan2000 VALUES LESS THAN(TO_DATE('01/02/2000','DD/MM/YYYY'),1000),
    PARTITION sales_feb2000 VALUES LESS THAN(TO_DATE('01/03/2000','DD/MM/YYYY'),2000),
    PARTITION sales_mar2000 VALUES LESS THAN(TO_DATE('01/04/2000','DD/MM/YYYY'),3000),
    PARTITION sales_apr2000 VALUES LESS THAN(TO_DATE('01/05/2000','DD/MM/YYYY'),4000),
    PARTITION sales_2000 VALUES LESS THAN(MAXVALUE, MAXVALUE)
    );
    Insert into sales_range1 values(1,2,500, TO_DATE('21/01/2000','DD/MM/YYYY'));
    Insert into sales_range1 values(2,3,1500, sysdate);

linux

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)

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

How to read the oracle awr report How to read the oracle awr report Apr 11, 2025 pm 09:45 PM

An AWR report is a report that displays database performance and activity snapshots. The interpretation steps include: identifying the date and time of the activity snapshot. View an overview of activities and resource consumption. Analyze session activities to find session types, resource consumption, and waiting events. Find potential performance bottlenecks such as slow SQL statements, resource contention, and I/O issues. View waiting events, identify and resolve them for performance. Analyze latch and memory usage patterns to identify memory issues that are causing performance issues.

See all articles