-4

Please I need help optimizing my database performance. I have done some profiling to see seek queries using BlitzCache script created by Brent Ozar. After executing the script, some number of queries was listed which I generated an execution plan which can be found on the following link. https://www.brentozar.com/pastetheplan/?id=H1FmJ9_Wi

the below query listed by BlitzCache:

(@_msparam_0 nvarchar(4000),@_msparam_1 nvarchar(4000),@_msparam_2 nvarchar(4000),@_msparam_3 nvarchar(4000),@_msparam_4 nvarchar(4000),@_msparam_5 nvarchar(4000),@_msparam_6 nvarchar(4000),@_msparam_7 nvarchar(4000))SELECT
tbl.name AS [Name],
SCHEMA_NAME(tbl.schema_id) AS [Schema],
'Server[@Name=' + quotename(CAST(
        serverproperty(N'Servername')
   AS sysname),'''') + ']' + '/Database[@Name=' + quotename(db_name(),'''') + ']' + '/Table[@Name=' + quotename(tbl.name,'''') + ' and @Schema=' + quotename(SCHEMA_NAME(tbl.schema_id),'''') + ']' AS [Urn],

tbl.create_date AS [CreateDate], CAST(tbl.is_memory_optimized AS bit) AS [IsMemoryOptimized], CAST(CASE idx.type WHEN 5 THEN 1 ELSE 0 END AS bit) AS [HasClusteredColumnStoreIndex], CAST(tbl.is_remote_data_archive_enabled AS bit) AS [RemoteDataArchiveEnabled], tbl.temporal_type AS [TemporalType], CAST(CASE WHEN 'PS'=dsidx.type THEN 1 ELSE 0 END AS bit) AS [IsPartitioned], CAST(

    ISNULL((SELECT distinct 1 from sys.all_columns

    WHERE object_id = tbl.object_id

    AND is_sparse = 1), 0)

   AS bit) AS [HasSparseColumn],

CAST(tbl.is_node AS bit) AS [IsNode], CAST(tbl.is_edge AS bit) AS [IsEdge], CAST(ISNULL((select top 1 1 from sys.indexes ind where ind.object_id = tbl.object_id and ind.type > 1 and ind.is_hypothetical = 0 ), 0) AS bit) AS [HasNonClusteredIndex], CAST(CASE idx.index_id WHEN 1 THEN 1 ELSE 0 END AS bit) AS [HasClusteredIndex], CAST(case idx.index_id when 1 then case when (idx.is_primary_key + 2*idx.is_unique_constraint = 1) then 1 else 0 end else 0 end AS bit) AS [HasPrimaryClusteredIndex], CAST(ISNULL((select top 1 1 from sys.indexes ind where ind.object_id = tbl.object_id and ind.type = 3 and ind.is_hypothetical = 0 ), 0) AS bit) AS [HasXmlIndex], CAST(ISNULL((select top 1 1 from sys.all_columns as clmns join sys.types as usrt on usrt.user_type_id = clmns.user_type_id where clmns.object_id = tbl.object_id and usrt.name = N'xml'), 0) AS bit) AS [HasXmlData], CAST(ISNULL((select top 1 1 from sys.all_columns as clmns join sys.types as usrt on usrt.user_type_id = clmns.user_type_id where clmns.object_id = tbl.object_id and usrt.name in (N'geometry', N'geography')), 0) AS bit) AS [HasSpatialData], CAST(ISNULL((select top 1 1 from sys.indexes ind where ind.object_id = tbl.object_id and ind.type = 6 and ind.is_hypothetical = 0 ), 0) AS bit) AS [HasNonClusteredColumnStoreIndex] FROM sys.tables AS tbl INNER JOIN sys.indexes AS idx ON

    idx.object_id = tbl.object_id and (idx.index_id < @_msparam_0  or (tbl.is_memory_optimized = 1 and idx.index_id = (select min(index_id) from sys.indexes where object_id = tbl.object_id)))


