This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Display of SQL text (SQL Server), possible bug

When displaying the SQL text for a hash, it displays the statement, followed by the entire stored procedure text (if the statement is part of a procedure. However I'm having a problem with the display of SQL text that is not part of a procedure.

We have written custom code for Entity Framework that injects a comment containing the location of the method that contains the LINQ from which the SQL is being generated into the generated SQL itself. This is really helpful, except when the generated SQL is very long.

For a relatively short statement, I'll see something like this:

-- Core.Repositories.PurchaseOrderHistoryRepo.GetPurchaseOrderLineItems

SELECT [Extent1].[SKUId] AS [SKUId], [Extent1]

.[doh] AS [doh], [Project1]

...

(DPA shows the entire thing, I just put in the ellipsis to conserve space.)

However, if it is very long, I see something like this:

/* (inserted by DPA)

Text truncated due to excessive length

*/

SELECT [Project1].[id] AS [id], [Project1]

.[doh] AS [doh], [Project1]

...

But if I hunt it down in sys.dm_exec_sql_text.test, I see this:

(@p__linq__0 decimal(5,0))-- Core.Repositories.InventoryRepository.GetAllNonDiscontinuedBySupplierId

SELECT

    [Project1].[id] AS [id],

    [Project1].[doh] AS [doh],

...

Note that the first line is not shown by DPA. That first line (shown in red for emphasis) not only shows me what the parameter is, it also includes our injected comment. DPA must be filtering out everything before the SELECT keyword. This is an anti-feature. emoticons_laugh.png

Also note that in both examples, the SQL is getting reformatted (it is wrapped differently than what is shown by the DMV) and in the first example a blank line is inserted between the comment and the SELECT whereas in the second example the line before the select isn't separated by a blank line, it is instead completely removed. (I tried to find a short example that also had a parameter but was unable to find one quickly.)

I haven't investigated enough to determine if the text is being stored in the repository the same way it is coming out of the DMV, in which case this is a UI issue, or whether it is an issue with the SQL being executed to populate the repository.

I'd submit a feature request to improve this, but I think it should be considered a bug to be fixed and made a higher priority.

While I'm here, consider this a plug for a feature request I submitted that is tangentially related:

  • Just a heads up - engineering is taking a look at this.

    My first though is that everything before the statement itself is being thrown away to present as much of the actual query as possible since we know it will be truncated.

    As you state though, this could be a disservice in a case like you have here...

  • mandevil: Any news on this? Is it being handled as a bug or do I need to submit it as a feature request?

  • m60freeman​, This was treated as a bug DPA-639. It was fixed in the DPA 11 builds that are now in RC. "Fixed an issue where the text poll for SQL Server was truncated to 8000 characters."

    Reading the notes it was fixed as follows.

    In the options menu there is new parameters.

    added a new parameter (SQLTEXT_SQLSERVER_MAX_TEXT_LENGTH_LEGACY) to allow us to have different defaults for SQL Server 2000 and SQL Server 2005+ and Azure

    SQLTEXT_SQLSERVER_MAX_TEXT_LENGTH

    Defaults to 19999 with a max value of 49999

    For SQL Server 2005+ and Azure

    SQLTEXT_SQLSERVER_MAX_TEXT_LENGTH_LEGACY

    Defaults to 7999 with a max value of 7999

    Verified with 9000+ char stored procedure on SQL 2k16. Verified entire SQL shows in multiple views. Compared against old DPA where it truncates.

  • Looks like Jamin provided the status on this one - let me know if there's anything else though!

  • Excellent! I'll test it out.

  • Is this fixed only for new SQL not in the repository prior to upgrading or should it be working for all? I'm not seeing new results for older statements.

  • Mark,

    This is a good point. I hadn't thought it through fully on that one and so I asked in engineering. In the fix we made it so DPA can poll and store more SQL text. However with the way DPA polls SQL text if we think we have the text we do not recollect it. This is to avoid polling data we would have. Because of this if you had a SQL hash that had been collected and truncated you would need to clear the text from the CONST_ID table for that hash and then if DPA sees the same text / hash again it would collect it and get the part it had not before.

  • Do you mean UPDATE ignite.CONST_ID SET ST = NULL WHERE TRUNCATED = 'Y' AND PNAME IS NULL or DELETE ignite.CONST_ID WHERE TRUNCATED = 'Y' AND PNAME IS NULL?