醫(yī)院數(shù)據(jù)庫系統(tǒng)SQL語句優(yōu)化分析
在醫(yī)院執(zhí)行模塊的數(shù)據(jù)窗口SQL:
SELECT DISTINCT
ZY_BQYZ.ZYH,ZY_BRRY.BRCH,ZY_BRRY.ZYHM,ZY_BRRY.BRXM,ZY_BRRY.BRXZ
FROM ZY_BQYZ, ZY_BRRY
WHERE ( ZY_BQYZ.ZYH = ZY_BRRY.ZYH )
AND ( ZY_BRRY.CYPB = 0 )
AND ( ZY_BQYZ.SRKS = :al_hsql )
AND ( ZY_BQYZ.SYBZ = 0 )
AND ( ZY_BQYZ.LSBZ = 0 OR ZY_BQYZ.LSBZ = 2 )
AND ( ZY_BQYZ.QRSJ < :ad_today OR ( ZY_BQYZ.QRSJ IS NULL ) )
AND ( ZY_BQYZ.JFBZ = 2 OR ZY_BQYZ.JFBZ = 9 )
AND ( ZY_BQYZ.XMLX > 3 )
AND ( ZY_BQYZ.YZPB = 0 )
ORDER BY ZY_BRRY.BRCH
4小結(jié)
從以上這些例子可以看出,SQL優(yōu)化的實質(zhì)就是在結(jié)果正確的前提下,用優(yōu)化器可以識別的語句,充份利用索引,減少表掃描的1/O 次數(shù),盡量避免表搜索的發(fā)生。其實SQL的性能優(yōu)化是一個復雜的過程,上述這些只是在SQL語句應用時的一種具體實例和平時應用中的總結(jié)??傊瑪?shù)據(jù)庫的性能優(yōu)化是一個系統(tǒng)工程,涉及的方面很多。數(shù)據(jù)庫管理員需要綜合運用多種方法,認真分析數(shù)據(jù)庫運行過程中出現(xiàn)的各種問題,才能保證數(shù)據(jù)庫高效地運行。
評論