Got an interesting one that I've struggled to resolve for several years now and is starting to become a bigger issue. We have a UDF that is used thoroughly throughout our system and retrieves a single value back from a journal table. It usually runs instantly, however periodically something appears to happen to its query plan causing it to run for several minutes without returning.
We have found that if we recompile the UDF, it works again.
If I pull back the execution plan I don't really get any information back indicating a problem with an index.
EDIT: Copy of execution plan: https://filebin.net/jlxf0ejqeyz9j9b9
EDIT 2: Screenshots of exec plan: screenshot 1: https://filebin.net/eula7cir72lp95iv/exec-screenshot1.png?t=0i8i2kyj
screenshot 2: https://filebin.net/yr2d84x5fftqjvnm/exec-screenshot2.png?t=um9ldpdk
EDIT 3: screenshot 3 hovering over the function call: https://filebin.net/9azjdvb1mpmsi3am/exec-screenshot3.png?t=qjsemw6d
We currently have a job which loops through and recompiles the UDF every 30 minutes which I know is just a bandaid solution. If anyone has some recommendations on how to debug this further I would greatly appreciate your insight!
Unfortunately it's a problem that doesn't always show itself so quite often we don't know about it until someone points it out.