偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

一篇學(xué)會(huì) OpenGauss 分區(qū)表索引

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

[[422438]]

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

一、概述

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

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

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

  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ū)中的間隔語法可以自動(dòng)追加分區(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ù),會(huì)自動(dòng)增加一個(gè)以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; 
  • 默認(rèn)刪除分區(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.測試結(jié)果

-

添加分區(qū)

刪除分區(qū)

備注

全局索引

生效

默認(rèn)語法失效/update global index語法生效

索引失效后,需要reindex

本地索引

生效

生效

 

總結(jié):

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

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

三、示例

1.分區(qū)表準(zhǔn)備

  • 創(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); 
  • 默認(rèn)刪除分區(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.默認(rèn)刪除分區(qū)語法

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

關(guān)于作者

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

 

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

2021-07-02 09:45:29

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

2022-01-02 08:43:46

Python

2022-06-22 07:32:53

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

2022-08-29 08:00:11

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

2021-07-06 08:59:18

抽象工廠模式

2023-01-03 08:31:54

Spring讀取器配置

2021-07-05 22:11:38

MySQL體系架構(gòu)

2023-11-28 08:29:31

Rust內(nèi)存布局

2022-08-26 09:29:01

Kubernetes策略Master

2021-05-11 08:54:59

建造者模式設(shè)計(jì)

2022-08-23 08:00:59

磁盤性能網(wǎng)絡(luò)

2022-02-07 11:01:23

ZooKeeper

2021-12-07 08:50:40

字母區(qū)間字符串

2021-07-29 07:55:20

React實(shí)踐代碼

2021-09-06 06:31:40

理解動(dòng)態(tài)規(guī)劃

2021-09-14 07:26:26

組合問題循環(huán)

2022-06-30 22:53:18

數(shù)據(jù)結(jié)構(gòu)算法

2021-08-01 07:19:16

語言OpenrestyNginx

2021-09-13 09:00:03

istio安裝部署

2021-11-30 19:58:51

Java問題排查
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號