Do you have a comment or suggestion to improve SQL Server? We’d love to hear it!

Permit UDF with time-dependent functions to be inlined

The advent of inlining of scalar UDFs in SQL 2019 is a major leap forward! UDF will remain a trap for many developers since far from all UDFs cannot be inlined. For the most part, there is not much to about it. How would you inline a WHILE loop? And overall, the changes in SQL 2019 go far beyond what I could ever dream of.

However, there is one inline preventer that I am not happy with and that is functions that calls gedate() & co. I understand why they do not inline by default, as that could be a breaking change - a system may rely on that sysdatetime() can return different values for different rows. However, it should be possible to force inlining with INLINE = ON as in this example:

CREATE FUNCTION sysdate() RETURNS date WITH INLINE = ON AS
BEGIN
RETURN convert(date, sysdatetime())
END

In my experience, it is not at all uncommon to use getdate()/sysdatetime() in scalar UDFs, and naïve users are likely to expect the function to inline, particularly when it is a simple like the one above.

3 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Erland Sommarskog shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base