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 add check for table variable use #422

Closed
CharBosell opened this issue Aug 16, 2016 · 4 comments
Closed

sp_BlitzCache add check for table variable use #422

CharBosell opened this issue Aug 16, 2016 · 4 comments

Comments

@CharBosell
Copy link

During a SQL Performance Tuning class today with Brent, we were discussing the horrible performance of Table variables in SQL queries.

I would like to see the addition of functionality for the identification of queries that are using table variables in sp_BlitzCache to help in identifying these issues.

@BlitzErik
Copy link
Contributor

BlitzErik commented Aug 16, 2016

It would be easy enough to identify table names beginning with '@' in execution plans, but physical tables can also lead with them. There's nothing explicit in an execution plan that differentiates between the two that I know of. At best we'd be guessing.

Here's some repro code attached. (BGO: updated, switched to attached file because Github is stripping parts of it out.)

TableVariables.txt

@BrentOzar
Copy link
Member

I couldn't get this line to work:

CREATE TABLE @craptable

The only way I could get it to work was to frame it in brackets like this:

CREATE TABLE [@craptable]

Which I thought I'd be able to catch because typical table variables aren't framed in square brackets, but the diabolical engine is adding the brackets behind me even when I don't use them:

<Object Table="[@crap]" Storage="RowStore" />

@BlitzErik
Copy link
Contributor

Yeah. I'm totally down to add it as something to look closer at in warnings, since physical tables that start with @ are pretty rare. The real benefit would be if we could also warn when estimates are skewed because of them, but of course cached plans don't give you actual vs estimated rows.

@BlitzErik BlitzErik changed the title sp_BlitzCache additional functionality requested sp_BlitzCache add check for table variable use Oct 20, 2016
@BrentOzar
Copy link
Member

Works! Repro:

DBCC FREEPROCCACHE GO DECLARE @Dining TABLE (DinerName VARCHAR(50)); INSERT INTO @Dining VALUES ('Pope Erik'); SELECT * FROM @Dining; GO sp_BlitzCache

Produces:

1

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

3 participants