1. Truncate
语法:truncate table table_name ;
truncate table用于删除表中的所有行,而不记录单个删除操作;
速度快,使用的系统资源和事务日志资源更好;
能针对具有自动递增的字段,做计数重置归零重新计算的作用,只能作用于表;
2. union
语法:
select column1, colmn2, ... from table1
union
select column1, colmn2, ... from table2
操作符用于合并两个或多个select语句的结果集;
union内部的select语句必须拥有相同数量的列,列也必须拥有相似的数据类型;
每条select语句中列的顺序必须相同;
3. union all
union all操作符合并的结果集,不会允许重复值,如果允许有重复值的话,使用union all;
规则同上;
4.声明表的分布策略
gp的分布键作用是保证数据能够均匀分布在不同的存储节点上,充分利用并行计算带来的高性能。
gp包含Hash分布和随机分布。
hash分布:distributed by(列名)
随机分布:disrributed by randonly
在创建表或者修改表定义的时候,必须使用distributed by 来执行分布键,从而使数据均匀的存储在不同的Segment上。
如果致命的分布键(列名)不是主键,则无法创建(指定的列必须是主键)。
(1)声明hash分布
create table 表名(
id integer primary key, {主键约束}
name text not null, {非空约束}
price numeric check(price>0), {检查约束}
type integer unique {唯一约束}
) distributed by(id);
(2)声明随机分布
create table 表名(
id integer primary key, {主键约束,这里就不能在声明主键约束}
name text not null, {非空约束}
price numeric check(price>0), {检查约束}
type integer unique {唯一约束,这里就不能在声明唯一约束}
) distributed by randonly; {指定随机分布}
5.distinct 唯一值
语法:select col1, distinct col2 from ......
select distinct col1, col2, col3, ...... from ......