Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance Implications of Comments in SQL Stored Procedures

Recently at my day-job were were instructed that any comments regarding our stored procedures MUST NOT exist inside the stored procedure and rather Extended Properties must be used.

In the past we used something like this.

/*
 * NOTE: Auto-Generated Procedure DO NOT MODIFY
 */
CREATE PROCEDURE dbo.MyProc
AS
SELECT *
FROM MyTable
GO

This way anytime anyone opened the procedure in SSMS they would see the note, other comments also existed in procedures to document our process. Now I was not aware of any performance/memory issues with this. However we have individuals that insist it does.

I have not been able to find any documentation to prove or deny the existance of performance and/or memory issues with this type of comments.

So my question is, does anyone know of any documentation that can either prove or deny this?

like image 437
Mitchel Sellers Avatar asked Mar 30 '09 16:03

Mitchel Sellers


People also ask

Does commented code affect performance SQL?

PLSQL source code is compiled into binary code. Comments are comments in source code, they do not affect the runtime performance.

Do comments slow down SQL?

Can too many comments in a SQL Server 2000 stored procedure slow down that procedure? No, definitely not. Only the active code gets passed to the optimiser, so the comments don't go anywhere.

How do you comment a stored procedure in SQL?

To create line comments you just use two dashes "--" in front of the code you want to comment. You can comment out one or multiple lines with this technique.


2 Answers

It will slow down the compilation of the stored procedure just a tiny bit, and that shouldn't happen often anyway.

Basically this sounds like scare-mongering. Given how useful comments can be (in moderation) I would demand evidence that comments hurt performance. It sounds like a ridiculous policy to me.

(Demanding evidence any time someone makes claims about performance is a good general rule - particularly if they're suggesting that you sacrifice readability or some other positive attribute for the sake of the supposed performance gain.)

like image 72
Jon Skeet Avatar answered Sep 23 '22 05:09

Jon Skeet


The text (including comments) is stored in sys.sql_modules in SQL 2005+. So it adds to the system table size.

On compilation to produce a plan, the comments are ignored: they are comments. Just like any reasonable language...?

However, in some circumstances debug comments can apparently still be parsed and affect things.

This is something I saw a while ago but dismissed it (and searched for it for this answer).

like image 40
gbn Avatar answered Sep 20 '22 05:09

gbn