KingbaseES 分区表修改字段类型
KingbaseES普通表修改表结构请参考:KingbaseES变更表结构表重写问题
数据类型转换重写与不重写:
- varchar(x) 转换到 varchar(y) 当 y>=x,不需要重写。
- numeric(x,z) 转换到 numeric(y,z) 当 y>=x,或者不指定精度类型,不需要重写。
- numeric(x,c) 转换到 numeric(y,z) 当 y=x c>z,当numeric数据类型标度不一致时,需要重写。
- varbit(x) 转换到 varbit(y) 当 y>=x,不需要重写。
- timestamp(x) 转换到 timestamp(y) 当 y>=x,或者转换为timestamp,不需要重写。
- timestamptz(x) 转换到 timestamptz(y) 当 y>=x,或者转换为timestamptz,不需要重写。
- interval(x) 转换到 interval(y) 当 y>=x ,或者转换为interval,不需要重写。
- timestamp 转换到 text、varchar、varchar(n),char(n),需要重写。
- timestamp(x)转换到 text、varchar、varchar(n)、char(n),n>=x,需要重写。
- text 转换到 char、char(x)、varchar(n),需要重写。
- text 转换到 varchar,不需要重写。
- numeric(x) 转换到 numeric(y),y>=x,不需要重写。
- numeric(x) 转换到 numeric,不需要重写。
- numeric(x,y) 转换到 numeric,不需要重写。
一、普通表的修改:
普通表数据类型长度或者精度由小改大表不会重写,索引也不会重写。
test=# create table t01(id int,name varchar(10));
CREATE TABLE
test=# insert into t01 select generate_series(1,10),substr(md5(random()::text),1,10);
INSERT 0 10
test=# create index on t01 (name);
CREATE INDEX
test=# \d t01
Table "public.t01"
Column | Type | Collation | Nullable | Default
--------+----------------------------+-----------+----------+---------
id | integer | | |
name | character varying(10 char) | | |
Indexes:
"t01_name_idx" btree (name)
test=#
test=# select sys_relation_filenode('t01'),sys_relation_filenode('t01_name_idx');
SYS_RELATION_FILENODE | SYS_RELATION_FILENODE
-----------------------+-----------------------
289043 | 289046
(1 row)
# 设置客户端消息级别client_min_messages=debug5
test=# set client_min_messages=debug5;
# 修改t01表name字段长度varchar(10)为varchar(15)
test=# alter table t01 alter column name type varchar(15);
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: EventTriggerInvoke 267860
DEBUG: rehashing catalog cache id 68 for sys_recyclebin; 33 tups, 16 buckets
DEBUG: EventTriggerInvoke 13761
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 428092/1/7
ALTER TABLE
test=# select sys_relation_filenode('t01'),sys_relation_filenode('t01_name_idx');
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
SYS_RELATION_FILENODE | SYS_RELATION_FILENODE
-----------------------+-----------------------
289043 | 289046
(1 row)
test=#
分区表修改表结构是否跟普通表一样?
二、分区表的修改:
分区表分区键无法修改数据类型,本测试只针对非分区键进行测试。
create table tb(id bigint,pdate date,info varchar2(10)) partition by range(pdate) INTERVAL ('1 MONTH'::INTERVAL)
(
PARTITION tb_p0 VALUES LESS THAN ('2023-01-01'),
PARTITION tb_p1 VALUES LESS THAN ('2023-02-01'),
PARTITION tb_p2 VALUES LESS THAN ('2023-03-01'),
PARTITION tb_p3 VALUES LESS THAN ('2023-04-01')
);
CREATE TABLE
insert into tb select generate_series(1,100),'2023-01-01'::date,substr(md5(random()::text),1,10);
INSERT 0 100
insert into tb select generate_series(101,200),'2023-02-01'::date,substr(md5(random()::text),1,10);
INSERT 0 100
insert into tb select generate_series(201,300),'2023-03-01'::date,substr(md5(random()::text),1,10);
INSERT 0 100
2.1.分区表非索引列数据类型的修改:
修改非索引列的类型:由小改大,表不会发生重写,索引自然也没有发生重写。
修改非索引列的类型:由大改小,遵循KingbaseES变更表结构表重写规则,表需要重写,索引也需要重写。
test=# set client_min_messages =debug5;
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
SET
test=# select oid,relname from sys_class where relname='tb';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+---------
289063 | tb
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p0';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289066 | tb_tb_p0
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p1';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289069 | tb_tb_p1
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p2';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289072 | tb_tb_p2
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p3';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289075 | tb_tb_p3
(1 row)
# 修改tb分区表info列为varchar(20)
test=# alter table tb alter column info type varchar(20);
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: EventTriggerInvoke 267860
DEBUG: EventTriggerInvoke 13761
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 428111/1/10
ALTER TABLE
test=# select oid,relname from sys_class where relname='tb';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+---------
289063 | tb
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p0';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289066 | tb_tb_p0
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p1';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289069 | tb_tb_p1
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p2';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289072 | tb_tb_p2
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p3';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289075 | tb_tb_p3
(1 row)
test=# alter table tb alter column info type varchar(30);
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: EventTriggerInvoke 267860
DEBUG: EventTriggerInvoke 13761
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 428112/1/10
ALTER TABLE
test=# select oid,relname from sys_class where relname='tb';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+---------
289063 | tb
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p0';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289066 | tb_tb_p0
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p1';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289069 | tb_tb_p1
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p2';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289072 | tb_tb_p2
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p3';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289075 | tb_tb_p3
(1 row)
分区表修改非索引列字段长度或者是精度由小变大,跟普通表一样,不需要重写。
2.2.分区表全局(GLOBAL)索引列数据类型的修改:
修改全局(GLOBAL)索引列的类型:由小改大,表不会发生重写,索引也没有发生重写。
修改全局(GLOBAL)索引列的类型:由大改小,遵循KingbaseES变更表结构表重写规则,表需要重写,索引也需要重写。
test=# \d+ tb
Partitioned table "public.tb"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+----------------------------+-----------+----------+---------+----------+--------------+-------------
id | bigint | | | | plain | |
pdate | date | | | | plain | |
info | character varying(10 char) | | not null | | extended | |
Partition key: RANGE (pdate)
Range interval: INTERVAL ('0-1'::pg_catalog.interval)
Partitions: tb_tb_p0 FOR VALUES FROM (MINVALUE) TO ('2023-01-01 00:00:00'),
tb_tb_p1 FOR VALUES FROM ('2023-01-01 00:00:00') TO ('2023-02-01 00:00:00'),
tb_tb_p2 FOR VALUES FROM ('2023-02-01 00:00:00') TO ('2023-03-01 00:00:00'),
tb_tb_p3 FOR VALUES FROM ('2023-03-01 00:00:00') TO ('2023-04-01 00:00:00')
# 添加主键
test=# alter table tb add constraint tb_pk primary key (info);
ALTER TABLE
test=# \d+ tb
Partitioned table "public.tb"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+----------------------------+-----------+----------+---------+----------+--------------+-------------
id | bigint | | | | plain | |
pdate | date | | | | plain | |
info | character varying(10 char) | | not null | | extended | |
Partition key: RANGE (pdate)
Range interval: INTERVAL ('0-1'::pg_catalog.interval)
Indexes:
"tb_pk" PRIMARY KEY, btree (info) INCLUDE (tableoid) GLOBAL
Partitions: tb_tb_p0 FOR VALUES FROM (MINVALUE) TO ('2023-01-01 00:00:00'),
tb_tb_p1 FOR VALUES FROM ('2023-01-01 00:00:00') TO ('2023-02-01 00:00:00'),
tb_tb_p2 FOR VALUES FROM ('2023-02-01 00:00:00') TO ('2023-03-01 00:00:00'),
tb_tb_p3 FOR VALUES FROM ('2023-03-01 00:00:00') TO ('2023-04-01 00:00:00')
test=# select sys_relation_filepath('tb_pk');
SYS_RELATION_FILEPATH
-----------------------
base/12176/289111
(1 row)
test=# select oid,relname from sys_class where relname='tb';
OID | RELNAME
--------+---------
289063 | tb
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p0';
OID | RELNAME
--------+----------
289066 | tb_tb_p0
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p1';
OID | RELNAME
--------+----------
289069 | tb_tb_p1
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p2';
OID | RELNAME
--------+----------
289072 | tb_tb_p2
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p3';
OID | RELNAME
--------+----------
289075 | tb_tb_p3
(1 row)
test=# alter table tb alter info type varchar(20);
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: EventTriggerInvoke 267860
DEBUG: drop auto-cascades to index tb_pk
DEBUG: EventTriggerInvoke 13761
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 428121/1/19
ALTER TABLE
test=# select sys_relation_filepath('tb_pk');
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
SYS_RELATION_FILEPATH
-----------------------
base/12176/289111
(1 row)
test=# select oid,relname from sys_class where relname='tb';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+---------
289063 | tb
(1 row)
test=# select oid,relname from sys_class where relname='tb_tb_p2';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+----------
289072 | tb_tb_p2
(1 row)
# 添加全局索引
test=# create unique index on tb(id,info) global;
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: EventTriggerInvoke 267860
DEBUG: building index "tb_id_info_idx" on table "tb" serially
DEBUG: EventTriggerInvoke 13761
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 428122/1/4
CREATE INDEX
test=# \d+ tb
Partitioned table "public.tb"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+----------------------------+-----------+----------+---------+----------+--------------+-------------
id | bigint | | | | plain | |
pdate | date | | | | plain | |
info | character varying(20 char) | | not null | | extended | |
Partition key: RANGE (pdate)
Range interval: INTERVAL ('0-1'::pg_catalog.interval)
Indexes:
"tb_pk" PRIMARY KEY, btree (info) INCLUDE (tableoid) GLOBAL
"tb_id_info_idx" UNIQUE, btree (id, info) INCLUDE (tableoid) GLOBAL
Partitions: tb_tb_p0 FOR VALUES FROM (MINVALUE) TO ('2023-01-01 00:00:00'),
tb_tb_p1 FOR VALUES FROM ('2023-01-01 00:00:00') TO ('2023-02-01 00:00:00'),
tb_tb_p2 FOR VALUES FROM ('2023-02-01 00:00:00') TO ('2023-03-01 00:00:00'),
tb_tb_p3 FOR VALUES FROM ('2023-03-01 00:00:00') TO ('2023-04-01 00:00:00')
test=# select sys_relation_filepath('tb_pk');
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
SYS_RELATION_FILEPATH
-----------------------
base/12176/289111
(1 row)
test=# select sys_relation_filepath('tb_id_info_idx');
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
SYS_RELATION_FILEPATH
-----------------------
base/12176/289115
(1 row)
test=# alter table tb alter info type varchar(30);
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: EventTriggerInvoke 267860
DEBUG: drop auto-cascades to index tb_pk
DEBUG: EventTriggerInvoke 13761
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 428123/1/27
ALTER TABLE
test=# select sys_relation_filepath('tb_pk');
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
SYS_RELATION_FILEPATH
-----------------------
base/12176/289111
(1 row)
test=# select sys_relation_filepath('tb_id_info_idx');
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
SYS_RELATION_FILEPATH
-----------------------
base/12176/289115
(1 row)
分区表修改全局(GLOBAL)索引列字段长度或者是精度由小变大,跟普通表一样,不需要重写。
2.3.分区表本地(LOCAL)索引列数据类型的修改:
修改本地(LOCAL)索引列的类型:由小改大,表不会发生重写,索引发生重写。
修改本地(LOCAL)索引列的类型:由大改小,遵循KingbaseES变更表结构表重写规则,表需要重写,索引也需要重写。
test=# \d+ tb
Partitioned table "public.tb"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+----------------------------+-----------+----------+---------+----------+--------------+-------------
id | bigint | | | | plain | |
pdate | date | | | | plain | |
info | character varying(30 char) | | not null | | extended | |
Partition key: RANGE (pdate)
Range interval: INTERVAL ('0-1'::pg_catalog.interval)
Indexes:
"tb_pk" PRIMARY KEY, btree (info) INCLUDE (tableoid) GLOBAL
"tb_id_info_idx" UNIQUE, btree (id, info) INCLUDE (tableoid) GLOBAL
Partitions: tb_tb_p0 FOR VALUES FROM (MINVALUE) TO ('2023-01-01 00:00:00'),
tb_tb_p1 FOR VALUES FROM ('2023-01-01 00:00:00') TO ('2023-02-01 00:00:00'),
tb_tb_p2 FOR VALUES FROM ('2023-02-01 00:00:00') TO ('2023-03-01 00:00:00'),
tb_tb_p3 FOR VALUES FROM ('2023-03-01 00:00:00') TO ('2023-04-01 00:00:00')
# 创建本地索引
test=# create index on tb(pdate,info);
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: EventTriggerInvoke 267860
DEBUG: building index "tb_tb_p0_pdate_info_idx" on table "tb_tb_p0" serially
DEBUG: building index "tb_tb_p1_pdate_info_idx" on table "tb_tb_p1" serially
DEBUG: building index "tb_tb_p2_pdate_info_idx" on table "tb_tb_p2" serially
DEBUG: building index "tb_tb_p3_pdate_info_idx" on table "tb_tb_p3" serially
DEBUG: EventTriggerInvoke 13761
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 428125/1/12
CREATE INDEX
test=# \d+ tb
Partitioned table "public.tb"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+----------------------------+-----------+----------+---------+----------+--------------+-------------
id | bigint | | | | plain | |
pdate | date | | | | plain | |
info | character varying(30 char) | | not null | | extended | |
Partition key: RANGE (pdate)
Range interval: INTERVAL ('0-1'::pg_catalog.interval)
Indexes:
"tb_pk" PRIMARY KEY, btree (info) INCLUDE (tableoid) GLOBAL
"tb_id_info_idx" UNIQUE, btree (id, info) INCLUDE (tableoid) GLOBAL
"tb_pdate_info_idx" btree (pdate, info)
Partitions: tb_tb_p0 FOR VALUES FROM (MINVALUE) TO ('2023-01-01 00:00:00'),
tb_tb_p1 FOR VALUES FROM ('2023-01-01 00:00:00') TO ('2023-02-01 00:00:00'),
tb_tb_p2 FOR VALUES FROM ('2023-02-01 00:00:00') TO ('2023-03-01 00:00:00'),
tb_tb_p3 FOR VALUES FROM ('2023-03-01 00:00:00') TO ('2023-04-01 00:00:00')
test=# select sys_relation_filepath('tb_pk'),sys_relation_filepath('tb_id_info_idx');
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
SYS_RELATION_FILEPATH | SYS_RELATION_FILEPATH
-----------------------+-----------------------
base/12176/289111 | base/12176/289115
(1 row)
test=# select oid,relname from sys_class where relname='tb_pdate_info_idx';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+-------------------
289119 | tb_pdate_info_idx
(1 row)
# 修改本地索引依赖info列
test=# alter table tb alter info type varchar(40);
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: EventTriggerInvoke 267860
DEBUG: drop auto-cascades to index tb_tb_p0_pdate_info_idx
DEBUG: drop auto-cascades to index tb_tb_p1_pdate_info_idx
DEBUG: drop auto-cascades to index tb_tb_p2_pdate_info_idx
DEBUG: rehashing catalog cache id 68 for sys_recyclebin; 33 tups, 16 buckets
DEBUG: drop auto-cascades to index tb_tb_p3_pdate_info_idx
DEBUG: drop auto-cascades to index tb_pk
DEBUG: building index "tb_tb_p0_pdate_info_idx" on table "tb_tb_p0" serially
DEBUG: building index "tb_tb_p1_pdate_info_idx" on table "tb_tb_p1" serially
DEBUG: building index "tb_tb_p2_pdate_info_idx" on table "tb_tb_p2" serially
DEBUG: building index "tb_tb_p3_pdate_info_idx" on table "tb_tb_p3" serially
DEBUG: EventTriggerInvoke 13761
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 428127/1/51
ALTER TABLE
test=# select sys_relation_filepath('tb_pk'),sys_relation_filepath('tb_id_info_idx');
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
SYS_RELATION_FILEPATH | SYS_RELATION_FILEPATH
-----------------------+-----------------------
base/12176/289111 | base/12176/289115
(1 row)
test=# select oid,relname from sys_class where relname='tb_pdate_info_idx';
DEBUG: StartTransaction(1) name: unnamed; blockState: DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
DEBUG: CommitTransaction(1) name: unnamed; blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0
OID | RELNAME
--------+-------------------
289127 | tb_pdate_info_idx
(1 row)
test=#
分区表本地(LOCAL)索引列修改字段长度或者是精度由小变大,表、全局索引不需要重写,但是本地索引需要重写。
2.4.分区表修改表结构总结:
分区表修改非索引列字段长度或者是精度由小变大,跟普通表一样,不需要重写。
分区表修改全局(GLOBAL)索引列字段长度或者是精度由小变大,跟普通表一样,不需要重写。
分区表本地(LOCAL)索引列修改字段长度或者是精度由小变大,表、全局索引不需要重写,但是本地索引需要重写。
三、分区表变更表结构的思考:
通过以上测试可知:分区表修改本地索引依赖字段长度或者标度会导致索引重写。
如果分区表数据量大、子分区多、字段列依赖的索引多,修改分区表(本地索引)列字段长度会发生如下问题:
修改字段长度由小到大:分区表所有的子表不会发生重写,但是索引会发生重写,索引越多阻塞时间越长。
目前想到的解决方法:删除被修改列依赖的所有本地索引,避免长时间的AccessExclusiveLock,修改完成后子表使用concurrently的方式创建。
修改字段长度由大到小:分区表所有的子表都会发生重写,只要表发生重写所有的索引都需要重写,此过程会导致业务不可用(影响太大)。
对分区表使用detach?分区表要求所有子分区的表结构必须跟父表一致,所有的子分区全部修改完成后再attach回去,跟直接改区别不大,可以避免业务中断。需要根据业务提前准备好脚本。
KingbaseES 分区表修改字段类型的更多相关文章
- PostgreSQL 修改字段类型从int到bigint
由于现在pg的版本,修改int到bigint仍然需要rewrite表,会导致表阻塞,无法使用.但可以考虑其他方式来做.此问题是排查现网pg使用序列的情况时遇到的. 由于int的最大值只有21亿左右,而 ...
- sqlServer 2008修改字段类型和重命名字段名称的sql语句
sqlServer 2008修改字段类型和重命名字段名称的sql语句 //修改字段的类型 alter table fdi_news alter column c_author nvarchar(50) ...
- Oracle/SQL 修改字段类型和长度
标准SQL修改字段类型和长度语句: ALTER TABLE tableName modify column columnName 类型;例如Mysql的修改字段类型语句:alter table tes ...
- Mysql字段操作—增加字段、删除字段、修改字段名、修改字段类型(约束条件)
1.增加字段: alter table tablename add new_field_id type not null default '0'; 例: a ...
- oracle如何修改字段类型(oracle总体知识2)
在一次做开发的时候,遇到需要将数据表的字段类型由number改成varchar,可是该字段又有值, 用 alter table t-name modify cname newType;会报错. 话说 ...
- Oracle修改字段类型和长度
Oracle修改字段名 alter table 表名 rename column 旧字段名 to 新字段名 Oracle修改字段类型和长度 alter table 表名 modify 字段名 数据类型 ...
- sql语句修改字段类型和增加字段
/*修改字段类型*/ ) go /*增加字段和说明*/ ) EXECUTE sp_addextendedproperty N'MS_Description','说明文字',N'user',N'dbo' ...
- Oracle创建表、修改字段类型
1.创建表 1.创建表 create table SCM_PER( --SCM_PER表名 ID ) primary key,--主键ID USERID ),--用户ID --Permission v ...
- Oracle基本操作,Oracle修改列名,Oracle修改字段类型
oracle基本操作,Oracle修改列名,Oracle修改字段类型 >>>>>>>>>>>>>>>>& ...
- 曲演杂坛--使用ALTER TABLE修改字段类型的吐血教训
--===================================================================== 事件起因:开发发现有表插入数据失败,查看后发现INT类型 ...
随机推荐
- PC端应用程序自动化测试——pywinauto、pywin32、pyautogui
1 前言 PC 端自动化测试使用到的 python 模块主要有 pywinauto.win32gui.pyautogui,主要功能如下: pywinauto:主要使用到 Application 类,用 ...
- Laravel入坑指南(5)——请求与响应
作为互联网典型的Web应用,接收用户请求的数据,并将处理的结果向用户进行响应,是最基础也是最必备的功能.在原生的PHP中,我们常用$_POST.$_GET.$_REQUEST和$_FILES对不同的请 ...
- oracle中使用自定义函数解析指定分隔符的字符串
1.创建字符串表类型 create type tab_varchar is table of varchar2(2000); 2.创建管道函数 create or replace function g ...
- 发送HTML模板邮件
概述 为了增强邮件内容展示的样式,可以将普通的文本邮件转换为HTML内容格式. 在Java中,可以通过页面模板技术来实现.具体来说,可以使用Thymeleaf模板. 具体实现 首先,在项目中引入Thy ...
- Git 分支管理参考模型
一个值得参考的Git分支管理模型如下: master 生产主分支,发布到生产环境使用这个分支,由hotfix或者release分支合并过来,不直接提交代码. release 预发布分支, 基于feat ...
- django1.11和django2.2中namespace的用法
django1.11中namespace用法 urlpatterns = [ url(r'^user/', include('user.urls', namespace='user')) ] djan ...
- ubuntu 中 docker 每次都输入 sudo 命令
查看用户组及成员 sudo cat /etc/group | grep docker 可以添加docker组 sudo groupadd docker 添加用户到docker组 sudo gpassw ...
- 手写web框架
重新认识HTTP http请求报文包含三个部分(请求行 + 请求头 + 请求体) 请求行 请求行包含三个内容: method + request-URI + http-version -- 例如 GE ...
- 【Azure API 管理】 为APIM创建一个审批订阅申请的RBAC角色,最少的Action内容是什么呢?
问题描述 在使用APIM服务中,需要为专门的一组用户赋予特殊的权限:审批APIM用户的对产品的订阅.需要自定义一个RBAC角色,那么如何来设置最少的Action满足需求呢? 问题解答 要对APIM订阅 ...
- 【Azure Redis 缓存】定位Java Spring Boot 使用 Jedis 或 Lettuce 无法连接到 Redis的网络连通性步骤
问题描述 Java Spring Boot的代码在IDE里面跑可以连上 Azure 的 Redis服务,打包成Image放在容器里面跑,就连不上azure的redis服务,错误消息为: Unable ...