What are the magic pink numbers you can see in Code Outline window?

The answer is very simple - these are

So how Complexity is calculated?*numbers. Each number represents complexity of outlined node, something like Cost in query execution plan. The same numbers you can see after Complexity check - but for whole procedure, not for each statement.***Code Complexity**Here is a schematic calculation algorithm:

- Each statement breaks into very small parts.
- Complexity of each statement consists of complexity of all its parts.
- Each part has some constant complexity (weight), usually 0.01. Why so small weight? Each statement can break into a huge number of parts.
- Each identifier has weight of one. So the more identifiers you use (tables, functions, columns) the more complex your query is.
- Some statements or its part can have a big weight (eg EXEC(query) has weight of ten).
- For complex parts of statement (eg - correlated subquery or query under EXISTS clause) its complexity is multiplied by "Complex factor" (for derived_table by factor of two. Rowset functions are multiplied by factor of ten).
- First <table_source> in FROM clause have multiplication factor of one, each next have multiplication factor of one and a half.

Do you have a table with different categories for the complexity values? When we should worry about a piece of code that has too much complexity?

ReplyDeleteThanks in advance