公司網(wǎng)站維護(hù)都需要怎么做旅行網(wǎng)站排名前十名
分區(qū):
根據(jù)某一列進(jìn)行進(jìn)行劃分存儲(chǔ),常用的有時(shí)間分區(qū);
查詢數(shù)據(jù)時(shí)只需要掃描特定的分區(qū)數(shù)據(jù),不需要全盤掃描,節(jié)省時(shí)間,
方便數(shù)據(jù)歸檔和清理
創(chuàng)建分區(qū)表
create table table_name(
col1 int,
col2 string
)
partition by (dt string,country string);
插入分區(qū)
insert into table_name partition (dt='2024-06-19',country='china')
values(1,'data1'),(2,data2);
修改分區(qū)
alter table table_name partition ()
刪除分區(qū)
alter table table_name drop partition(dt='2024-06-18');
分桶:
將表數(shù)據(jù)按照哈希函數(shù)的結(jié)果進(jìn)行劃分存儲(chǔ),將數(shù)據(jù)均勻分不到桶中,提高了查詢的并行度和性能。
支持隨機(jī)抽樣
創(chuàng)建分桶
create table bucket_table_name(
col1 int,
col2 string
)
clustered by (col1) into 4 buckets
sorted by (col2);
插入數(shù)據(jù)
insert overwrite table bucket_table_name
select cols,col2
from table_name;
查詢分桶數(shù)據(jù)
select *
from
bucket_table_name
where col1=1;