2
之間的性能差異,我有兩個簡單的腳本 之一是:噸-SQL:光標和光標靜態
declare @active_from date = '01.03.2014'
declare @active_to date = '01.04.2014'
declare @house_id integer = 11927
----
declare @service_id integer
declare @addendum_id integer
declare @activity_id integer
declare @session_id integer
declare @cur_active_from datetime
declare @cur_active_to datetime
declare @session_license_fee_cur cursor
-- prepare cursor
set @session_license_fee_cur = cursor static for
select activity_id
, addendum_id
, service_id
, active_from
, active_to
from dbo.bills_supp_get_activate_license_fee_for_sessions_by_house(@active_from, @active_to, @house_id)
-- open cursor
open @session_license_fee_cur
fetch next from @session_license_fee_cur into @activity_id, @addendum_id, @service_id, @cur_active_from, @cur_active_to
while (@@FETCH_STATUS = 0)
begin
-- get next record
fetch next from @session_license_fee_cur into @activity_id, @addendum_id, @service_id, @cur_active_from, @cur_active_to
end
--
close @session_license_fee_cur
deallocate @session_license_fee_cur
它的工作原理不到一秒鐘。 第二個是一樣的,而是
set @session_license_fee_cur = cursor static for
我用
set @session_license_fee_cur = cursor for
沒有 「靜態」。它的工作時間超過1分鐘。 爲什麼這樣的性能差異? 查詢計數的記錄是大約3000