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

Fixes #1945 - sp_BlitzCache - Plural checks for @SortOrder #1958

Closed
wants to merge 1 commit into from
Closed

Conversation

RichBenner
Copy link
Contributor

@RichBenner RichBenner commented Feb 11, 2019

Fixes #1945

Changes proposed in this pull request:

  • additional plural checks
  • raise error to sev 16 if invalid sort order passed through

How to test this code:

  • It's easy enough to test with the block below. Otherwise call sp_BlitzCache @sortorder = 'your string' and check the output is as expected
DECLARE @SortOrder varchar(20) = 'execution'

SET @SortOrder = LOWER(@SortOrder);
SET @SortOrder = REPLACE(REPLACE(@SortOrder, 'average', 'avg'), '.', '');
SET @SortOrder = REPLACE(@SortOrder, 'executions per minute', 'avg executions');
SET @SortOrder = REPLACE(@SortOrder, 'execution per minute', 'avg executions');
SET @SortOrder = REPLACE(@SortOrder, 'executions / minute', 'avg executions');
SET @SortOrder = REPLACE(@SortOrder, 'execution / minute', 'avg executions');							  
SET @SortOrder = REPLACE(@SortOrder, 'xpm', 'avg executions');
SET @SortOrder = REPLACE(@SortOrder, 'recent compilations', 'compiles');
SET @SortOrder = REPLACE(@SortOrder, 'recent compilation', 'compiles');
SET @SortOrder = REPLACE(@SortOrder, 'compile', 'compiles');
SET @SortOrder = REPLACE(@SortOrder, 'read', 'reads');
SET @SortOrder = REPLACE(@SortOrder, 'avg read', 'avg reads');
SET @SortOrder = REPLACE(@SortOrder, 'write', 'writes');
SET @SortOrder = REPLACE(@SortOrder, 'avg write', 'avg writes');
SET @SortOrder = REPLACE(@SortOrder, 'memory grants', 'memory grant');
SET @SortOrder = REPLACE(@SortOrder, 'avg memory grants', 'avg memory grant');
SET @SortOrder = REPLACE(@SortOrder, 'spill', 'spills');
SET @SortOrder = REPLACE(@SortOrder, 'avg spill', 'avg spills');							  
IF @SortOrder = 'execution' SET @SortOrder = 'executions';

SELECT @SortOrder

RAISERROR(N'Checking sort order', 0, 1) WITH NOWAIT;
IF @SortOrder NOT IN ('cpu', 'avg cpu', 'reads', 'avg reads', 'writes', 'avg writes',
                       'duration', 'avg duration', 'executions', 'avg executions',
                       'compiles', 'memory grant', 'avg memory grant',
					   'spills', 'avg spills', 'all', 'all avg', 'sp_BlitzIndex')
  BEGIN
  RAISERROR(N'Invalid sort order chosen, reverting to cpu', 0, 1) WITH NOWAIT;
  RAISERROR(N'Invalid sort order chosen, reverting to cpu', 16, 1) WITH NOWAIT;
  SET @SortOrder = 'cpu';
  END;

Has been tested on (remove any that don't apply):

  • SQL Server 2012
  • SQL Server 2014

@BrentOzar
Copy link
Member

I'm on my phone so I can't test, but this looks like it will fail:

SET @sortorder = REPLACE(@sortorder, 'recent compilation', 'compiles');
SET @sortorder = REPLACE(@sortorder, 'compile', 'compiles');

Try it with 'recent compilation' and I think you'll end up with compiless.

Same thing with this:

SET @sortorder = REPLACE(@sortorder, 'write', 'writes');
SET @sortorder = REPLACE(@sortorder, 'avg write', 'avg writes');

I think if you pass in 'avg write', you'll end up with 'avg writess'. You may wanna use an if/else series of branches.

@RichBenner
Copy link
Contributor Author

that's a good point. I'll do the if branches and submit a new pull request

@RichBenner
Copy link
Contributor Author

3rd time's a charm

@RichBenner RichBenner closed this Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants