首页 > 数据库 > > SQL语法-REINDEX
为表中的数据重建索引。
在以下几种情况下需要使用REINDEX重建索引:
使用CONCURRENTLY选项创建索引失败,留下了一个“非法”索引。
REINDEX DATABASE和SYSTEM这种形式的重建索引不能在事务块中执行。
REINDEX { INDEX | [INTERNAL] TABLE | DATABASE | SYSTEM } name [ FORCE ];
REINDEX { INDEX| [INTERNAL] TABLE} name
PARTITION partition_name [ FORCE ];
重新建立指定的索引。
重建列存表或Hadoop内表的Desc表的索引,如果表有从属的"TOAST"表,则这个表也会重建索引。
重新建立指定表的所有索引,如果表有从属的"TOAST"表,则这个表也会重建索引。
重建当前数据库里的所有索引。
在当前数据库上重建所有系统表上的索引。不会处理在用户表上的索引。
需要重建索引的索引、表、数据库的名称。表和索引可以有模式修饰。
说明:REINDEX DATABASE和SYSTEM只能重建当前数据库的索引,所以name必须和当前数据库名称相同。
无效选项,会被忽略。
需要重建索引的分区的名字或者索引分区的名字。
取值范围:

REINDEX DATABASE和SYSTEM这种形式的重建索引不能在事务块中执行。
--创建一个行存表tpcds.customer_t1,并在tpcds.customer_t1表上的c_customer_sk字段创建索引。
CREATE TABLE tpcds.customer_t1
(
c_customer_sk integer not null,
c_customer_id char(16) not null,
c_current_cdemo_sk integer ,
c_current_hdemo_sk integer ,
c_current_addr_sk integer ,
c_first_shipto_date_sk integer ,
c_first_sales_date_sk integer ,
c_salutation char(10) ,
c_first_name char(20) ,
c_last_name char(30) ,
c_preferred_cust_flag char(1) ,
c_birth_day integer ,
c_birth_month integer ,
c_birth_year integer ,
c_birth_country varchar(20) ,
c_login char(13) ,
c_email_address char(50) ,
c_last_review_date char(10)
)
WITH (orientation = row)
DISTRIBUTE BY HASH (c_customer_sk);
CREATE INDEX tpcds_customer_index1 ON tpcds.customer_t1 (c_customer_sk);
INSERT INTO tpcds.customer_t1 SELECT * FROM tpcds.customer WHERE c_customer_sk < 10;
--重建一个单独索引。
REINDEX INDEX tpcds.tpcds_customer_index1;
--重建表tpcds.customer_t1上的所有索引。
REINDEX TABLE tpcds.customer_t1;
--删除tpcds.customer_t1表。
DROP TABLE tpcds.customer_t1;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69959250/viewspace-3131961/ ,如需转载,请注明出处,否则将追究法律责任。