A couple days ago, a colleage brought our SQL Server to it's knees using a the RMV_Installed_File_Inventory view. He just wanted to look at some file versions and paths, so wrote something rather innocent looking,
SELECT vc.Name
,vif.[File Name]
,vif.[File Version]
,vif.[Path]
FROM [RMV_Installed_File_Inventory] vif
JOIN vComputer vc
ON vc.Guid = vif._ResourceGuid
WHERE LOWER(vif.[File Name]) IN ('oracleadnettest.exe')
ORDEAA BY vc.Name
All he wanted to do was to see where a specific executable 'oracleadnettest.exe' was located and what its version was. Once he'd realised the Altiris Console report window had gotten sulky, he gave me a call.
I was rather surprised to find that the SQL Server was hitting 99% CPU and it didn't give any indication of finishing any time soon. As it was already late afternoon, I decided to let it be and look at it again the next day when things were better.
So, the next day I went in the SQL Server, and went into SQL Server management studio. I thought that before I'd try anything fancy, I'd just do a simple row count. As I couldn't believe what happened next, I took a screenshot....
Image may be NSFW.
Clik here to view.
On the face of it it doesn't seem so bad. The view returned got just under 5million rows. Notice however the execution time. I didn't take this screenshot a few minutes after executing the query. I took it the next day when it completed. This query took a whopping 1 day, 1 hour and 28 minutes to execute.
So... anyone else seeing this?
For posterity, here is the revsion I made to the original console report query to avoid this view,
SELECT
vc.Name,
Inv_Installed_File_Details.Path AS [ Name],
Inv_Windows_File.ProductVersion AS [Version]
FROM dbo.vComputer vc
JOIN Inv_Installed_File_Details ON vc.Guid = Inv_Installed_File_Details._ResourceGuid
JOIN Inv_Windows_File ON Inv_Installed_File_Details.FileResourceGuid = Inv_Windows_File._ResourceGuid
WHERE Inv_Installed_File_Details.Name = N'oracleadnettest.exe'
ORDER BY vc.Name
And below is the T-SQL for the RMV_Installed_File_Inventory view which seems to be misbehaving.....
[dbo].[RMV_Installed_File_Inventory]
CREATE VIEW [dbo].[RMV_Installed_File_Inventory] AS SELECT DISTINCT iifd._ResourceGuid, ISNULL (ISNULL (sc.[Name],wf.ProductName), sp.Name) [Product Name], ISNULL (ISNULL (ap.Publisher,wf.Manufacturer), vc.Name) [Manufacturer], ISNULL (isc.Version,wf.ProductVersion) [Product Version], ISNULL (wf.FileVersionString,'') [File Version], f.[Name] [File Name], ISNULL (CAST (CAST (ifd.FileSize / (1024.0 * 1024.0) AS DECIMAL (10,2)) AS NVARCHAR (MAX)),'') [File Size (MB)], f.ModifiedDate [Modification Date], iifd.Path [Path], wf.InternalName [Internal name], CASE WHEN ISNULL (CAST (iifd.VirtualSoftwareGuid AS NVARCHAR (MAX)),'00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000' THEN 'N' ELSE 'Y' END [Virtualized (Y/N)], wf.Description [File Description], ifd.FileExtension [File Extension] FROM dbo.Inv_Installed_File_Details iifd LEFT JOIN (dbo.ResourceAssociation ra JOIN dbo.vSoftwareComponent sc ON sc.Guid = ra.ParentResourceGuid AND ra.ResourceAssociationTypeGuid = 'EABE86D3-AAFD-487A-AF63-5C95D7511AF6' LEFT JOIN (dbo.ResourceAssociation ra2 JOIN dbo.vSoftwareProduct sp ON sp.Guid = ra2.ParentResourceGuid AND ra2.ResourceAssociationTypeGuid = '9D67B0C6-BEFF-4FCD-86C1-4A40028FE483') ON ra2.ChildResourceGuid = ra.ParentResourceGuid LEFT JOIN (dbo.ResourceAssociation ra1 JOIN dbo.vCompany vc ON vc._ResourceGuid = ra1.ChildResourceGuid) ON (ra1.ParentResourceGuid = ra.ParentResourceGuid AND ra1.ResourceAssociationTypeGuid = '292DBD81-1526-423A-AE6D-F44EB46C5B16') OR (ra1.ParentResourceGuid = ra2.ParentResourceGuid AND ra1.ResourceAssociationTypeGuid = 'D5C66D5A-7686-4CA2-B7C1-AC980576CE1D')) ON ra.ChildResourceGuid = iifd.FileResourceGuid LEFT JOIN dbo.Inv_AddRemoveProgram ap On ap._SoftwareComponentGuid = sc.Guid AND ap.InstallFlag = 1 LEFT JOIN vWindowsFile wf ON wf.Guid = iifd.FileResourceGuid LEFT JOIN dbo.Inv_Software_Component isc ON isc._ResourceGuid = sc.Guid LEFT JOIN dbo.vFile f ON f.Guid = iifd.FileResourceGuid LEFT JOIN dbo.Inv_File_Details ifd ON ifd._ResourceGuid = f.Guid