update from statement in SQL Server 2008 execution efficiency -
i have such functions in sql server 2008, execution time long.
create table [dbo].[t_sourcepayin]( [sourcepayinid] [int] identity(1,1) not null, [checkperiod] [varchar](6) not null, [kddeptid] [varchar](20) not null, [zxdeptid] [varchar](20) not null, [amount] [decimal](18, 6) not null, [processdate] [smalldatetime] null, [operatorid] [varchar](20) not null, [manual] [bit] null, [disabled] [bit] not null, [chargetypeid] [varchar](20) not null, [nono] [varchar](20) null, [remarks] [varchar](50) null, [kddeptcode] [varchar](32) null, [zxdeptcode] [varchar](32) null, [hldeptcode] [varchar](10) null, [cwclass] [varchar](20) null, [outin] [varchar](6) null, [chargeitem] [varchar](20) null, [kdhsdeptid] [varchar](10) null, [zxhsdeptid] [varchar](10) null, [kdratio] [decimal](8, 6) null, [zxratio] [decimal](8, 6) null, [kdjjratio] [decimal](8, 6) null, [zxjjratio] [decimal](8, 6) null, [ekdratio] [decimal](18, 6) null, [ezxratio] [decimal](18, 6) null, [freemark] [varchar](50) null, [freetype] [varchar](20) null, [jmratio] [decimal](18, 6) null, [dfratio] [decimal](18, 6) null, [mzratio] [decimal](18, 6) null, [zyratio] [decimal](18, 6) null, [ejmratio] [decimal](18, 6) null, [edfratio] [decimal](18, 6) null, [emzratio] [decimal](18, 6) null, [ezyratio] [decimal](18, 6) null, [kddoctor] [varchar](20) null, [kddoctorno] [varchar](20) null, [qtjjratio] [decimal](18, 6) null, [hljjratio] [decimal](18, 6) null, [hldeptid] [varchar](10) null, [hlhsdeptid] [varchar](10) null, [qtdeptid] [varchar](10) null, [qthsdeptid] [varchar](10) null, [qtratio] [decimal](18, 6) null, [eqtratio] [decimal](18, 6) null, [hlratio] [decimal](18, 6) null, [ehlratio] [decimal](18, 6) null, [quantity] [decimal](12, 2) null, [patientid] [varchar](20) null, [patientname] [varchar](20) null, [kdysdeptid] [varchar](10) null, [zxysdeptid] [varchar](10) null, [yjdeptid] [varchar](10) null, [hldydeptid] [varchar](10) null, [ysratio] [decimal](18, 6) null, [kdysratio] [decimal](18, 6) null, [zxysratio] [decimal](18, 6) null, [yjratio] [decimal](18, 6) null, [hldyratio] [decimal](18, 6) null, [lc] [decimal](18, 4) null, [chargeitemname] [varchar](64) null, [ysdeptid] [varchar](10) null, [epayinruleid] [varchar](30) null, [payinruleid] [varchar](30) null, [jjpayinruleid] [varchar](30) null, constraint [pk_t_sourcepayin] primary key clustered ( [checkperiod] asc, [sourcepayinid] asc )with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary] ) on [primary] /****** object: index [ix_t_sourcepayin] script date: 05/21/2013 09:27:41 ******/ create nonclustered index [ix_t_sourcepayin] on [dbo].[t_sourcepayin] ( [checkperiod] asc, [chargeitem] asc )with (pad_index = off, statistics_norecompute = off, sort_in_tempdb = off, ignore_dup_key = off, drop_existing = off, online = off, allow_row_locks = on, allow_page_locks = on) on [primary] go
table t_sourcepayin have 100k rows per month. map table named t_mapinter follows 100 rows:
create table [dbo].[t_mapinter]( [type] [varchar](20) null, [inid] [varchar](32) null, [inname] [varchar](64) null, [outid] [varchar](32) null, [outname] [varchar](64) null, [ratio] [decimal](18, 2) null, [remarks] [varchar](128) null, [id] [int] identity(1,1) not null, [lastusedtime] [datetime] null, [lastusedinter] [varchar](32) null ) on [primary]
in project, use t_sourcepayint
month data, , insert it, update t_mapinter 20 times,as follows:
truncate table t_sourcepayint --delete index --31s or 60s insert t_sourcepayint select * t_sourcepayin checkperiod = '201305' -- create index t_sourcepayint /****** object: index [idx_unc_oi_i_sid_cid] script date: 03/17/2013 10:03:25 ******/ create nonclustered index [idx_unc_oi_i_sid_cid] on [dbo].[t_sourcepayint] ( [outin] asc ) include ( [sourcepayinid], [chargeitem]) (pad_index = off, statistics_norecompute = off, sort_in_tempdb = off, ignore_dup_key = off, drop_existing = off, online = off, allow_row_locks = on, allow_page_locks = on) on [primary] /****** object: index [ix_t_sourcepayint] script date: 03/17/2013 10:03:26 ******/ create nonclustered index [ix_t_sourcepayint] on [dbo].[t_sourcepayint] ( [chargeitem] asc )with (pad_index = off, statistics_norecompute = off, sort_in_tempdb = off, ignore_dup_key = off, drop_existing = off, online = off, allow_row_locks = on, allow_page_locks = on) on [primary] /****** object: index [ix_t_sourcepayint_kdhsdeptid] script date: 03/17/2013 10:03:26 ******/ create nonclustered index [ix_t_sourcepayint_kdhsdeptid] on [dbo].[t_sourcepayint] ( [kdhsdeptid] asc )with (pad_index = off, statistics_norecompute = off, sort_in_tempdb = off, ignore_dup_key = off, drop_existing = off, online = off, allow_row_locks = on, allow_page_locks = on) on [primary] /****** object: index [ix_t_sourcepayint_zxhsdeptid] script date: 03/17/2013 10:03:26 ******/ create nonclustered index [ix_t_sourcepayint_zxhsdeptid] on [dbo].[t_sourcepayint] ( [zxhsdeptid] asc )with (pad_index = off, statistics_norecompute = off, sort_in_tempdb = off, ignore_dup_key = off, drop_existing = off, online = off, allow_row_locks = on, allow_page_locks = on) on [primary] --update follows update set kdhsdeptid = b.inid t_sourcepayint a, (select * t_mapinter ) b a.kddeptid = b.outid update set zxhsdeptid = b.inid t_sourcepayint a, (select * t_mapinter ) b a.zxdeptid = b.outid -- t_chargeitem have 10k rows update set kdratio = b.ratio t_sourcepayint a, (select chargeitem,ratio t_chargeitem ) b a.kddeptid = 'd000034' , a.chargeitem = b.chargeitem update set kdratio = b.ratio t_sourcepayint a, (select chargeitem,ratio t_chargeitem ) b a.kddeptid in ('d000038','d000056') , a.chargeitem = b.chargeitem ...... -- update t_sourcepayin 120s update set kdratio = b.kdratio,zxratio = b.zxratio, kdjjratio = b.kdjjratio, ... t_sourcepayin a, t_sourcepayint b a.checkperiod = '201305' , a.sourcepayinid = b.sourcepayinid
the execut time
sum 5 minutes.
how can improve execution efficiency? change execute seq or create more efficient index table t_sourcepayint or t_sourcepayin.
update insert
may way?
Comments
Post a Comment