自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

一篇學會 OpenGauss 分區(qū)表索引

運維 數(shù)據(jù)庫運維
openGauss分區(qū)表支持兩種索引:全局(global)索引和本地(local)索引。分區(qū)表創(chuàng)建索引不支持concurrently語法,默認索引是全局索引,創(chuàng)建本地索引需要指定local。

[[422438]]

本文轉載自微信公眾號「數(shù)據(jù)和云」,作者高云龍。轉載本文請聯(lián)系數(shù)據(jù)和云公眾號。

一、概述

openGauss分區(qū)表支持兩種索引:全局(global)索引和本地(local)索引。

分區(qū)表創(chuàng)建索引不支持concurrently語法,默認索引是全局索引,創(chuàng)建本地索引需要指定local。

創(chuàng)建主鍵約束和唯一約束必須要包含分區(qū)字段,創(chuàng)建本地唯一索引也必須要包含分區(qū)字段,但是創(chuàng)建全局唯一索引沒有這個限制。

  1. postgres=# create index concurrently on part_index_test(col2,col1,col3); 
  2. ERROR:  cannot create concurrent partitioned indexes 

本文主要闡述添加或刪除分區(qū)對索引的影響。

數(shù)據(jù)庫版本:openGauss 1.1.0

二、測試

1.建表語句

范圍分區(qū)中的間隔語法可以自動追加分區(qū)表,這里以間隔分區(qū)表為例:

  1. create table part_index_test( 
  2. partid varchar(32) not null
  3. col1 varchar(2) not null
  4. col2 date not null
  5. col3 varchar(8) not null 
  6. )partition by range(col2) 
  7. interval('1 day'
  8. partition part1 values less than ('20210331'), 
  9. partition part2 values less than ('20210401'
  10. ); 

全局索引:

  1. create index on part_index_test(col2,col1,col3); 

本地索引:

  1. create index on part_index_test(col2,col1,col3) local

2.測試數(shù)據(jù)

間隔分區(qū)是以1天為單位,所以新增一天的數(shù)據(jù),會自動增加一個以sys_p開頭的自增分區(qū):

  1. insert into part_index_test select generate_series(1,1000),'1','20210401',generate_series(1,1000); 
  2. insert into part_index_test select generate_series(1,1000),'1','20210402',generate_series(1,1000); 
  3. insert into part_index_test select generate_series(1,1000),'1','20210403',generate_series(1,1000); 
  4. insert into part_index_test select generate_series(1,1000),'1','20210404',generate_series(1,1000); 
  5. insert into part_index_test select generate_series(1,1000),'1','20210405',generate_series(1,1000); 
  6. insert into part_index_test select generate_series(1,1000),'1','20210406',generate_series(1,1000); 

3.刪除分區(qū)語法

  • 先通過pg_partition系統(tǒng)表查看分區(qū)
  1. select relname,parttype,parentid,boundaries from pg_partition; 
  • 默認刪除分區(qū):
  1. alter table part_index_test DROP PARTITIONpartition_name; 
  • update global index 方式刪除分區(qū):
  1. alter table part_index_test DROP PARTITION partition_name update global index

4.索引使用

  1. explain select * from part_index_test where col2=$1 and partid=$2; 

5.測試結果

-

添加分區(qū)

刪除分區(qū)

備注

全局索引

生效

默認語法失效/update global index語法生效

索引失效后,需要reindex

本地索引

生效

生效

 

總結:

1、添加/刪除分區(qū)不影響本地索引使用。

2、添加分區(qū)不影響全局索引使用,默認刪除分區(qū)方式,全局索引失效,需要對全局索引重建;update global index方式刪除分區(qū),不影響全局索引使用。

三、示例

1.分區(qū)表準備

  • 創(chuàng)建分區(qū)表
  1. create table part_range_lessthan_int( 
  2. id serial primary key
  3. col1 varchar(16)) 
  4. partition by range(id) 
  5. partition p1 values less than(1000), 
  6. partition p2 values less than(2000), 
  7. partition p3 values less than(3000), 
  8. partition p4 values less than(maxvalue) 
  9. ); 
  • 創(chuàng)建全局索引
  1. create unique index on part_range_lessthan_int(col1); 
  • 初始化數(shù)據(jù)
  1. insert into part_range_lessthan_int select generate_series(1,5000),'tuple'||generate_series(1,5000); 
  • 默認刪除分區(qū)SQL
  1. select now();alter table part_range_lessthan_int drop partition p1; 
  • update global index 刪除分區(qū)SQL
  1. select now();alter table part_range_lessthan_int drop partition p1 update global index
  • 查詢SQL
  1. analyze;select now();explain select * from part_range_lessthan_int where col1='tuple2500'

2.默認刪除分區(qū)語法

3.update global index 刪除分區(qū)

關于作者

高云龍,云和恩墨服務總監(jiān),長期從事PG運維工作,目前在支持openGauss生態(tài)發(fā)展。

 

責任編輯:武曉燕 來源: 數(shù)據(jù)和云
相關推薦

2021-07-02 09:45:29

MySQL InnoDB數(shù)據(jù)

2022-06-22 07:32:53

Sharding分庫數(shù)據(jù)源

2022-08-29 08:00:11

哈希表數(shù)組存儲桶

2022-01-02 08:43:46

Python

2022-02-07 11:01:23

ZooKeeper

2023-01-03 08:31:54

Spring讀取器配置

2021-05-11 08:54:59

建造者模式設計

2021-07-05 22:11:38

MySQL體系架構

2021-07-06 08:59:18

抽象工廠模式

2022-08-26 09:29:01

Kubernetes策略Master

2023-11-28 08:29:31

Rust內存布局

2022-08-23 08:00:59

磁盤性能網(wǎng)絡

2021-10-27 09:59:35

存儲

2021-07-02 08:51:29

源碼參數(shù)Thread

2021-07-16 22:43:10

Go并發(fā)Golang

2021-09-28 08:59:30

復原IP地址

2022-04-12 08:30:52

回調函數(shù)代碼調試

2022-10-20 07:39:26

2022-03-11 10:21:30

IO系統(tǒng)日志

2023-11-01 09:07:01

Spring裝配源碼
點贊
收藏

51CTO技術棧公眾號