sql – A copy of the function works instantly, and the original up to 2 minutes

Question:

There is a function that a lot of people use and sometimes it is terribly dull.

If I create a copy of this function and execute it exclusively for myself in the request where the original function is stupid, then the request is executed instantly, and if from the old then 2 minutes.

What could be the problem?

Does MS SQL have any kind of object level locks?

The query plans are identical.

Inside the function, all kinds of connections with tables, etc. are performed.

Could it be that the old function used some old statistics on tables, and the new function received updated statistics and is running faster?

UPD

It looks like it's not about statistics. If you swap the functions, then my newly compiled procedure starts to dull, and the old procedure works fine …

Answer:

It is unlikely that it will be possible to quickly answer your question, I would recommend reading a useful article about the reasons for such a slowdown – if you regularly work with MS SQL, this can be very useful and informative:

http://www.somewheresomehow.ru/fast-in-ssms-slow-in-app-part1/

Scroll to Top