sqlsql-serverperformancet-sqlstored-procedures

Does source length of SQL functions matter


First, to define what I'm talking about, the "length" of a source is how many characters it has. Having more characters allows improving readability by using more descriptive function and variable names, as well as indentation.

In compiled languages, the length of the source's text does not matter, but in interpreted languages (which AFAIK SQL is) it can. Does that also extend to stored procedures/functions?

In other words, do I need to try to minimize something like this:

CREATE FUNCTION dbo.Add_Highest_Subjects
    (@studentScoreInMath INT,
     @studentScoreInBiology INT,
     @studentScoreInLiterature INT)
RETURNS INT
AS
BEGIN
    DECLARE @bestOfTwo INT

    SET @bestOfTwo = 
        CASE
            WHEN @studentScoreInMath > @studentScoreInBiology 
                AND @studentScoreInBiology > @studentScoreInLiterature
                THEN @studentScoreInMath + @studentScoreInBiology

            WHEN @studentScoreInMath > @studentScoreInBiology 
                AND @studentScoreInBiology < @studentScoreInLiterature
                THEN @studentScoreInMath + @studentScoreInLiterature

            ELSE @studentScoreInBiology + @studentScoreInLiterature
        END

    RETURN @bestOfTwo
END

into that:

CREATE FUNCTION dbo.ahs(@m INT, @b INT, @l INT)
RETURNS INT
AS
BEGIN
    DECLARE @r INT

    SET @r = CASE 
                 WHEN @m > @b AND @b > @l THEN @m + @b 
                 WHEN @m > @b AND @b < @l THEN @m + @l 
                 ELSE @b + @l 
             END
    RETURN @r
END

Or is there no need?

PS: this is quite hard to search for, as I keep finding explanations of how the LEN function works, instead of the answer to my question.

PPS: I can't believe I have to say this: the function above is an example stripped down to essentials (variable names and indentations). I don't need advice on how to add two integers efficiently, but thank you.


Solution

  • In short: No, variable name lengths usually do not matter.

    Interpreted languages usually parse variable names and assign IDs or some other form of identifier, so usually all variable names tend to end up with names of the same lengths internally.

    There are a few other performance concerns that may arise depending on database access, data transfer, and so on. Since some of these processes might actually involve the storage or transfer of these huge variable names, it would indeed slow down the process, increase the amount of data transferred and various other issues. Normally though? A variable name that isn't 200+ characters barely makes a difference and I don't know if 200 characters would already even be measurable in useful frames of reference.

    Just be advised that long names can hurt readability.