此次我处理的数据量大概在10w左右,一开始直接使用连接查询,效率极低。【甚至是查询40多分钟没能出结果这种情况】
后来在两个表中对我需要连接的列分别建立了非聚集索引。在这之后再进行连接查询时,效率简直不能再高了!!!【就1min之内结束了】
连接查询语句如下:
select * into orderInBeijing
from realytrain, mobike_beijing
where geohashed_loc = geohashed_start_loc or geohashed_loc = geohashed_end_loc
【其中realytrain表中有250w+条数据】
建立索引:
-- 创建唯一非聚集索引
create unique nonclustered --表示创建唯一非聚集索引
index UQ_Clu_geoLoc --索引名称
on mobike_beijing(geohashed_loc) --数据表名称(建立索引的列名)
with
(
pad_index=on, --表示使用填充
fillfactor=50, --表示填充因子为50%
ignore_dup_key=on, --表示向唯一索引插入重复值会忽略重复值
statistics_norecompute=off --表示启用统计信息自动更新功能
)
--创建非聚集索引
create nonclustered index NonClu_startLoc
on realytrain(geohashed_start_loc)
with (drop_existing=on);
create nonclustered index NonClu_endLoc
on realytrain(geohashed_end_loc)
with (drop_existing=on);
索引是个好东西呀!