Oracle大数据量查询实际分析

php中文网
发布: 2016-06-07 17:31:39
原创
1585人浏览过

刚做一张5000万条数据的数据抽取,当前表同时还在继续insert操作,每分钟几百条数据。所以加分区后的查询效率提高十几倍,所以大

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='{0}'
                                    group by to_char(gpstime,'yyyy-MM-dd HH24:mi'))
                                    and carcode='{0}'
                                    and gpstime>(select nvl((select max(gpstime) from t_gps_carposition where carcode='{0}'),(select min(gpstime) from t_gps_record where carcode='{0}')) from dual)
                                    order by gpstime asc
                                    ) where rownum


一开始以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='{0}'
                                    group by to_char(gpstime,'yyyy-MM-dd HH24:mi'))
                                    and carcode='{0}'
                                    and gpstime>to_date('2011-11-1 00:00:00','yyyy-mm-dd HH24:mi:ss')
                                    order by gpstime asc
                                    ) where rownum


查询时间 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                                    order by gpstime asc

查询时间:3分29秒,共1426条

Shop7z网上购物系统至尊版
Shop7z网上购物系统至尊版

Shop7z网上购物系统支持电脑版+手机版+支付宝及微信支付,支持QQ和微信一键登陆,系统集众家之所长,大气超美观页面+手机版+商品组合套餐+限时抢购秒杀+图片批量上传+淘宝数据包导入+弹出式分类菜单+不同规格不同价格+新订单邮件通知+销售报表打印与Excel输出+物流跟踪打印查询+会员积分及优惠券+邮件群发+图片在线管理+销售统计报表+五种价格体系+礼品礼券+微信公众号支付+扫码支付等等等。

Shop7z网上购物系统至尊版 2
查看详情 Shop7z网上购物系统至尊版

4.添加分区查询

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                                    order by gpstime asc

添加分区后查询:17s,共1426条

所以加分区后的查询效率提高十几倍,所以大数据量建立分区表是相当重要的。

相关阅读:

Oracle 并行查询

Oracle用户信息查询操作语句

Oracle单表查询某列最大最小值的性能问题

回收站引发Oracle查询表空间使用缓慢

linux

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号