91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

SQLServer如何使用UNION代替OR提升查詢性能

發布時間:2021-03-09 16:11:40 來源:億速云 閱讀:367 作者:小新 欄目:數據庫

這篇文章主要介紹SQLServer如何使用UNION代替OR提升查詢性能,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

  SQLServer數據庫查詢的過程中,通過對SQL語句的優化來提高SQL查詢的性能。下面億速云小編來講解下SQLServer怎么使用UNION代替OR提升查詢性能?

  SQLServer怎么使用UNION代替OR提升查詢性能

  SQL>settimingonSQL>setautotraceonSQL>selectcount(*)rowcount_lhy2fromswgl_ddjbxxt3wheret。fzgs_dm='001085'4and(t。lrr_dm='e90e3fe4237c4af988477329c7f2059e'orexists5(selecty。kh_id6fromkhgl_khywdlxxy7wherey。kh_id=t。kh_id8andy。sskhjl_dm='e90e3fe4237c4af988477329c7f2059e')or9t。kpr_dm='e90e3fe4237c4af988477329c7f2059e')10andt。xjbz='9999'11andt。FROMNBGL1='0';SQL>setline300SQL>/ROWCOUNT_LHY————————60已用時間:00:00:20。53執行計劃——————————————————————————————————————Planhashvalue:1217125969——————————————————————————————————————————————————————————————————————|Id|Operation|Name|Rows|Bytes|Cost(%CPU)|Time|——————————————————————————————————————————————————————————————————————|0|SELECTSTATEMENT||1|86|28048(1)|00:05:37||1|SORTAGGREGATE||1|86||||*2|FILTER|||||||*3|TABLEACCESSFULL|SWGL_DDJBXX|5926|497K|28048(1)|00:05:37||*4|TABLEACCESSBYINDEXROWID|KHGL_KHYWDLXX|1|57|5(0)|00:00:01||*5|INDEXRANGESCAN|IDX_KHGL_KHYWDLXX_KHID|1||3(0)|00:00:01|————————————————————————————————————————————————————————————————————PredicateInformation(identifiedbyoperationid):——————————————————————————————————-2-filter("T"。"LRR_DM"='e90e3fe4237c4af988477329c7f2059e'OR"T"。"KPR_DM"='e90e3fe4237c4af988477329c7f2059e'OREXISTS(SELECT0FROM"KHGL_KHYWDLXX""Y"WHERE"Y"。"KH_ID"=:B1AND"Y"。"SSKHJL_DM"='e90e3fe4237c4af988477329c7f2059e'))3-filter("T"。"FROMNBGL1"='0'AND"T"。"XJBZ"='9999'AND"T"。"FZGS_DM"='001085')4-filter("Y"。"SSKHJL_DM"='e90e3fe4237c4af988477329c7f2059e')5-access("Y"。"KH_ID"=:B1)統計信息——————————————————————————————————————0recursivecalls0dbblockgets804560consistentgets71127physicalreads0redosize516bytessentviaSQL*Nettoclient469bytesreceivedviaSQL*Netfromclient2SQL*Netroundtripsto/fromclient0sorts(memory)0sorts(disk)1rowsprocessed

  用UNION代替OR對其進行優化后的代碼如下:

  SQL>selectcount(*)2from(select*3fromswgl_ddjbxxt4wheret。lrr_dm='e90e3fe4237c4af988477329c7f2059e'5andt。fzgs_dm='001085'6andt。xjbz='9999'7andt。FROMNBGL1='0'8union9select*10fromswgl_ddjbxxt11wheret。kpr_dm='e90e3fe4237c4af988477329c7f2059e'12andt。fzgs_dm='001085'13andt。xjbz='9999'14andt。FROMNBGL1='0'15union16select*17fromswgl_ddjbxxt18whereexists19(selecty。kh_id20fromkhgl_khywdlxxy21wherey。kh_id=t。kh_id22andy。sskhjl_dm='e90e3fe4237c4af988477329c7f2059e')23andt。fzgs_dm='001085'24andt。xjbz='9999'25andt。FROMNBGL1='0');COUNT(*)————————60已用時間:00:00:06。89執行計劃——————————————————————————————————————Planhashvalue:3846872744————————————————————————————-----------------------------------------------------------------------------|Id|Operation|Name|Rows|Bytes|TempSpc|Cost(%CPU)|Time|-----------------------------------------------------------------------------------------------------------------------|0|SELECTSTATEMENT||1|||52263(1)|00:10:28||1|SORTAGGREGATE||1||||||2|VIEW||5996|||52263(1)|00:10:28||3|SORTUNIQUE||5996|2238K|6344K|52263(47)|00:10:28||4|UNION-ALL||||||||*5|TABLEACCESSFULL|SWGL_DDJBXX|59|19234||28037(1)|00:05:37||*6|TABLEACCESSBYINDEXROWID|SWGL_DDJBXX|10|3260||1209(1)|00:00:15||*7|INDEXRANGESCAN|IDX_SWGL_DDJBXX_KPRDM|4748|||34(0)|00:00:01||*8|TABLEACCESSBYINDEXROWID|SWGL_DDJBXX|1|326||5(0)|00:00:01||9|NESTEDLOOPS||5927|2216K||22527(1)|00:04:31||10|SORTUNIQUE||10165|565K||1916(1)|00:00:23||11|TABLEACCESSBYINDEXROWID|KHGL_KHYWDLXX|10165|565K||1916(1)|00:00:23||*12|INDEXRANGESCAN|IDX_KHGL_KHYWDLXX_SSKHJL|10165|||111(0)|00:00:02||*13|INDEXRANGESCAN|IDX_SWGL_DDJBXX_KHID|2|||2(0)|00:00:01|-----------------------------------------------------------------------------------------------------------------------PredicateInformation(identifiedbyoperationid):---------------------------------------------------5-filter("T"。"LRR_DM"='e90e3fe4237c4af988477329c7f2059e'AND"T"。"FROMNBGL1"='0'AND"T"。"XJBZ"='9999'AND"T"。"FZGS_DM"='001085')6-filter("T"。"FROMNBGL1"='0'AND"T"。"XJBZ"='9999'AND"T"。"FZGS_DM"='001085')7-access("T"。"KPR_DM"='e90e3fe4237c4af988477329c7f2059e')8-filter("T"。"FROMNBGL1"='0'AND"T"。"XJBZ"='9999'AND"T"。"FZGS_DM"='001085')12-access("Y"。"SSKHJL_DM"='e90e3fe4237c4af988477329c7f2059e')13-access("Y"。"KH_ID"="T"。"KH_ID")統計信息----------------------------------------------------------1recursivecalls0dbblockgets128422consistentgets10308physicalreads0redosize512bytessentviaSQL*Nettoclient469bytesreceivedviaSQL*Netfromclient2SQL*Netroundtripsto/fromclient2sorts(memory)0sorts(disk)1rowsprocessed

  SQL改寫之后,執行時間由原來的20秒下降到6秒,邏輯讀由804560降低到128422,性能還是有很大提升的,到了這里優化還沒完,可以創建一個組合索引進一步優化。

  createindexidxonswgl_ddjbxx(fzgs_dm,xjbz,FROMNBGL1);

  SQLServer怎么使用UNION代替OR提升查詢性能

  創建索引之后,原始的SQL執行時間,執行計劃,統計信息如下:

  SQL>selectcount(*)rowcount_lhy2fromswgl_ddjbxxt3wheret。fzgs_dm='001085'4and(t。lrr_dm='e90e3fe4237c4af988477329c7f2059e'orexists5(selecty。kh_id6fromkhgl_khywdlxxy7wherey。kh_id=t。kh_id8andy。sskhjl_dm='e90e3fe4237c4af988477329c7f2059e')or9t。kpr_dm='e90e3fe4237c4af988477329c7f2059e')10andt。xjbz='9999'11andt。FROMNBGL1='0';ROWCOUNT_LHY------------60已用時間:00:00:02。96執行計劃----------------------------------------------------------Planhashvalue:3049366449--------------------------------------------------------------------------------------------------------|Id|Operation|Name|Rows|Bytes|Cost(%CPU)|Time|--------------------------------------------------------------------------------------------------------|0|SELECTSTATEMENT||1|86|506(0)|00:00:07||1|SORTAGGREGATE||1|86||||*2|FILTER|||||||3|TABLEACCESSBYINDEXROWID|SWGL_DDJBXX|5926|497K|506(0)|00:00:07||*4|INDEXRANGESCAN|IDX|2370||12(0)|00:00:01||*5|TABLEACCESSBYINDEXROWID|KHGL_KHYWDLXX|1|57|5(0)|00:00:01||*6|INDEXRANGESCAN|IDX_KHGL_KHYWDLXX_KHID|1||3(0)|00:00:01|--------------------------------------------------------------------------------------------------------PredicateInformation(identifiedbyoperationid):---------------------------------------------------2-filter("T"。"LRR_DM"='e90e3fe4237c4af988477329c7f2059e'OR"T"。"KPR_DM"='e90e3fe4237c4af988477329c7f2059e'OREXISTS(SELECT0FROM"KHGL_KHYWDLXX""Y"WHERE"Y"。"KH_ID"=:B1AND"Y"。"SSKHJL_DM"='e90e3fe4237c4af988477329c7f2059e'))4-access("T"。"FZGS_DM"='001085'AND"T"。"XJBZ"='9999'AND"T"。"FROMNBGL1"='0')5-filter("Y"。"SSKHJL_DM"='e90e3fe4237c4af988477329c7f2059e')6-access("Y"。"KH_ID"=:B1)統計信息----------------------------------------------------------1recursivecalls0dbblockgets702767consistentgets0physicalreads0redosize516bytessentviaSQL*Nettoclient469bytesreceivedviaSQL*Netfromclient2SQL*Netroundtripsto/fromclient0sorts(memory)0sorts(disk)1rowsprocessed

  改寫的SQL:

  SQL>selectcount(*)2from(select*3fromswgl_ddjbxxt4wheret。lrr_dm='e90e3fe4237c4af988477329c7f2059e'5andt。fzgs_dm='001085'6andt。xjbz='9999'7andt。FROMNBGL1='0'8union9select*10fromswgl_ddjbxxt11wheret。kpr_dm='e90e3fe4237c4af988477329c7f2059e'12andt。fzgs_dm='001085'13andt。xjbz='9999'14andt。FROMNBGL1='0'15union16select*17fromswgl_ddjbxxt18whereexists19(selecty。kh_id20fromkhgl_khywdlxxy21wherey。kh_id=t。kh_id22andy。sskhjl_dm='e90e3fe4237c4af988477329c7f2059e')23andt。fzgs_dm='001085'24andt。xjbz='9999'25andt。FROMNBGL1='0');COUNT(*)----------60已用時間:00:00:00。53執行計劃----------------------------------------------------------Planhashvalue:2947849958-------------------------------------------------------------------------------------------------------------------------|Id|Operation|Name|Rows|Bytes|TempSpc|Cost(%CPU)|Time|-------------------------------------------------------------------------------------------------------------------------|0|SELECTSTATEMENT||1|||3469(1)|00:00:42||1|SORTAGGREGATE||1||||||2|VIEW||5995|||3469(1)|00:00:42||3|SORTUNIQUE||5995|2238K|4760K|3469(86)|00:00:42||4|UNION-ALL||||||||*5|TABLEACCESSBYINDEXROWID|SWGL_DDJBXX|59|19234||506(0)|00:00:07||*6|INDEXRANGESCAN|IDX|2370|||12(0)|00:00:01||7|TABLEACCESSBYINDEXROWID|SWGL_DDJBXX|10|3260||50(0)|00:00:01||8|BITMAPCONVERSIONTOROWIDS||||||||9|BITMAPAND||||||||10|BITMAPCONVERSIONFROMROWIDS||||||||*11|INDEXRANGESCAN|IDX|2370|||12(0)|00:00:01||12|BITMAPCONVERSIONFROMROWIDS||||||||*13|INDEXRANGESCAN|IDX_SWGL_DDJBXX_KPRDM|2370|||34(0)|00:00:01||*14|HASHJOINRIGHTSEMI||5926|2216K||2423(1)|00:00:30||15|TABLEACCESSBYINDEXROWID|KHGL_KHYWDLXX|10165|565K||1916(1)|00:00:23||*16|INDEXRANGESCAN|IDX_KHGL_KHYWDLXX_SSKHJL|10165|||111(0)|00:00:02||17|TABLEACCESSBYINDEXROWID|SWGL_DDJBXX|5926|1886K||506(0)|00:00:07||*18|INDEXRANGESCAN|IDX|2370|||12(0)|00:00:01|-------------------------------------------------------------------------------------------------------------------------PredicateInformation(identifiedbyoperationid):---------------------------------------------------5-filter("T"。"LRR_DM"='e90e3fe4237c4af988477329c7f2059e')6-access("T"。"FZGS_DM"='001085'AND"T"。"XJBZ"='9999'AND"T"。"FROMNBGL1"='0')11-access("T"。"FZGS_DM"='001085'AND"T"。"XJBZ"='9999'AND"T"。"FROMNBGL1"='0')filter("T"。"FROMNBGL1"='0'AND"T"。"XJBZ"='9999'AND"T"。"FZGS_DM"='001085')13-access("T"。"KPR_DM"='e90e3fe4237c4af988477329c7f2059e')14-access("Y"。"KH_ID"="T"。"KH_ID")16-access("Y"。"SSKHJL_DM"='e90e3fe4237c4af988477329c7f2059e')18-access("T"。"FZGS_DM"='001085'AND"T"。"XJBZ"='9999'AND"T"."FROMNBGL1"='0')統計信息---------------------------------------------------------1recursivecalls0dbblockgets25628consistentgets0physicalreads0redosize512bytessentviaSQL*Nettoclient469bytesreceivedviaSQL*Netfromclient2SQL*Netroundtripsto/fromclient1sorts(memory)0sorts(disk)1rowsprocessed。

以上是“SQLServer如何使用UNION代替OR提升查詢性能”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

富锦市| 柳河县| 德庆县| 伊金霍洛旗| 咸丰县| 商河县| 万山特区| 鹤山市| 万州区| 洛宁县| 常熟市| 新宾| 隆回县| 吉林市| 贵州省| 永泰县| 禄劝| 蕲春县| 连南| 内黄县| 宝兴县| 阿克苏市| 肇州县| 大姚县| 诸暨市| 砀山县| 龙江县| 平顺县| 五大连池市| 汶川县| 福贡县| 兴山县| 中牟县| 新巴尔虎右旗| 德庆县| 荣成市| 杭锦后旗| 平度市| 富锦市| 万全县| 随州市|