Your query slowness is almost certainly down to :
- Lack of suitable indexes to quickly find the associated rows
- The function being applied to the
TrnTime
column - forcing a table scan
If you create an additional calculated column for MONTH(TrnTime)
and include that in a non-clustered index with Amount
and DebitAccount
then your query would be quicker.
Also, calculating a balance (which I assume you are by calculating the sum of amounts on an account) while using NOLOCK
is full of dangers through phantom reads and repeated reads so I would not trust those query results.
With the size of the table, also consider partitioning it - either by MONTH(TrnTime)
or by DebitAccount
columns
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…