Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sp_BlitzCache - Alert for computed columns that reference scalar UDFS #617

Closed
BlitzErik opened this issue Dec 4, 2016 · 1 comment
Closed

Comments

@BlitzErik
Copy link
Contributor

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
We find compute scalar operators that reference scalar UDFs, but we can also detect if they're in computed columns

<ComputeScalar>
                    <DefinedValues>
                      <DefinedValue>
                        <ColumnReference Database="[RebuildVsReorg]" Schema="[dbo]" Table="[Orders]" Alias="[o]" Column="ID_Multiply" **ComputedColumn="true"** />
                        <ScalarOperator ScalarString="[RebuildVsReorg].[dbo].[Multiplier](CONVERT_IMPLICIT(int,[RebuildVsReorg].[dbo].[Orders].[ID] as [o].[ID],0))">
                          <UserDefinedFunction FunctionName="[RebuildVsReorg].[dbo].[Multiplier]">

**If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via http://sqlfiddle.com

What is the expected behavior?
Additional flag for computed column UDFs because it may not be obvious where they're used if you look at just the query text.

Which versions of SQL Server and which OS are affected by this issue? Did this work in previous versions of our procedures?
All

@BlitzErik
Copy link
Contributor Author

This will look a lot like the code that catches functions, except we'll filter down to where a computed column is referenced.

WITH XMLNAMESPACES('http://schemas.microsoft.com/sqlserver/2004/07/showplan' AS p)
SELECT qs.QueryHash,
	   n.fn.value('count(distinct-values(//p:UserDefinedFunction[not(@IsClrFunction)]))', 'INT') AS function_count
FROM   #relop qs
CROSS APPLY relop.nodes('/p:RelOp/p:ComputeScalar/p:DefinedValues/p:DefinedValue/p:ScalarOperator') n(fn)
WHERE n.fn.exist('/p:RelOp/p:ComputeScalar/p:DefinedValues/p:DefinedValue/p:ColumnReference[(@ComputedColumn[.="1"])]') = 1
OPTION (RECOMPILE)

BlitzErik added a commit that referenced this issue Dec 4, 2016
This reverts commit aa9b05a.
BlitzErik added a commit that referenced this issue Dec 4, 2016
Closes #617
@BlitzErik BlitzErik mentioned this issue Dec 4, 2016
@BrentOzar BrentOzar added this to the 2016-12 milestone Dec 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants