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

BlitzIndex Column Details Showing Half Sizes for varchar Columns #1068

Closed
powderdba opened this issue Aug 16, 2017 · 3 comments
Closed

BlitzIndex Column Details Showing Half Sizes for varchar Columns #1068

powderdba opened this issue Aug 16, 2017 · 3 comments
Assignees
Milestone

Comments

@powderdba
Copy link

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

What is the current behavior?
When running BlitzIndex with the @tablename parameter, the column information is incorrectly showing datatype sizes of half of what they should be for varchar. Example: Varchar(8) is showing as varchar(4). The thing that made me first notice is that some columns were showing as varchar(0). Nchar datatypes lengths are also not being divided in half like nvarchars are.

What is the expected behavior?
Show the correct data lengths.

Details:
I believe it's just a simple datatype mix up between two lines of code. On lines 1945 and 1946 of BlitzIndex:
Nchar should be down with the other unicode datatype nvarchar on line 1946 (with the lengths being divided by 2), and varchar should be up on line 1945 with the non unicode datatypes (with the lengths not being divided by 2) :)

@BrentOzar BrentOzar self-assigned this Aug 25, 2017
@BrentOzar BrentOzar added this to the 2017-09 milestone Aug 25, 2017
@BrentOzar
Copy link
Member

BrentOzar commented Aug 27, 2017

Good catch! I had to do some digging to understand what you were reporting. Here's a repro script:

CREATE TABLE dbo.Tester 
  (my_varchar10 VARCHAR(10),
   my_char10 CHAR(10),
   my_varcharmax VARCHAR(MAX),
   my_nvarchar10 NVARCHAR(10),
   my_nchar10 NCHAR(10),
   my_nvarcharmax NVARCHAR(MAX),
   my_integer INT,
   my_guid UNIQUEIDENTIFIER,
   my_datetime DATETIME,
   my_decimal_18_2 DECIMAL(18,2),
   my_decimal_4_0 DECIMAL(4,0));
GO
CREATE INDEX ix_my_varchar10 ON dbo.Tester(my_varchar10);
CREATE INDEX ix_my_nvarchar10 ON dbo.Tester(my_nvarchar10);
CREATE INDEX ix_my_char10 ON dbo.Tester(my_char10);
CREATE INDEX ix_my_nchar10 ON dbo.Tester(my_nchar10);
CREATE INDEX ix_my_integer ON dbo.Tester(my_integer);
CREATE INDEX ix_my_guid ON dbo.Tester(my_guid);
CREATE INDEX ix_my_datetime ON dbo.Tester(my_datetime);
CREATE INDEX ix_my_decimal_18_2 ON dbo.Tester(my_decimal_18_2);
CREATE INDEX ix_my_decimal_4_0 ON dbo.Tester(my_decimal_4_0);
GO
sp_BlitzIndex @TableName = 'Tester';
GO
DROP TABLE dbo.Tester;

The output:
1

It's confusing, but the number in parenthesis means different things in different result sets and columns:

  • Result set 1, column "Definition" - parenthesis means maximum bytes required for storage.
  • Result set 3, column "Length (max bytes)"
  • Result set 3, column "Type" - parenthesis means the datatype definition. This is the one that's wrong.

The results:

  • my_char10 says it's a char(10) - correct
  • my_nchar10 says it's an nchar(20) - wrong
  • my_nvarchar10 says it's an nvarchar(10) - correct
  • my_varchar10 says it's a varchar(5) - wrong

@BrentOzar
Copy link
Member

And you're exactly right about the fix, by the way - here's what it looks like after your fix:

1

Thanks!

BrentOzar added a commit that referenced this issue Aug 27, 2017
nchar and varchar fields were reporting the wrong data type lengths.
Closes #1068.
@powderdba
Copy link
Author

Yay! Thank you! :)

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