日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Oracle大數據量查詢實際分析

系統 2092 0

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 ", 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='{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<=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.添加分區查詢

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條


所以加分區后的查詢效率提高十幾倍,所以大數據量建立分區表是相當重要的。




?

Oracle大數據量查詢實際分析


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 黎平县| 台东市| 丘北县| 天峨县| 聊城市| 明光市| 涟水县| 容城县| 无锡市| 凤庆县| 龙岩市| 广宗县| 辽源市| 青州市| 刚察县| 仙游县| 莒南县| 喀喇| 志丹县| 永宁县| 隆化县| 平阳县| 罗江县| 广丰县| 临泽县| 沙雅县| 镇宁| 娄底市| 天镇县| 巴彦县| 秦安县| 钦州市| 阿尔山市| 西青区| 南靖县| 延吉市| 桃江县| 石渠县| 迭部县| 武宣县| 宁阳县|