LEFT OUTER JOIN sys.data_spaces AS dsidx ON dsidx.data_space_id = idx.data_space_id WHERE (CAST(

case

when tbl.is_ms_shipped = 1 then 1

when (

    select 

        major_id 

    from 

        sys.extended_properties 

    where 

        major_id = tbl.object_id and 

        minor_id = 0 and 

        class = 1 and 

        name = N'microsoft_database_tools_support') 

    is not null then 1

else 0

end

         AS bit)=@_msparam_1 and tbl.is_filetable=@_msparam_2 and CAST(tbl.is_memory_optimized AS bit)=@_msparam_3 and tbl.temporal_type=@_msparam_4 and CAST(tbl.is_external AS bit)=@_msparam_5 and CAST(tbl.is_node AS bit)=@_msparam_6 and CAST(tbl.is_edge AS bit)=@_msparam_7)

Dan Guzman
  • 28,168
  • 2
  • 44
  • 68
  • 2
    You've posted a query that hits SQL Server system views. Those aren't typically ones that anyone can tune. Are you sure there aren't some higher priority user queries? – Erik Darling Sep 21 '22 at 14:17
  • It looks like it's probably a script run by a tool like SSMS – Charlieface Sep 21 '22 at 14:56
  • @ErikDarling I got this query after investigating my database. i thought as much, this queries are used by the server. – Keembest Sep 21 '22 at 15:32
  • @ErikDarling What i don't get is why is the query performance low. it was not created by me. this is really crashing the app – Keembest Sep 21 '22 at 15:35
  • If you can find the query hash, you can set up an XE to capture the application_name. Usually, this is some 3rd party monitoring tool or IntelliSense, etc. – Zikato Sep 21 '22 at 15:44
  • 4
    How do you know that it is this query that is "crashing your app"? – Tibor Karaszi Sep 21 '22 at 15:44
  • @TiborKaraszi I executed a BlitzCache script to find the first most slow performance queries and this query appear to be number one. the problem is it is not a query i can edit. it is a sys.object query on a system table called [sysschobjs] – Keembest Sep 22 '22 at 04:50
  • The query is likely generated by a tool. like SQL Server Management Studio or the database project in Visual Studio. There's nothing you can do about it. As for why sp_blitzcache show this as a "slow performance query" we can't say since we don't have any details, like the parameters you passed to sp_blitzcache or the actual output from sp_blitzcache. Most likely a red herring. – Tibor Karaszi Sep 22 '22 at 08:18

1 Answers1

1

Two quick guesses based on the information you provided in your question:

  1. Your SQL Server instance is not yet productive and sp_BlitzCache is showing internal statements that are "slow", because they are the only statements currently running. ==> This is possibly a non-issue.

  2. Your SQL Server instance is productive and the statement shown in the results of sp_BlitzCache is at the top. ==> This could mean that your productive databases aren't being used a lot. ==> See General Considerations further down.

  3. You seem to be having a general issue with your SQL Server instance. Consider using sp_Blitz to see if your SQL Server instance is configured correctly. This will return a prioritised list of items to check.

General Considerations

  1. Is your SQL Server instance a stand-alone instance or is it competing with resources from applications running on the same server? It is running on a server, isn't it? And it isn't running on a Domain Server, right?

  2. Does your Windows Server have enough RAM? Is your SQL Server instance's max server memory (MB) configured to allow for enough database pages to be cached in memory? Maximum server memory (duplicate)

  3. Is your SQL Server instance running on a supported version of SQL Server? (Service Packs, Cummulative Updates, ...)

  4. Is the network connection sufficient enough to support the amount of queries you are expecting? Are you possibly having network issues?

  5. If you check the wait statistics of your SQL Server instance for an hour using the script provided in the Blog Post Capturing wait statistics for a period of time (SQLskills.com / Paul Randal), what are the most prevalent wait types in your SQL Server instance? Check SQL Server Wait Types Library (SQLSkills.com / Paul Randal) for possible solutions.

  6. Consider engaging a consultant to analyse your server/instance/environment.

There are multitude of possible causes for performance issues, but without more details, the community will not be able to provide a solution.

Good luck.

John K. N.
  • 17,649
  • 12
  • 51
  • 110