2

SQL Server 2012 Lag and Lead functions aren't performing well over large amounts of data, ~100 million records with ~200 columns.

The combination of

lag(balance, 1, 0) over (partition by loanId order by datetime series)

trying to get previous date's balance. The execution plan says most time consuming part falls in (order by) part.

Is there a way to improve the performance?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
kaiyan711
  • 171
  • 2
  • 7

1 Answers1

3

You can improve the performance by having an index on (loanid, datatime series).

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786