GBase 8a
运维管理
文章

GBase 8a将Hash分布表转成随机分布表的方法

发表于2024-11-08 15:04:5461次浏览2个评论

一张id为分布列的hash分布表。

gbase> create table t_hash(id int, name varchar(100))distributed by('id');
Query OK, 0 rows affected (Elapsed: 00:00:00.66)

gbase> show create table t_hash;
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table  | Create Table                                                                                                                                                                   |
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t_hash | CREATE TABLE "t_hash" (
 "id" int(11) DEFAULT NULL,
 "name" varchar(100) DEFAULT NULL
) ENGINE=EXPRESS DISTRIBUTED BY('id') DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace' |
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)

重建表

该方法适合所有版本,无任何风险。

新建一张表,表结构与hash分布表一样,但去掉hash分布列

create table t_nohash(id int, name varchar(100));
insert into t_nohash select * from t_hash;
rename table t_hash to t_hash_BAK;
reanem table t_nohash to t_hash ;
如上的rename操作确认所有业务正常后,可以考虑删除t_hash_BAK表以便节省空间。

删除hash列关键字

该方法在9.5的手册里出现,86未注意,但预计能用。

gbase> drop distributed column on t_hash;
Query OK, 0 rows affected (Elapsed: 00:00:00.02)

gbase> show create table t_hash;
+--------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table  | Create Table                                                                                                                                              |
+--------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
| t_hash | CREATE TABLE "t_hash" (
 "id" int(11) DEFAULT NULL,
 "name" varchar(100) DEFAULT NULL
) ENGINE=EXPRESS DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace' |
+--------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)

评论

登录后才可以发表评论
崔哥发表于 8个月前
评论是一种尊重
崔哥发表于 7个月前
终南阴岭秀,积雪浮云端。林表明霁色,城中增暮寒。