首页 > 大数据 > 数据分析 > Oracle大数据量查询实际分析
Oracle大年夜数据量查询真际阐收
Oracle数据库:
刚做一张5000万条数据的数据抽取,当前表同时借在继尽insert操做,每分钟几百条数据。
该表按照时候,以月份为单位做的表分区,没有任何索引,当前共有14个字段,仄均每个字段30个字节。当前表分区从201101到201512每月一个分区
>
测试效劳器:xeno 5650,32核cpu,win2003操做系统,物理内存16G;测试工具plsql
1.最开初的查询:
string.Format(@"select * from (select r.id,r.carcode,r.longtitude,r.latitude,r.velocity,r.gpstime,r.isonline from t_gps_record r where id in( select min(id) from t_gps_record r where carcode="" group by to_char(gpstime,"yyyy-MM-dd HH24:mi")) and carcode="" and gpstime>(select nvl((select max(gpstime) from t_gps_carposition where carcode=""),(select min(gpstime) from t_gps_record where carcode="")) from dual) order by gpstime asc ) where rownum<=200 ", row["carcode"].ToString());
一开初以200条数据为段停止查询,查询一次2分钟16秒;
后来查20条,2分钟14秒;根基跟条数无闭。
2.后来把最小时候写成安稳的:
string.Format(@"select * from (select r.id,r.carcode,r.longtitude,r.latitude,r.velocity,r.gpstime,r.isonline from t_gps_record r where id in( select min(id) from t_gps_record r where carcode="" group by to_char(gpstime,"yyyy-MM-dd HH24:mi")) and carcode="" and gpstime>to_date("2011-11-1 00:00:00","yyyy-mm-dd HH24:mi:ss") order by gpstime asc ) where rownum<=200 ", row["carcode"].ToString());
查询时候 1分34秒。
3.不加分区查询
select r.id,r.carcode,r.longtitude,r.latitude,r.velocity,r.gpstime,r.isonline from t_gps_record r where id in( select min(id) from t_gps_record r group by carcode, to_char(gpstime,"yyyy-MM-dd HH24:mi")) and gpstime>=to_date("2011-11-1 9:00:00","yyyy-mm-dd HH24:mi:ss") and gpstime<=to_date("2011-11-1 9:59:59","yyyy-mm-dd HH24:mi:ss") order by gpstime asc
查询时候:3分29秒,共1426条
4.添加分区查询
12345 select r.id,r.carcode,r.longtitude,r.latitude,r.velocity,r.gpstime,r.isonline from t_gps_record r where id in( select min(id) from t_gps_record partition(GPSHISTORY201111) r group by carcode, to_char(gpstime,"yyyy-MM-dd HH24:mi")) and gpstime>=to_date("2011-11-1 9:00:00","yyyy-mm-dd HH24:mi:ss") and gpstime<=to_date("2011-11-1 9:59:59","yyyy-mm-dd HH24:mi:ss") order by gpstime asc
添加分区后查询:17s,共1426条
所以加分区后的查询效率进步十几倍,所以大年夜数据量竖立分区表是相等重要的。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/14306196/viewspace-1121049/ ,如需转载,请注明出处,否则将追究法律责任。