日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

OpenSql的优化原则

發布時間:2024/10/12 60 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的优化原则的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。