资源描述:
《程式SQL优化规范ppt课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、PCEBG系統資訊處程式SQL優化經驗匯總SFC課程式開發組:周順明AGENDA一、程式SQL優化目的二、SQL语句优化規範與實例三、SQL优化工具四、SQL調整的目標程式SQL優化目的目的規範、統一SFCS的SQL語法.提升SQL語句的執行速度與程式的執行效率.降低數據庫負載,避免SQL引起DB負載異常,影響產線生產.透過實作,培養新人SQL優化概念,使新人程式開發技能更加全面、系統.SQL语句优化規範與實例ORACLE的解析器按照從右到左的順序處理FROM子句中的表名,所以由小至大去Table
2、例如:表TAB116,384條記錄表TAB21條記錄選擇TAB2作為基礎表(最好的方法)selectcount(*)fromtab1,tab2執行時間0.96秒選擇TAB2作為基礎表(不佳的方法)selectcount(*)fromtab2,tab1執行時間26.09秒1.選擇最有效率的表名順序1.選擇最有效率的表名順序實例煙台DMDIIIWEB有“Yieldratechart-byoneday”(查詢一天內各個工站生產數量及良率並Show出良率圖表)一支報表,Sql如下:(低效)10分38秒SE
3、LECTr.group_name,SUM(r.pass_qty)+SUM(r.fail_qty)total_qty,SUM(r.pass_qty)pass_qty,SUM(r.fail_qty)fail_qty,TO_CHAR(100*SUM(r.pass_qty)/DECODE((SUM(r.pass_qty)+SUM(r.fail_qty)),0,1(SUM(r.pass_qty)+SUM(r.fail_qty))),'990.99')yield_rate,SUM(r.repass_qty)r
4、epass_qty,SUM(r.refail_qty)refail_qty,g.group_codeFROMsfism4.r_mo_base_tkk,sfism4.r_station_rec_tr,(SELECTgroup_code,group_nameFROMsfis1.c_group_config_t)gWHEREr.work_id>=TO_CHAR(TO_DATE('2006/01/19','yyyy-mm-dd'),'yyyymmdd')
5、
6、'00'ANDr.work_id<=TO_CHA
7、R(TO_DATE('2006/01/19','yyyy-mm-dd'),'yyyymmdd')
8、
9、'25'ANDr.group_name<>'PTHINSPECT'ANDr.line_name='PTH0703'ANDkk.cust_no='FOXCONN'ANDr.mo_number=kk.mo_numberANDkk.mo_type='NORMAL'ANDr.group_name=g.group_nameANDr.group_nameIN('SMTINSPECT','INIT','TOUCH
10、UP','ICT','FFT','FVI','OQM','SI','IFT')GROUPBYr.group_name,g.group_codeORDERBYg.group_code優化後SQL語句如下:(高效)1秒SELECTr.group_name,SUM(r.pass_qty)+SUM(r.fail_qty)total_qty,SUM(r.pass_qty)pass_qty,SUM(r.fail_qty)fail_qty,TO_CHAR(100*SUM(r.pass_qty)/DECODE((
11、SUM(r.pass_qty)+SUM(r.fail_qty)),0,1(SUM(r.pass_qty)+SUM(r.fail_qty))),'990.99')yield_rate,SUM(r.repass_qty)repass_qty,SUM(r.refail_qty)refail_qty,g.group_codeFROMsfism4.r_station_rec_tr,sfism4.r_mo_base_tkk,(SELECTgroup_code,group_nameFROMsfis1.c_gro
12、up_config_t)gWHEREr.work_id>=TO_CHAR(TO_DATE('2006/01/19','yyyy-mm-dd'),'yyyymmdd')
13、
14、'00'ANDr.work_id<=TO_CHAR(TO_DATE('2006/01/19','yyyy-mm-dd'),'yyyymmdd')
15、
16、'25'ANDr.group_name<>'PTHINSPECT'ANDr.line_name='PTH0703'ANDkk.cust_no='FOXCONN'ANDr