分区:
 根据某一列进行进行划分存储,常用的有时间分区;
 查询数据时只需要扫描特定的分区数据,不需要全盘扫描,节省时间,
 方便数据归档和清理
创建分区表
 create table table_name(
 col1 int,
 col2 string
 )
 partition by (dt string,country string);
插入分区
 insert into table_name partition (dt='2024-06-19',country='china')
 values(1,'data1'),(2,data2);
修改分区
 alter table table_name partition ()
 删除分区
 alter table table_name drop partition(dt='2024-06-18');
分桶:
 将表数据按照哈希函数的结果进行划分存储,将数据均匀分不到桶中,提高了查询的并行度和性能。
 支持随机抽样
创建分桶
create table bucket_table_name(
 col1 int,
 col2 string
 )
 clustered by (col1) into 4 buckets
 sorted by (col2);
插入数据
 insert overwrite table bucket_table_name
 select cols,col2
 from table_name;
查询分桶数据
 select *
 from
 bucket_table_name
 where col1=1;