I am working in a type 2 data vault and currently working on a function to try and simulate a data cube for certain users to do fast data pulls from specific snapshots.
At the moment i can modify the code to make it work by convert the paramerter on the join (or where clause) however this results in a 3 second performance reduction across 100,000 records.
For performance is it possible to perform a
set @AsAt = dbo.AdjustLocalToUtc(@AsAt)
somewhere before the return statement or pehaps at the very start.
Code Block - Works if UTC value passed
ALTER FUNCTION dbo.fn_Ticket_AsAt
(
@AsAt datetime --Local Time for User Confort
)
RETURNS TABLE
AS
RETURN
(
Select *
from dvr.hub_ticket hub
join dvr.sat_ticket sat
on hub.hub_ticket_sk = sat.hub_ticket_sk
and @AsAt between sat.load_datetime and coalesce(sat.load_end_datetime,getutcdate())
--Load_datetime and load_end_datetime are UTC values
)
What would be a desired form of the query as the conversion only needs to be performed once and not for each record.
ALTER FUNCTION dbo.fn_Ticket_AsAt
(
@AsAt datetime --Local Time for User Confort
, declare @dv datetime = dbo.AdjustLocaltoUtc(@AsAt)
)
RETURNS TABLE
AS
RETURN
(
Select *
from dvr.hub_ticket hub
join dvr.sat_ticket sat
on hub.hub_ticket_sk = sat.hub_ticket_sk
and @dv between sat.load_datetime and coalesce(sat.load_end_datetime,getutcdate())
--Load_datetime and load_end_datetime are UTC values
)