Sql server 相同的视图,非常不同的执行时间(Was:Oracle链接服务器速度较慢,但仅为第二次)
我有一组ETL作业,它们将数据从MS SQL数据库加载到Oracle。作业和参数在表中定义,并且有一个包装程序逐个执行它们 我的问题是,当包装器执行第一个作业时,它很快,在大约45-50秒内将数据插入Oracle。当它到达第二个时(与第一个不同之处在于从源头获取不同的汇率),需要20-22分钟 完全相同的行数(大约24000行)、相同的数据量、相同的源表和目标表,唯一的区别在于源查询的where子句 我已经实现了一个相当广泛的日志记录,它表明从源数据库加载、转换和旋转数据具有稳定的性能,总是花费大致相同的时间。这只是最后一步,第一次推动甲骨文快速发展,其余时间缓慢发展 使用的提供程序:OraOLEDB.Oracle 插入使用的语句:Sql server 相同的视图,非常不同的执行时间(Was:Oracle链接服务器速度较慢,但仅为第二次),sql-server,oracle,linked-server,Sql Server,Oracle,Linked Server,我有一组ETL作业,它们将数据从MS SQL数据库加载到Oracle。作业和参数在表中定义,并且有一个包装程序逐个执行它们 我的问题是,当包装器执行第一个作业时,它很快,在大约45-50秒内将数据插入Oracle。当它到达第二个时(与第一个不同之处在于从源头获取不同的汇率),需要20-22分钟 完全相同的行数(大约24000行)、相同的数据量、相同的源表和目标表,唯一的区别在于源查询的where子句 我已经实现了一个相当广泛的日志记录,它表明从源数据库加载、转换和旋转数据具有稳定的性能,总是花费
insert into LINKEDORACLESERVER..SCHEMANAME.TABLENAME select * from spec.staging_tablename
你知道要检查什么吗
更新:
从用户ammoQ的评论中得到了一个想法。问题是,如果我把两个工作颠倒过来,那么第一个工作就变成了令人痛苦的慢工作,第二个工作就快了。也许现在整个问题都错了
但是,如果这两个作业的参数不同,特别是它们应该从SAP BPC的OLAP多维数据集中获取的汇率类别不同,这怎么可能发生呢?它们从同一个源读取数据,写入同一个目标表,这两个表都有大约24k行,但都是“速率B”,而不是“速率A”
更新2:
越来越近了。因此,这两个作业都将数据推送到一个表中,该表是Xcelsius仪表板的数据集市。它有一个非常特殊的结构,我在MSSQL中为此构建了一个视图。因此,将数据从同一个视图加载到同一个表中
View in job 1: returns 23,512 rows. Execution time: 00:01:03.
View in job 2: returns 23,512 rows. Execution time: 00:18:54.
这是视图的选择:
select base.organisation, calc.mm_account, base.analysis,
case base.kpiref when -1 then calc.source_of_value else sv1.value end source_of_value,
base.account, base.[year], 'ACTUAL' category,
[currency] currency_code, ltrim(rtrim(right(jobs.name, len(jobs.name) - patindex('%@%', jobs.name)))) forex_rate_type, base.[month],
isnull(Y_0.v01, 0) v01,
case base.[month] when 1 then 0 else isnull(Y_0.v02, 0) end v02,
case base.[month] when 2 then 0 else isnull(Y_0.v03, 0) end v03,
case base.[month] when 3 then 0 else isnull(Y_0.v04, 0) end v04,
case base.[month] when 4 then 0 else isnull(Y_0.v05, 0) end v05,
case base.[month] when 5 then 0 else isnull(Y_0.v06, 0) end v06,
case base.[month] when 6 then 0 else isnull(Y_0.v07, 0) end v07,
case base.[month] when 7 then 0 else isnull(Y_0.v08, 0) end v08,
case base.[month] when 8 then 0 else isnull(Y_0.v09, 0) end v09,
case base.[month] when 9 then 0 else isnull(Y_0.v10, 0) end v10,
case base.[month] when 10 then 0 else isnull(Y_0.v11, 0) end v11,
case base.[month] when 11 then 0 else isnull(Y_0.v12, 0) end v12,
isnull(Y_0.CMO, 0) CMO, (0) forecast_accuracy, isnull(Y_0.YTD, 0) YTD, (0) QTD, isnull(Y_0.FYR, 0) FYR,
(isnull(Ym1.v01, 0) + isnull(Ym1.v02, 0) + isnull(Ym1.v03, 0) + isnull(Ym1.v04, 0) + isnull(Ym1.v05, 0) + isnull(Ym1.v06, 0) + isnull(Ym1.v07, 0) + isnull(Ym1.v08, 0) + isnull(Ym1.v09, 0) + isnull(Ym1.v10, 0) + isnull(Ym1.v11, 0) + isnull(Ym1.v12, 0)) FYR_1,
(isnull(Ym2.v01, 0) + isnull(Ym2.v02, 0) + isnull(Ym2.v03, 0) + isnull(Ym2.v04, 0) + isnull(Ym2.v05, 0) + isnull(Ym2.v06, 0) + isnull(Ym2.v07, 0) + isnull(Ym2.v08, 0) + isnull(Ym2.v09, 0) + isnull(Ym2.v10, 0) + isnull(Ym2.v11, 0) + isnull(Ym2.v12, 0)) FYR_2,
0 FYR_NY, -- we don't need to calculate this one for actuals as there are no actuals for next year yet! this is why it's a hard-coded zero
(isnull(Ym2.v01,0)+isnull(Ym2.v02,0)+isnull(Ym2.v03,0)) q01, (isnull(Ym2.v04,0)+isnull(Ym2.v05,0)+isnull(Ym2.v06,0)) q02, (isnull(Ym2.v07,0)+isnull(Ym2.v08,0)+isnull(Ym2.v09,0)) q03, (isnull(Ym2.v10,0)+isnull(Ym2.v11,0)+isnull(Ym2.v12,0)) q04,
(isnull(Ym1.v01,0)+isnull(Ym1.v02,0)+isnull(Ym1.v03,0)) q05, (isnull(Ym1.v04,0)+isnull(Ym1.v05,0)+isnull(Ym1.v06,0)) q06, (isnull(Ym1.v07,0)+isnull(Ym1.v08,0)+isnull(Ym1.v09,0)) q07, (isnull(Ym1.v10,0)+isnull(Ym1.v11,0)+isnull(Ym1.v12,0)) q08,
( isnull(Y_0.v01,0) + case base.[month] when 1 then 0 else isnull(Y_0.v02,0) end + case base.[month] when 2 then 0 else isnull(Y_0.v03,0) end) q09,
(case base.[month] when 3 then 0 else isnull(Y_0.v04,0) end + case base.[month] when 4 then 0 else isnull(Y_0.v05,0) end + case base.[month] when 5 then 0 else isnull(Y_0.v06,0) end) q10,
(case base.[month] when 6 then 0 else isnull(Y_0.v07,0) end + case base.[month] when 7 then 0 else isnull(Y_0.v08,0) end + case base.[month] when 8 then 0 else isnull(Y_0.v09,0) end) q11,
(case base.[month] when 9 then 0 else isnull(Y_0.v10,0) end + case base.[month] when 10 then 0 else isnull(Y_0.v11,0) end + case base.[month] when 11 then 0 else isnull(Y_0.v12,0) end) q12,
dbo.dateOnly(getdate()) date_uploaded, 'strata' data_source
from
(select organisation, account, analysis, [year], kpiref, min([month]) [month], min(jobID) jobID from staging_phase_4
where category in ('ACTUAL', 'ACTUAL-1', 'ACTUAL-2')
and jobID in (select id from dbo.jobs where (name in ('strata @ Actual Average', 'strata @ Plan')))
group by organisation, account, analysis, [year], kpiref) base
left outer join staging_phase_4 Y_0 on Y_0.organisation = base.organisation and Y_0.account = base.account and Y_0.analysis = base.analysis and Y_0.kpiref = base.kpiref and Y_0.category = 'ACTUAL'
left outer join staging_phase_4 Ym1 on Ym1.organisation = base.organisation and Ym1.account = base.account and Ym1.analysis = base.analysis and Ym1.kpiref = base.kpiref and Ym1.category = 'ACTUAL-1'
left outer join staging_phase_4 Ym2 on Ym2.organisation = base.organisation and Ym2.account = base.account and Ym2.analysis = base.analysis and Ym2.kpiref = base.kpiref and Ym2.category = 'ACTUAL-2'
left outer join jobs_calculations_setvalues sv1 on base.kpiref = sv1.calcid
inner join jobs on base.jobID = jobs.id
cross apply spec.calculated_strategic_accounts(base.account) calc
union
-- *** LAST YEAR ***
select base.organisation, calc.mm_account, base.analysis,
case base.kpiref when -1 then calc.source_of_value else sv1.value end source_of_value,
base.account, base.[year], 'LAST YEAR' category,
[currency] currency_code, ltrim(rtrim(right(jobs.name, len(jobs.name) - patindex('%@%', jobs.name)))) forex_rate_type, base.[month],
isnull(Y_0.v01, 0) v01, isnull(Y_0.v02, 0) v02, isnull(Y_0.v03, 0) v03, isnull(Y_0.v04, 0) v04, isnull(Y_0.v05, 0) v05, isnull(Y_0.v06, 0) v06,
isnull(Y_0.v07, 0) v07, isnull(Y_0.v08, 0) v08, isnull(Y_0.v09, 0) v09, isnull(Y_0.v10, 0) v10, isnull(Y_0.v11, 0) v11, isnull(Y_0.v12, 0) v12,
isnull(Y_0.CMO, 0) CMO, (0) forecast_accuracy, isnull(Y_0.YTD, 0) YTD, (0) QTD, isnull(Y_0.FYR, 0) FYR,
(isnull(Ym1.v01, 0) + isnull(Ym1.v02, 0) + isnull(Ym1.v03, 0) + isnull(Ym1.v04, 0) + isnull(Ym1.v05, 0) + isnull(Ym1.v06, 0) + isnull(Ym1.v07, 0) + isnull(Ym1.v08, 0) + isnull(Ym1.v09, 0) + isnull(Ym1.v10, 0) + isnull(Ym1.v11, 0) + isnull(Ym1.v12, 0)) FYR_1,
(isnull(Ym2.v01, 0) + isnull(Ym2.v02, 0) + isnull(Ym2.v03, 0) + isnull(Ym2.v04, 0) + isnull(Ym2.v05, 0) + isnull(Ym2.v06, 0) + isnull(Ym2.v07, 0) + isnull(Ym2.v08, 0) + isnull(Ym2.v09, 0) + isnull(Ym2.v10, 0) + isnull(Ym2.v11, 0) + isnull(Ym2.v12, 0)) FYR_2,
(isnull(Yp1.v01, 0) + isnull(Yp1.v02, 0) + isnull(Yp1.v03, 0) + isnull(Yp1.v04, 0) + isnull(Yp1.v05, 0) + isnull(Yp1.v06, 0) + isnull(Yp1.v07, 0) + isnull(Yp1.v08, 0) + isnull(Yp1.v09, 0) + isnull(Yp1.v10, 0) + isnull(Yp1.v11, 0) + isnull(Yp1.v12, 0)) FYR_NY,
(isnull(Ym2.v01,0)+isnull(Ym2.v02,0)+isnull(Ym2.v03,0)) q01, (isnull(Ym2.v04,0)+isnull(Ym2.v05,0)+isnull(Ym2.v06,0)) q02, (isnull(Ym2.v07,0)+isnull(Ym2.v08,0)+isnull(Ym2.v09,0)) q03, (isnull(Ym2.v10,0)+isnull(Ym2.v11,0)+isnull(Ym2.v12,0)) q04,
(isnull(Ym1.v01,0)+isnull(Ym1.v02,0)+isnull(Ym1.v03,0)) q05, (isnull(Ym1.v04,0)+isnull(Ym1.v05,0)+isnull(Ym1.v06,0)) q06, (isnull(Ym1.v07,0)+isnull(Ym1.v08,0)+isnull(Ym1.v09,0)) q07, (isnull(Ym1.v10,0)+isnull(Ym1.v11,0)+isnull(Ym1.v12,0)) q08,
(isnull(Y_0.v01,0)+isnull(Y_0.v02,0)+isnull(Y_0.v03,0)) q09, (isnull(Y_0.v04,0)+isnull(Y_0.v05,0)+isnull(Y_0.v06,0)) q10, (isnull(Y_0.v07,0)+isnull(Y_0.v08,0)+isnull(Y_0.v09,0)) q11, (isnull(Y_0.v10,0)+isnull(Y_0.v11,0)+isnull(Y_0.v12,0)) q12,
dbo.dateOnly(getdate()) date_uploaded, 'strata' data_source
from
(select organisation, account, analysis, [year], kpiref, min([month]) [month], min(jobID) jobID from staging_phase_4
where category in ('LAST YEAR', 'ACTUAL-2', 'ACTUAL-3', 'ACTUAL')
and jobID in (select id from dbo.jobs where (name in ('strata @ Actual Average', 'strata @ Plan')))
group by organisation, account, analysis, [year], kpiref) base
left outer join staging_phase_4 Y_0 on Y_0.organisation = base.organisation and Y_0.account = base.account and Y_0.analysis = base.analysis and Y_0.kpiref = base.kpiref and Y_0.category = 'LAST YEAR'
left outer join staging_phase_4 Ym1 on Ym1.organisation = base.organisation and Ym1.account = base.account and Ym1.analysis = base.analysis and Ym1.kpiref = base.kpiref and Ym1.category = 'ACTUAL-2'
left outer join staging_phase_4 Ym2 on Ym2.organisation = base.organisation and Ym2.account = base.account and Ym2.analysis = base.analysis and Ym2.kpiref = base.kpiref and Ym2.category = 'ACTUAL-3'
left outer join staging_phase_4 Yp1 on Yp1.organisation = base.organisation and Yp1.account = base.account and Yp1.analysis = base.analysis and Yp1.kpiref = base.kpiref and Yp1.category = 'ACTUAL'
left outer join jobs_calculations_setvalues sv1 on base.kpiref = sv1.calcid
inner join jobs on base.jobID = jobs.id
cross apply spec.calculated_strategic_accounts(base.account) calc
union
-- *** PLAN ***
select base.organisation, calc.mm_account, base.analysis,
case base.kpiref when -1 then calc.source_of_value else sv1.value end source_of_value,
base.account, base.[year], 'PLAN' category,
[currency] currency_code, ltrim(rtrim(right(jobs.name, len(jobs.name) - patindex('%@%', jobs.name)))) forex_rate_type, base.[month],
isnull(Y_0.v01, 0) v01, isnull(Y_0.v02, 0) v02, isnull(Y_0.v03, 0) v03, isnull(Y_0.v04, 0) v04, isnull(Y_0.v05, 0) v05, isnull(Y_0.v06, 0) v06,
isnull(Y_0.v07, 0) v07, isnull(Y_0.v08, 0) v08, isnull(Y_0.v09, 0) v09, isnull(Y_0.v10, 0) v10, isnull(Y_0.v11, 0) v11, isnull(Y_0.v12, 0) v12,
isnull(Y_0.CMO, 0) CMO, (0) forecast_accuracy, isnull(Y_0.YTD, 0) YTD, (0) QTD, isnull(Y_0.FYR, 0) FYR,
(isnull(Am1.v01, 0) + isnull(Am1.v02, 0) + isnull(Am1.v03, 0) + isnull(Am1.v04, 0) + isnull(Am1.v05, 0) + isnull(Am1.v06, 0) + isnull(Am1.v07, 0) + isnull(Am1.v08, 0) + isnull(Am1.v09, 0) + isnull(Am1.v10, 0) + isnull(Am1.v11, 0) + isnull(Am1.v12, 0)) FYR_1,
(isnull(Am2.v01, 0) + isnull(Am2.v02, 0) + isnull(Am2.v03, 0) + isnull(Am2.v04, 0) + isnull(Am2.v05, 0) + isnull(Am2.v06, 0) + isnull(Am2.v07, 0) + isnull(Am2.v08, 0) + isnull(Am2.v09, 0) + isnull(Am2.v10, 0) + isnull(Am2.v11, 0) + isnull(Am2.v12, 0)) FYR_2,
(isnull(Yp1.v01, 0) + isnull(Yp1.v02, 0) + isnull(Yp1.v03, 0) + isnull(Yp1.v04, 0) + isnull(Yp1.v05, 0) + isnull(Yp1.v06, 0) + isnull(Yp1.v07, 0) + isnull(Yp1.v08, 0) + isnull(Yp1.v09, 0) + isnull(Yp1.v10, 0) + isnull(Yp1.v11, 0) + isnull(Yp1.v12, 0)) FYR_NY,
(isnull(Ym2.v01,0)+isnull(Ym2.v02,0)+isnull(Ym2.v03,0)) q01, (isnull(Ym2.v04,0)+isnull(Ym2.v05,0)+isnull(Ym2.v06,0)) q02, (isnull(Ym2.v07,0)+isnull(Ym2.v08,0)+isnull(Ym2.v09,0)) q03, (isnull(Ym2.v10,0)+isnull(Ym2.v11,0)+isnull(Ym2.v12,0)) q04,
(isnull(Ym1.v01,0)+isnull(Ym1.v02,0)+isnull(Ym1.v03,0)) q05, (isnull(Ym1.v04,0)+isnull(Ym1.v05,0)+isnull(Ym1.v06,0)) q06, (isnull(Ym1.v07,0)+isnull(Ym1.v08,0)+isnull(Ym1.v09,0)) q07, (isnull(Ym1.v10,0)+isnull(Ym1.v11,0)+isnull(Ym1.v12,0)) q08,
(isnull(Y_0.v01,0)+isnull(Y_0.v02,0)+isnull(Y_0.v03,0)) q09, (isnull(Y_0.v04,0)+isnull(Y_0.v05,0)+isnull(Y_0.v06,0)) q10, (isnull(Y_0.v07,0)+isnull(Y_0.v08,0)+isnull(Y_0.v09,0)) q11, (isnull(Y_0.v10,0)+isnull(Y_0.v11,0)+isnull(Y_0.v12,0)) q12,
dbo.dateOnly(getdate()) date_uploaded, 'strata' data_source
from
(select organisation, account, analysis, [year], kpiref, min([month]) [month], min(jobID) jobID from staging_phase_4
where category in ('PLAN', 'PLAN-1', 'PLAN-2', 'PLAN+1', 'ACTUAL-1', 'ACTUAL-2')
and jobID in (select id from dbo.jobs where (name in ('strata @ Actual Average', 'strata @ Plan')))
group by organisation, account, analysis, [year], kpiref) base
left outer join staging_phase_4 Y_0 on Y_0.organisation = base.organisation and Y_0.account = base.account and Y_0.analysis = base.analysis and Y_0.kpiref = base.kpiref and Y_0.category = 'PLAN'
left outer join staging_phase_4 Ym1 on Ym1.organisation = base.organisation and Ym1.account = base.account and Ym1.analysis = base.analysis and Ym1.kpiref = base.kpiref and Ym1.category = 'PLAN-1'
left outer join staging_phase_4 Ym2 on Ym2.organisation = base.organisation and Ym2.account = base.account and Ym2.analysis = base.analysis and Ym2.kpiref = base.kpiref and Ym2.category = 'PLAN-2'
left outer join staging_phase_4 Yp1 on Yp1.organisation = base.organisation and Yp1.account = base.account and Yp1.analysis = base.analysis and Yp1.kpiref = base.kpiref and Yp1.category = 'PLAN+1'
left outer join staging_phase_4 Am1 on Am1.organisation = base.organisation and Am1.account = base.account and Am1.analysis = base.analysis and Am1.kpiref = base.kpiref and Am1.category = 'ACTUAL-1'
left outer join staging_phase_4 Am2 on Am2.organisation = base.organisation and Am2.account = base.account and Am2.analysis = base.analysis and Am2.kpiref = base.kpiref and Am2.category = 'ACTUAL-2'
left outer join jobs_calculations_setvalues sv1 on base.kpiref = sv1.calcid
inner join jobs on base.jobID = jobs.id
cross apply spec.calculated_strategic_accounts(base.account) calc
union
-- *** CURRENT GFO ***
select base.organisation, calc.mm_account, base.analysis,
case base.kpiref when -1 then calc.source_of_value else sv1.value end source_of_value,
base.account, base.[year], 'CURRENT GFO' category,
[currency] currency_code, ltrim(rtrim(right(jobs.name, len(jobs.name) - patindex('%@%', jobs.name)))) forex_rate_type, base.[month],
isnull(Y_0.v01, 0) v01, isnull(Y_0.v02, 0) v02, isnull(Y_0.v03, 0) v03, isnull(Y_0.v04, 0) v04, isnull(Y_0.v05, 0) v05, isnull(Y_0.v06, 0) v06,
isnull(Y_0.v07, 0) v07, isnull(Y_0.v08, 0) v08, isnull(Y_0.v09, 0) v09, isnull(Y_0.v10, 0) v10, isnull(Y_0.v11, 0) v11, isnull(Y_0.v12, 0) v12,
isnull(Y_0.CMO, 0) CMO, (0) forecast_accuracy, isnull(Y_0.YTD, 0) YTD, (0) QTD, isnull(Y_0.FYR, 0) FYR,
(isnull(Ym1.v01, 0) + isnull(Ym1.v02, 0) + isnull(Ym1.v03, 0) + isnull(Ym1.v04, 0) + isnull(Ym1.v05, 0) + isnull(Ym1.v06, 0) + isnull(Ym1.v07, 0) + isnull(Ym1.v08, 0) + isnull(Ym1.v09, 0) + isnull(Ym1.v10, 0) + isnull(Ym1.v11, 0) + isnull(Ym1.v12, 0)) FYR_1,
(isnull(Ym2.v01, 0) + isnull(Ym2.v02, 0) + isnull(Ym2.v03, 0) + isnull(Ym2.v04, 0) + isnull(Ym2.v05, 0) + isnull(Ym2.v06, 0) + isnull(Ym2.v07, 0) + isnull(Ym2.v08, 0) + isnull(Ym2.v09, 0) + isnull(Ym2.v10, 0) + isnull(Ym2.v11, 0) + isnull(Ym2.v12, 0)) FYR_2,
(isnull(Yp1.v01, 0) + isnull(Yp1.v02, 0) + isnull(Yp1.v03, 0) + isnull(Yp1.v04, 0) + isnull(Yp1.v05, 0) + isnull(Yp1.v06, 0) + isnull(Yp1.v07, 0) + isnull(Yp1.v08, 0) + isnull(Yp1.v09, 0) + isnull(Yp1.v10, 0) + isnull(Yp1.v11, 0) + isnull(Yp1.v12, 0)) FYR_NY,
(isnull(Ym2.v01,0)+isnull(Ym2.v02,0)+isnull(Ym2.v03,0)) q01, (isnull(Ym2.v04,0)+isnull(Ym2.v05,0)+isnull(Ym2.v06,0)) q02, (isnull(Ym2.v07,0)+isnull(Ym2.v08,0)+isnull(Ym2.v09,0)) q03, (isnull(Ym2.v10,0)+isnull(Ym2.v11,0)+isnull(Ym2.v12,0)) q04,
(isnull(Ym1.v01,0)+isnull(Ym1.v02,0)+isnull(Ym1.v03,0)) q05, (isnull(Ym1.v04,0)+isnull(Ym1.v05,0)+isnull(Ym1.v06,0)) q06, (isnull(Ym1.v07,0)+isnull(Ym1.v08,0)+isnull(Ym1.v09,0)) q07, (isnull(Ym1.v10,0)+isnull(Ym1.v11,0)+isnull(Ym1.v12,0)) q08,
(isnull(Y_0.v01,0)+isnull(Y_0.v02,0)+isnull(Y_0.v03,0)) q09, (isnull(Y_0.v04,0)+isnull(Y_0.v05,0)+isnull(Y_0.v06,0)) q10, (isnull(Y_0.v07,0)+isnull(Y_0.v08,0)+isnull(Y_0.v09,0)) q11, (isnull(Y_0.v10,0)+isnull(Y_0.v11,0)+isnull(Y_0.v12,0)) q12,
dbo.dateOnly(getdate()) date_uploaded, 'strata' data_source
from
(select organisation, account, analysis, [year], kpiref, min([month]) [month], min(jobID) jobID from staging_phase_4
where category in ('CURRENT GFO', 'ACTUAL-1', 'ACTUAL-2', 'CURRENT GFO+1')
and jobID in (select id from dbo.jobs where (name in ('strata @ Actual Average', 'strata @ Plan')))
group by organisation, account, analysis, [year], kpiref) base
left outer join staging_phase_4 Y_0 on Y_0.organisation = base.organisation and Y_0.account = base.account and Y_0.analysis = base.analysis and Y_0.kpiref = base.kpiref and Y_0.category = 'CURRENT GFO'
left outer join staging_phase_4 Ym1 on Ym1.organisation = base.organisation and Ym1.account = base.account and Ym1.analysis = base.analysis and Ym1.kpiref = base.kpiref and Ym1.category = 'ACTUAL-1'
left outer join staging_phase_4 Ym2 on Ym2.organisation = base.organisation and Ym2.account = base.account and Ym2.analysis = base.analysis and Ym2.kpiref = base.kpiref and Ym2.category = 'ACTUAL-2'
left outer join staging_phase_4 Yp1 on Yp1.organisation = base.organisation and Yp1.account = base.account and Yp1.analysis = base.analysis and Yp1.kpiref = base.kpiref and Yp1.category = 'CURRENT GFO+1'
left outer join jobs_calculations_setvalues sv1 on base.kpiref = sv1.calcid
inner join jobs on base.jobID = jobs.id
cross apply spec.calculated_strategic_accounts(base.account) calc
union
-- *** PREVIOUS RF ***
select base.organisation, calc.mm_account, base.analysis,
case base.kpiref when -1 then calc.source_of_value else sv1.value end source_of_value,
base.account, base.[year], 'PREVIOUS RF' category,
[currency] currency_code, ltrim(rtrim(right(jobs.name, len(jobs.name) - patindex('%@%', jobs.name)))) forex_rate_type, base.[month],
isnull(Y_0.v01, 0) v01, isnull(Y_0.v02, 0) v02, isnull(Y_0.v03, 0) v03, isnull(Y_0.v04, 0) v04, isnull(Y_0.v05, 0) v05, isnull(Y_0.v06, 0) v06,
isnull(Y_0.v07, 0) v07, isnull(Y_0.v08, 0) v08, isnull(Y_0.v09, 0) v09, isnull(Y_0.v10, 0) v10, isnull(Y_0.v11, 0) v11, isnull(Y_0.v12, 0) v12,
isnull(Y_0.CMO, 0) CMO, (0) forecast_accuracy, isnull(Y_0.YTD, 0) YTD, (0) QTD, isnull(Y_0.FYR, 0) FYR,
(isnull(Ym1.v01, 0) + isnull(Ym1.v02, 0) + isnull(Ym1.v03, 0) + isnull(Ym1.v04, 0) + isnull(Ym1.v05, 0) + isnull(Ym1.v06, 0) + isnull(Ym1.v07, 0) + isnull(Ym1.v08, 0) + isnull(Ym1.v09, 0) + isnull(Ym1.v10, 0) + isnull(Ym1.v11, 0) + isnull(Ym1.v12, 0)) FYR_1,
(isnull(Ym2.v01, 0) + isnull(Ym2.v02, 0) + isnull(Ym2.v03, 0) + isnull(Ym2.v04, 0) + isnull(Ym2.v05, 0) + isnull(Ym2.v06, 0) + isnull(Ym2.v07, 0) + isnull(Ym2.v08, 0) + isnull(Ym2.v09, 0) + isnull(Ym2.v10, 0) + isnull(Ym2.v11, 0) + isnull(Ym2.v12, 0)) FYR_2,
(isnull(Yp1.v01, 0) + isnull(Yp1.v02, 0) + isnull(Yp1.v03, 0) + isnull(Yp1.v04, 0) + isnull(Yp1.v05, 0) + isnull(Yp1.v06, 0) + isnull(Yp1.v07, 0) + isnull(Yp1.v08, 0) + isnull(Yp1.v09, 0) + isnull(Yp1.v10, 0) + isnull(Yp1.v11, 0) + isnull(Yp1.v12, 0)) FYR_NY,
(isnull(Ym2.v01,0)+isnull(Ym2.v02,0)+isnull(Ym2.v03,0)) q01, (isnull(Ym2.v04,0)+isnull(Ym2.v05,0)+isnull(Ym2.v06,0)) q02, (isnull(Ym2.v07,0)+isnull(Ym2.v08,0)+isnull(Ym2.v09,0)) q03, (isnull(Ym2.v10,0)+isnull(Ym2.v11,0)+isnull(Ym2.v12,0)) q04,
(isnull(Ym1.v01,0)+isnull(Ym1.v02,0)+isnull(Ym1.v03,0)) q05, (isnull(Ym1.v04,0)+isnull(Ym1.v05,0)+isnull(Ym1.v06,0)) q06, (isnull(Ym1.v07,0)+isnull(Ym1.v08,0)+isnull(Ym1.v09,0)) q07, (isnull(Ym1.v10,0)+isnull(Ym1.v11,0)+isnull(Ym1.v12,0)) q08,
(isnull(Y_0.v01,0)+isnull(Y_0.v02,0)+isnull(Y_0.v03,0)) q09, (isnull(Y_0.v04,0)+isnull(Y_0.v05,0)+isnull(Y_0.v06,0)) q10, (isnull(Y_0.v07,0)+isnull(Y_0.v08,0)+isnull(Y_0.v09,0)) q11, (isnull(Y_0.v10,0)+isnull(Y_0.v11,0)+isnull(Y_0.v12,0)) q12,
dbo.dateOnly(getdate()) date_uploaded, 'strata' data_source
from
(select organisation, account, analysis, [year], kpiref, min([month]) [month], min(jobID) jobID from staging_phase_4
where category in ('PREVIOUS RF', 'ACTUAL-1', 'ACTUAL-2', 'PREVIOUS RF+1')
and jobID in (select id from dbo.jobs where (name in ('strata @ Actual Average', 'strata @ Plan')))
group by organisation, account, analysis, [year], kpiref) base
left outer join staging_phase_4 Y_0 on Y_0.organisation = base.organisation and Y_0.account = base.account and Y_0.analysis = base.analysis and Y_0.kpiref = base.kpiref and Y_0.category = 'PREVIOUS RF'
left outer join staging_phase_4 Ym1 on Ym1.organisation = base.organisation and Ym1.account = base.account and Ym1.analysis = base.analysis and Ym1.kpiref = base.kpiref and Ym1.category = 'ACTUAL-1'
left outer join staging_phase_4 Ym2 on Ym2.organisation = base.organisation and Ym2.account = base.account and Ym2.analysis = base.analysis and Ym2.kpiref = base.kpiref and Ym2.category = 'ACTUAL-2'
left outer join staging_phase_4 Yp1 on Yp1.organisation = base.organisation and Yp1.account = base.account and Yp1.analysis = base.analysis and Yp1.kpiref = base.kpiref and Yp1.category = 'PREVIOUS RF+1'
left outer join jobs_calculations_setvalues sv1 on base.kpiref = sv1.calcid
inner join jobs on base.jobID = jobs.id
cross apply spec.calculated_strategic_accounts(base.account) calc
使用OPENQUERY子句将数据插入到链接服务器(SQL server除外):
insert into openquery(LINKEDORACLESERVER,'select col1, col2, col3 from SCHEMANAME.TABLENAME')
select col1, col2, col3 from spec.staging_tablename;
检查从中选择数据的视图,问题不在Oracle方面。(请参见注释;-)您可以更改传输顺序吗?当你先执行第二次插入时会发生什么?哇,太简单了,但我还没试过。我会在30分钟内通知您。在第一次插入之前目标表是否为空?没关系,它使用相同的模式。另外,我只能在仍在测试的情况下清空目标表,这不能在生产环境中完成。您如何进行插入?批量插入?交易?反过来说。从MS SQL加载到Oracle。这正是脚本所做的-从SQL Server(表spec.staging\u tablename)到Oracle(表SCHEMANAME.tablename)。请记住列出所有列。首先,请尝试仅使用SELECT子句以确保如何正确使用OPENQUERY子句,例如,从OPENQUERY中选择*(LINKEDORACLESERVER,'SELECT col1,col2,col3 from SCHEMANAME.TABLENAME')啊,对不起,我的错。我很快会尝试一下,但你有机会检查我的更新吗?实际上,第二个作业的源代码(实际上是一个视图,请参见上面的代码)慢了19倍。有一次,当我使用直接链接到Oracle DB而不是openquery子句时,我遇到了一些性能问题,因此您可以尝试openquery。如果它不起作用,你应该根据你使用的参数准确地研究你的视图——正如ammoQ所说,这可能是你的瓶颈。这里的经验教训:不要因为开发平台上的其他东西运行得很快而懒得假设其他平台的性能不好/很慢/很差。