九零不老心
发布于 2025-12-23 / 2 阅读 / 0 评论 / 0 点赞

Doris慎用create table tab as select *

作用

复制表结构和数据

create table test01 as select * from test02;

不建议使用的原因

doris中,“不会继承主键、分区分桶、表备注等结构”,默认是duplicate key

范例

比如原表ods_cnt_dyuser_mainurl的创建语句是

CREATE TABLE `ods_cnt_dyuser_mainurl` (
  `uid` varchar(512) NOT NULL COMMENT '抖音唯一uid',
  `sec_url` text NULL COMMENT '用户主页',
  `actiondatetime` text NULL COMMENT 'rpa更新时间戳',
  `dy_id` text NULL COMMENT '抖音号',
  `avatar` text NULL COMMENT '头像url',
  `total_favorited` text NULL COMMENT '总获赞数',
  `follower_count` text NULL COMMENT '粉丝总数',
  `signature` text NULL COMMENT '个性签名 / 简介'
) ENGINE=OLAP
UNIQUE KEY(`uid`)
COMMENT '抖音号用户主页sec_url'
DISTRIBUTED BY HASH(`uid`) BUCKETS 6

执行创建新表以后的语句create table test01 as select * from ods_cnt_dyuser_mainurl;

CREATE TABLE `test01` (
  `uid` varchar(65533) NOT NULL COMMENT '抖音唯一uid',
  `sec_url` text NULL COMMENT '用户主页',
  `actiondatetime` text NULL COMMENT 'rpa更新时间戳',
  `dy_id` text NULL COMMENT '抖音号',
  `avatar` text NULL COMMENT '头像url',
  `total_favorited` text NULL COMMENT '总获赞数',
  `follower_count` text NULL COMMENT '粉丝总数',
  `signature` text NULL COMMENT '个性签名 / 简介'
) ENGINE=OLAP
DUPLICATE KEY(`uid`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`uid`) BUCKETS 10

对比会发现 UNIQUE KEY变成了DUPLICATE KEY,表的comment也不一致BUCKETS个数也不一致