OpenSql的优化原则
OpenSql的優化原則
Sql語句語法是否合理,將直接影響到程序的執行效率
?
1)要充分利用index,且index的字段盡量同時使用
2)盡量使用select? f1 f2。。。(具體字段)來代替select *寫法
3)使用up to n rows來實現對數據前n項的查詢
4)充分利用系統提供的標準函數,如:max,min,avg,sum,count等
5)盡量不要在頻率較高的循環語句中使用update \insert\delete\modify等操作
6)對于需要同時對多個表數據查詢時,盡量使用Join語句,且注意應選擇資料量最小的表作為基表,盡量避免3個以上Table?間的相關Join查詢
?
7)在查詢單條數據時盡量使用select single?語句,不要使用select.....endselect?語句
?
如:?select?id name discount?from?scustom
????????into?(? xid,xname,xdiscount )
????????where?custtype = 'B'
????????order by?discount.
????????write:/ xid,xname,xdiscount.
?????enselect
?
改進后:
?????????select single?id name discount?from?scustom
????????into?(? xid,xname,xdiscount )
????????where?custtype = 'B'
????????order by?discount.
????????write:/ xid,xname,xdiscount.
?
8)對于存在?OR條件判斷的語句中,盡量使用IN來代替
?
select?*?from?sflight
???????? ???into?xflight
???????? ?where?carrid = 'LH'
?????? and?( connid = '0300'?or?connid = '0302' )
???????? ??write:/ xflight-fldate.
endselect.
?
優化后:
?
select?*?from?sflight
???????into?xflight
???? where?carrid = 'LH'
???????and?connid?in( '0300','0302' )
????? write:/ xflight-fldate.
endselect.
9) where語句中盡量避免使用模糊查詢
轉載于:https://www.cnblogs.com/bailang-LBG/articles/3801125.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的OpenSql的优化原则的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: django - 替换admin的tex
- 下一篇: 读谷歌编码规范所想到的