A demo of nonprefix & prefix Index

Source: Internet
Author: User

The following is an experiment I have done on partition indexes to deepen my understanding of related concepts:

For related concepts, refer to my blog:

Http://blog.csdn.net/waterxcfg304/article/details/8509734

1, create a partition table

Create Table batch_usr.sales_history
(
Prod_id number not null,
Cust_id number not null,
Time_id date not null,
Channel_id number not null,
Promo_id number not null,
Quantity_sold number (10, 2) not null,
Amount_sold number (10, 2) not null
)
Partition by range (time_id)
(
Partition p1998_1h values less than (to_date ('2017-07-01 ', 'yyyy-mm-dd') tablespace data1,
Partition p1998_2h values less than (to_date ('1970-01-01 ', 'yyyy-mm-dd') tablespace data2,
Partition p1999_1h values less than (to_date ('2017-07-01 ', 'yyyy-mm-dd') tablespace data3,
Partition p%_2h values less than (to_date ('1970-01-01 ', 'yyyy-mm-dd') tablespace data4,
Partition p2000_1h values less than (to_date ('2017-07-01 ', 'yyyy-mm-dd') tablespace data5,
Partition p2000_2h values less than (to_date ('1970-01-01 ', 'yyyy-mm-dd') tablespace data6,
Partition p2001_1h values less than (to_date ('2017-07-01 ', 'yyyy-mm-dd') tablespace data7,
Partition p2001_2h values less than (to_date ('1970-01-01 ', 'yyyy-mm-dd') tablespace data8
);

2, populate data into sales_history table
Insert into batch_usr.sales_history select * from SH. Sales where to_number (to_char (time_id, 'yyyy') in );

 

3, the followings are different types of indexes that will be created.

Firstly global indexes:
Yes
Create index batch_usr.sales_hist_pid_idx on batch_usr.sales_history (prod_id) Global
Partition by hash (prod_id)
Partitions 8 store in (Batch)
Nologging
Parallel;
Drop index batch_usr.sales_hist_pid_idx;

No (the global index must be prefix)
Create index batch_usr.sales_hist_pid_idx on batch_usr.sales_history (time_id) Global
Partition by hash (prod_id)
Partitions 8 store in (Batch)
Nologging
Parallel;
Error at line 2:
ORA-14038: Global partitioned index must be prefixed

Yes
Create index batch_usr.sales_hist_pid_idx on batch_usr.sales_history (time_id) Global
Partition by hash (time_id)
Partitions 8 store in (Batch)
Nologging
Parallel;
Drop index batch_usr.sales_hist_pid_idx;

No (the global index must be prefix)
Create index batch_usr.sales_hist_pid_idx on batch_usr.sales_history (prod_id) Global
Partition by hash (time_id)
Partitions 8 store in (Batch)
Nologging
Parallel;

Error at line 2:
ORA-14038: Global partitioned index must be prefixed

Secondly local indexes:

Non-Prefix index (index column and table partition column are different)

SQL> Create index batch_usr.sales_hist_pid_idx on batch_usr.sales_history (prod_id) local;

Index created.

SQL> drop index batch_usr.sales_hist_pid_idx;

Index dropped.

 

An index with a prefix (the same as a table partition)

SQL> Create index batch_usr.sales_hist_pid_idx on batch_usr.sales_history (time_id) local;

Index created.

SQL> drop index batch_usr.sales_hist_pid_idx;

Index dropped.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.