Oracle SQL tuning 數(shù)據(jù)庫優(yōu)化步驟圖文教程
SQL Turning 是Quest公司出品的Quest Central軟件中的一個(gè)工具。Quest Central是一款集成化、圖形化、跨平臺的數(shù)據(jù)庫管理解決方案,可以同時(shí)管理 Oracle、DB2 和 SQL server 數(shù)據(jù)庫。
一、SQL Tuning for SQL Server簡介
SQL語句的優(yōu)化對發(fā)揮數(shù)據(jù)庫的最佳性能非常關(guān)鍵。然而不幸的是,應(yīng)用優(yōu)化通常由于時(shí)間和資源的因素而被忽略。SQL Tuning (SQL優(yōu)化)模塊可以對比和評測特定應(yīng)用中SQL語句的運(yùn)行性能,提出智能化的優(yōu)化建議,幫助用戶改善應(yīng)用的響應(yīng)時(shí)間。SQL優(yōu)化模塊具有非介入式SQL采集、自動優(yōu)化和專家建議等功能,全面改善SQL優(yōu)化工作。
二、SQL Tuning for SQL Server的使用
1、打開Quest Database Management Solutions彈出窗口如圖1所示
圖1
2、在紅色標(biāo)記處打開SQL Tuning 優(yōu)化SQL
(1)建立連接。
在Quest Central主界面上的“Database”樹上選擇“SQL Server”,然后在下方出現(xiàn)的“Tools”框中選擇“SQL Tuning”選項(xiàng),打開“Lanch SQL Tuning for SQL Server Connections”對話框(圖2、圖3)。我們在這里建立數(shù)據(jù)庫服務(wù)器的連接,以后的分析工作都會在它上面完成。
圖2 “建立連接”對話框
圖3
雙擊“New Connection”圖標(biāo),在彈出窗口中輸入數(shù)據(jù)庫的信息,單擊“OK”,然后單擊“Connect”即可。
(2)分析原始SQL語句 ,在單擊“Connect”后將彈出一個(gè)新窗口,如圖4
圖4
在打開窗口的“Oriangal SQL”文本框內(nèi)輸入需要分析的原始SQL語句,紅色標(biāo)記處選擇對應(yīng)的數(shù)據(jù)庫名,SQL語句代碼如下:
圖5 分析原始SQL語句
原始SQL語句
然后點(diǎn)擊工具欄上的“Execute”按鈕,執(zhí)行原始的SQL語句,SQL Tuning會自動分析SQL的執(zhí)行計(jì)劃,并把分析結(jié)果顯示到界面上(圖5)。
(3)優(yōu)化SQL。
現(xiàn)在我們點(diǎn)擊工具欄上的“Optimize Statement”按鈕,讓SQL Tuning開始優(yōu)化SQL,完成后,可以看到SQL Tuning產(chǎn)生了19條與原始SQL等價(jià)的優(yōu)化方案(圖6)。
圖6 SQL優(yōu)化方案
(4)獲得最優(yōu)SQL。
接下來,我們來執(zhí)行上面產(chǎn)生的優(yōu)化方案,以選出性能最佳的等效SQL語句。在列表中選擇需要執(zhí)行的優(yōu)化方案(默認(rèn)已全部選中),然后點(diǎn)擊工具欄上的“Execute”按鈕旁邊的下拉菜單,選擇“Execute Selected”。等到所有SQL運(yùn)行完成后,點(diǎn)擊界面左方的“Tuning Resolution”按鈕,
可以看到最優(yōu)的SQL已經(jīng)出來啦,運(yùn)行時(shí)間竟然可以提高21%!(圖7)
圖7 “Tuning Resolution”界面
最優(yōu)的SQL語句如下:
5)學(xué)習(xí)書寫專家級的SQL語句 。
優(yōu)化后的SQL語句
SELECT dbo.Person_BasicInfo.*,
dbo.Graduater_GraduaterRegist.RegistNO AS RegistNO,
dbo.Graduater_GraduaterRegist.RegistTime AS BaoDaoTime,
dbo.Graduater_GraduaterRegist.RegistMan AS RegistMan,
dbo.Graduater_Business.ComeFrom AS ComeFrom,
dbo.Graduater_Business.Code AS Code,
dbo.Graduater_Business.Status AS Status,
dbo.Graduater_Business.ApproveResult AS ApproveResult,
dbo.Graduater_Business.NewCorp AS NewCorp,
dbo.Graduater_Business.CommendNumber AS CommendNumber,
dbo.Graduater_Business.EmployStatus AS EmployStatus,
dbo.Graduater_Business.NewCommendTime AS NewCommendTime,
dbo.Graduater_Business.GetSource AS GetSource,
dbo.Graduater_Business.EmployTime AS EmployTime,
dbo.Graduater_Business.Job AS Job,
dbo.Graduater_Business.FillMan AS FillMan,
dbo.Graduater_Business.FillTime AS FillTime,
dbo.Graduater_Business.IsCommendOK AS IsCommendOK,
dbo.Graduater_Business.ApproveUser AS ApproveUser,
dbo.Graduater_Business.ApproveTime AS ApproveTime,
dbo.Graduater_Business.RegistTime AS RegistTime,
dbo.Graduater_Business.EmployCorp AS EmployCorp,
dbo.Graduater_Business.JobRemark AS JobRemark,
CASE WHEN dbo.Graduater_Business.ComeFrom = 'WS' THEN '網(wǎng)上登記'
WHEN dbo.Graduater_Business.ComeFrom = 'HP' THEN '華普大廈'
WHEN dbo.Graduater_Business.ComeFrom = 'JD' THEN '精典大廈'
WHEN dbo.Graduater_Business.ComeFrom = 'MC' THEN '賽馬場'
WHEN ComeFrom = 'ZX' THEN '高指中心' END AS ComeFromName,
dbo.Person_Contact.Address AS Address,
dbo.Person_Contact.Zip AS Zip,
dbo.Person_Contact.Telephone AS Telephone,
dbo.Person_Contact.Mobile AS Mobile,
dbo.Person_Contact.Email AS Email,
dbo.Person_Contact.IM AS IM,
dbo.Person_Skill.ForeignLanguage AS ForeignLanguage,
dbo.Person_Skill.ForeignLanguageLevel&nbs
關(guān)鍵詞:Oracle,SQL,數(shù)據(jù)庫
閱讀本文后您有什么感想? 已有 人給出評價(jià)!
- 0
- 0
- 0
- 0
- 0
- 0