How can i fix Eager Spool?

rick_nica 2016-06-04 21:32:51

SQLkiwi 2016-06-12 10:24:02
To answer the question literally, you would need an index like:

CREATE INDEX index_name
ON dbo.MOVIMIENTOS_CONTABLES
(
    SUCURSAL_CUENTA, 
    MONEDA, 
    PRODUCTO, 
    OPERACION_CUENTA, 
    CUENTA, 
    ORDINAL_CUENTA
)
INCLUDE 
    (FECHAVALOR);

This will solve the immediate problem, but there are deeper issues with the execution plan related to the way the view is constructed, the way the PARAMETROS table is used, and the logic used to compare dates.