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类型 ...
随机推荐
- 【Unity3D】UGUI之Button
1 Button属性面板 在 Hierarchy 窗口右键,选择 UI 列表里的 Button 控件,即可创建 Button 控件,选中创建的 Button 控件,按键盘[T]键,可以调整 But ...
- lib,dll的位置
在添加第三方库的时候需要注意放置的路径,注意区分x86和x64的文件夹路径以及VS的版本,不要放错了 lib的位置:(需要先将lib放到该路径下,不然会说找不到.lib)C:\Program File ...
- 【架构师视角系列】QConfig配置中心系列之Client端(二)
目录 声明 配置中心系列文章 一.架构 一.客户端架 1.Server 职责 (1)配置管理 (2)配置发布 (3)配置读取 2.Client 职责 (1)配置拉取 (2)配置注入 (3)配置变更监听 ...
- 07、Etcd 中Raft算法简介
本篇内容主要来源于自己学习的视频,如有侵权,请联系删除,谢谢. 思考: etcd是如何基于Raft来实现高可用.数据强-致性的? 1.什么是Raft算法 Raft 算法是现在分布式系统开发首选的共识算 ...
- 【API Management】使用 APIM Inbound Policy 来修改Content‐Type Header的值
问题描述 在使用APIM提供API服务管理的场景中,遇见了客户端请求时候发送的请求Header中的Content-Type不满足后台服务器的要求,但是在客户端要求客户修改代码难度较高. 所以面对这样的 ...
- 【Azure 存储服务】Azure Blob Storage SDK 升级失败,遇见 Unsatisfied Dependency Exception 和 Unexpected Length Exception
问题描述 在升级Java Azure Blob Storage SDK的过程中,先后遇见了 UnsatisfiedDependencyException 和 UnexpectedLengthExcep ...
- 【Azure API 管理】通过Java APIM SDK创建一个新的API,如何为Reqeust的Representation设置一个内容示例(Sample)?
问题描述 在使用API Management服务时,以Echo API(默认创建)举例,它会在Request的body部分默认设置一个SAMPLE指,这样在测试接口时候,就会有默认的Body内容,我们 ...
- PHP项目&MVC文件安全&上传&包含&下载&删除&读取等
文件安全-文件包含-动态调试-xhcms 1.安装好xhcms,查看index.php文件. 2.存在include关键字,可以存在文件包含漏洞.看上面代码的逻辑,对r的传参添加魔术引号,如果r没有值 ...
- uniapp+定时云函数保活replit
在replit中运行起来后,如果没有请求,则会在5分钟后关机,所以需要一个进程来定时访问一下,以达到保活的目的.replit是什么?我的理解是:它是一个在线的IDE,前端项目可以直接跑起来,且repl ...
- Java 接口:比较对象的大小
1 package com.bytezreo.interfacetest; 2 3 /** 4 * 5 * @Description 接口:比较对象的大小 6 * @author Bytezero·z ...