From 51f2897a33baaeeeebb77ffe7cf1c3d4f3736d53 Mon Sep 17 00:00:00 2001 From: mschill Date: Thu, 16 Jul 2026 08:26:07 -0400 Subject: [PATCH] =?UTF-8?q?C2026-044=20=E2=80=93=20ve=5FGetParentItem=20Pe?= =?UTF-8?q?rformance=20Improvement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PROMS/VEPROMS User Interface/PROMSFixes.Sql | 33 ++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/PROMS/VEPROMS User Interface/PROMSFixes.Sql b/PROMS/VEPROMS User Interface/PROMSFixes.Sql index 5209a3a7..035bf245 100644 --- a/PROMS/VEPROMS User Interface/PROMSFixes.Sql +++ b/PROMS/VEPROMS User Interface/PROMSFixes.Sql @@ -5547,6 +5547,12 @@ ELSE PRINT 'Function: ve_GetItemDerivedApplicability Error on Creation' GO ------- + +-- ============================================= +-- Author: Matthew Schill +-- Modify date: 07/14/2026 +-- Description: Reworked ve_GetParentItem for Performance improvement +-- ============================================= /****** Object: UserDefinedFunction [dbo].[vefn_GetParentItem] Script Date: 03/28/2012 17:58:48 ******/ IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[ve_GetParentItem]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) DROP FUNCTION [ve_GetParentItem]; @@ -5555,29 +5561,28 @@ GO Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE Copyright 2012 - Volian Enterprises, Inc. All rights reserved. *****************************************************************************/ -CREATE FUNCTION [dbo].[ve_GetParentItem] (@ItemID int) RETURNS int +CREATE OR ALTER FUNCTION [dbo].[ve_GetParentItem4] (@ItemID int) RETURNS int WITH EXECUTE AS OWNER AS BEGIN DECLARE @ParentID int; -WITH Itemz([ItemID],[IsFound]) as +WITH Itemz([ItemID]) as ( -select ii.itemid,0 from items ii where ii.itemid = @ItemID +select ii.itemid from items ii WITH (NOLOCK) where ii.itemid = @ItemID union all -select ii.previousid,0 from items ii +select ii.previousid from items ii WITH (NOLOCK) join itemz zz on ii.itemid = zz.itemid where ii.previousid is not null -and zz.isfound = 0 -union all -select ii.itemid,1 -from parts pp -join itemz zz on pp.itemid = zz.itemid -join items ii on ii.contentid = pp.contentid ) -select top 1 @ParentID = itemid from itemz -where isfound = 1 OPTION (MAXRECURSION 10000) +select top 1 @ParentID = ii.itemid +from itemz +inner join parts pp WITH (NOLOCK) on pp.itemid = itemz.itemid +inner join items ii WITH (NOLOCK) on ii.contentid = pp.contentid +OPTION (MAXRECURSION 10000) + RETURN @ParentID END + GO IF (@@Error = 0) PRINT 'ScalerFunction [vefn_GetParentItem] Succeeded' @@ -25051,8 +25056,8 @@ BEGIN TRY -- Try Block DECLARE @RevDate varchar(255) DECLARE @RevDescription varchar(255) - set @RevDate = '06/29/2026 7:00 AM' - set @RevDescription = 'Update to Grid Deletion Audits' + set @RevDate = '07/16/2026 8:30 AM' + set @RevDescription = 'Reworked ve_GetParentItem for Performance improvement' Select cast(@RevDate as datetime) RevDate, @RevDescription RevDescription PRINT 'SQL Code Revision ' + @RevDate + ' - ' + @RevDescription