Fix sp_BlitzIndex error when scanning a database name of nvarchar(128)#3738
Fix sp_BlitzIndex error when scanning a database name of nvarchar(128)#3738MisterZeus wants to merge 4 commits intoBrentOzarULTD:devfrom
Conversation
…r(128)
When you run sp_BlitzIndex on a database/schema/table that actually has a name of nvarchar(128), it blows up at the debug step "Inserting data into #ForeignKeys".
You can replicate this by creating The Horrible Database, Schema, and Table below:
CREATE DATABASE [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
ON PRIMARY (
NAME = N'DATA456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
,FILENAME = N'C:\SQL\DATA456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
,SIZE = 1MB
,MAXSIZE = 20MB
,FILEGROWTH = 10MB
)
LOG ON (
NAME = N'LOG3456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
,FILENAME = N'C:\SQL\LOG3456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
,SIZE = 1MB
,MAXSIZE = 20MB
,FILEGROWTH = 10MB
)
;
USE [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
GO
CREATE SCHEMA [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
GO
CREATE TABLE [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
.[ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
(
[ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
[tinyint] NOT NULL
)
BrentOzar
left a comment
There was a problem hiding this comment.
Can you get your changes down to just what matters? I'm trying to review the code and it looks like there are tons of changes - you can see it here: https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/pull/3738/files?diff=split&w=1
I'm guessing you ran this code through some kind of formatter, and just at a glance, I'm not sure what changes you're making on purpose versus on accident. Thanks for understanding!
|
@BrentOzar should be cleaner now? Just removing whitespace to make the string smaller so it stops truncating the end of the dynamic tsql. |
BrentOzar
left a comment
There was a problem hiding this comment.
Can you do me a favor - when you submit a pull request, look at the file diff in Github, look to see if the changes are actually what you want. Right now, the only change is just spacing and casing. I don't think this is really what you want.

When you run sp_BlitzIndex on a database/schema/table that actually has a name of nvarchar(128),
it blows up at the debug step "Inserting data into #ForeignKeys".
I found this was because one of the @Dsql values was being truncated when you pass a database name of 128 chars.
The easiest fix was to edit the offending @Dsql query to stop using millions of consecutive spaces, and swap instead to tabs and well-formatted code.
You can replicate the problem and test the fix by creating The Horrible Database, Schema, and Table below, and running sp_BlitzIndex in various @modes.
(the names contain 128 Unicode characters, including some Greek at the start, and a space, to really test your code properly!)
CREATE DATABASE [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF] ON PRIMARY (
NAME = N'DATA456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
,FILENAME = N'C:\SQL\DATA456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
,SIZE = 1MB
,MAXSIZE = 20MB
,FILEGROWTH = 10MB
)
LOG ON (
NAME = N'LOG3456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
,FILENAME = N'C:\SQL\LOG3456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
,SIZE = 1MB
,MAXSIZE = 20MB
,FILEGROWTH = 10MB
)
;
USE [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
GO
CREATE SCHEMA [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
GO
CREATE TABLE [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
.[ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
(
[ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
[tinyint] NOT NULL
)