Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
abhishekmadas
Starting Member
19 Posts |
Posted - 2010-06-30 : 15:44:02
|
I need to optimize the below stored procedure. any help would be appreciated. Thanks.ALTER procedure [dbo].[GetPBXTNList] @BusinessId as int, @CustomerAcctNumber as Varchar(15) as Begin Declare @SalesPersonId as varchar(10) Declare @BusinessTicker as varchar(20) Declare @SwitchType as varchar(20)Declare @BusinessProductId as int Select @SalesPersonId=CGID, @BusinessTicker=BusinessTicker,@BusinessProductId=BusinessProductId from albhm01wsoinf12.serviceprofile.dbo.tblBusiness where BusinessId=@BusinessId SELECT * FROM ((SELECT convert(varchar(10),isnull(d.EffectiveDate,''),101) "EffectiveDate", case isnull(d.DisconnectDate,'1/1/00') when '1/1/00' then '' else convert(varchar(10),d.DisconnectDate,101) End "DisconnectDate", isnull(f.AdditionalListing,'') AS ListingType, isnull(d.ServiceNumber,'') ServiceNumber, isnull(s.svcdesc,'') "svcdesc", isnull(j.Line,'') "Line", @BusinessTicker "BusinessTicker",isnull(nep.SipAuthenticationId,'') "ATAUserId",isnull(nep.RootDeviceKey,'') "MACAddress",isnull(right(servicenumber,4),'') "Extension",isnull(nep.Password,'') "DevicePassword"End "MACAddress"from core.dbo.customer c join core.dbo.usgsvc d on c.custid = d.custid left outer JOIN (select UsgSvcID, NonUsgSvcID, x.SvcTypeID, SvcDesc, x.EndDate from core.dbo.NonUsgSvc x inner join core.dbo.productcatalog y on x.SvcTypeID = y.SvcTypeID where x.EndDate is null and (x.SvcTypeId in (Select BusinessCatalogValue from albhm01wsoinf12.serviceprofile.dbo.tblBusinessCatalog where CGID=@SalesPersonId and BusinessCatalogKey='NUSC' and isnumeric(BusinessCatalogValue)=1) or vendornumber='1')) s ON s.UsgSvcID = d.UsgSvcID left outer join core.dbo.vw_UsgSvcLocalCarrier h on d.UsgSvcID = h.UsgSvcID left outer join core.dbo.usgsvcATAInformation j on d.usgsvcId=j.usgsvcId LEFT OUTER JOIN core.dbo.UsgSvcProvOrderInfo f WITH (nolock) ON d.UsgSvcID = f.UsgSvcID left outer join core.dbo.VOIPListings i on f.AdditionalListing = i.ListingDescription left outer join GAATL01WSVINS.NEProvisioning.dbo.vw_LineRegistrations nepon nep.UserId= d.name and nep.CustomerAcctNumber=c.CustomerAcctNumber where c.customeracctnumber = @CustomerAcctNumber and c.SalesId =@SalesPersonId and ISNULL(d.branch,'LINEDFLT') in (Select linetype from tblBusinessProductLineType where BusinessProductId=@BusinessProductId))union(SELECT convert(varchar(10),isnull(n.StartDate,''),101) "EffectiveDate", case isnull(n.EndDate,'1/1/00') when '1/1/00' then '' else convert(varchar(10),n.EndDate,101) End "DisconnectDate", '' AS ListingType, '' ServiceNumber, isnull(n.svcdesc,'') "svcdesc", '' "Line",@BusinessTicker "BusinessTicker",'' "ATAUserId",'' "MACAddress",'' "Extension",'' "DevicePassword"from core.dbo.customer c left outer JOIN (select CustId, NonUsgSvcID, x.SvcTypeID, SvcDesc, x.StartDate,x.EndDate from core.dbo.NonUsgSvc x inner join core.dbo.productcatalog y on x.SvcTypeID = y.SvcTypeID and y.vendornumber='1' ) n on c.CustId=n.CustId Where LEFT(c.customeracctnumber,10) = LEFT(@CustomerAcctNumber,10) and c.SalesId =@SalesPersonId AND ISNULL(SvcDesc,'')<>'') ) T order by lineEnd |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
abhishekmadas
Starting Member
19 Posts |
Posted - 2010-06-30 : 16:45:31
|
The resultset is not huge. The stored procedure returns rows between 1-100. Our DBA says we have non-clustered indexes on tables residing in Core database and update statistics and reindexing is done every week. I have attached the text from the execution plan below. Let me know if there is a better way to post them. |--Sort(DISTINCT ORDER BY:([Union1045] ASC, [Union1040] ASC, [Union1041] ASC, [Union1042] ASC, [Union1043] ASC, [Union1044] ASC, [Union1046] ASC, [Union1047] ASC, [Union1048] ASC, [Union1049] ASC, [Union1050] ASC)) |--Concatenation |--Compute Scalar(DEFINE:([Expr1017]=Convert([d].[EffectiveDate]), [Expr1018]=If (isnull([d].[DisconnectDate], 'Jan 1 2000 12:00AM')='Jan 1 2000 12:00AM') then '' else Convert([d].[DisconnectDate]), [Expr1019]=isnull([f].[AdditionalListing], ''), [d].[ServiceNumber]=[d].[ServiceNumber], [Expr1021]=isnull([y].[SvcDesc], ''), [Expr1022]=isnull([j].[Line], 0), [Expr1023]=isnull([GAATL01WSVINS].[NEProvisioning].[dbo].[vw_LineRegistrations].[SIPAuthenticationId], ''), [Expr1024]=isnull([GAATL01WSVINS].[NEProvisioning].[dbo].[vw_LineRegistrations].[rootdevicekey], ''), [Expr1025]=Convert(isnull(right([d].[ServiceNumber], 4), '')), [Expr1026]=isnull([GAATL01WSVINS].[NEProvisioning].[dbo].[vw_LineRegistrations].[Password], ''))) | |--Merge Join(Left Outer Join, MANY-TO-MANY MERGE:([d].[Name])=([GAATL01WSVINS].[NEProvisioning].[dbo].[vw_LineRegistrations].[UserId]), RESIDUAL:([GAATL01WSVINS].[NEProvisioning].[dbo].[vw_LineRegistrations].[UserId]=[d].[Name])) | |--Sort(ORDER BY:([d].[Name] ASC)) | | |--Bookmark Lookup(BOOKMARK:([Bmk1009]), OBJECT:([Core].[dbo].[UsgSvcProvOrderInfo] AS [f])) | | |--Nested Loops(Left Outer Join, OUTER REFERENCES:([d].[UsgSvcID])) | | |--Nested Loops(Left Outer Join, OUTER REFERENCES:([d].[UsgSvcID])) | | | |--Sort(ORDER BY:([d].[UsgSvcID] ASC)) | | | | |--Nested Loops(Left Outer Join, OUTER REFERENCES:([d].[UsgSvcID])) | | | | |--Nested Loops(Left Semi Join, WHERE:(isnull([d].[Branch], 'LINEDFLT')=[tblBusinessProductLineType].[LineType])) | | | | | |--Bookmark Lookup(BOOKMARK:([Bmk1001]), OBJECT:([Core].[dbo].[UsgSvc] AS [d])) | | | | | | |--Nested Loops(Inner Join, OUTER REFERENCES:([c].[CustID])) | | | | | | |--Filter(WHERE:([c].[SalesID]=Convert([@SalesPersonId]))) | | | | | | | |--Bookmark Lookup(BOOKMARK:([Bmk1000]), OBJECT:([Core].[dbo].[Customer] AS [c])) | | | | | | | |--Index Seek(OBJECT:([Core].[dbo].[Customer].[CustomerAcctNumberAK] AS [c]), SEEK:([c].[CustomerAcctNumber]=[@CustomerAcctNumber]) ORDERED FORWARD) | | | | | | |--Index Seek(OBJECT:([Core].[dbo].[UsgSvc].[UsgSvcCustIDNdx] AS [d]), SEEK:([d].[CustID]=[c].[CustID]) ORDERED FORWARD) | | | | | |--Table Scan(OBJECT:([MBS_Core].[dbo].[tblBusinessProductLineType]), WHERE:([tblBusinessProductLineType].[BusinessProductId]=[@BusinessProductId])) | | | | |--Filter(WHERE:([y].[VendorNumber]='1' OR [Expr1063])) | | | | |--Nested Loops(Left Semi Join, WHERE:([y].[VendorNumber]='1')OUTER REFERENCES:([x].[SvcTypeID]), DEFINE:([Expr1063] = [PROBE VALUE])) | | | | |--Bookmark Lookup(BOOKMARK:([Bmk1003]), OBJECT:([Core].[dbo].[ProductCatalog] AS [y])) | | | | | |--Nested Loops(Inner Join, OUTER REFERENCES:([x].[SvcTypeID])) | | | | | |--Filter(WHERE:([x].[EndDate]=NULL)) | | | | | | |--Bookmark Lookup(BOOKMARK:([Bmk1002]), OBJECT:([Core].[dbo].[NonUsgSvc] AS [x])) | | | | | | |--Index Seek(OBJECT:([Core].[dbo].[NonUsgSvc].[NonUsgSvc_UsgSvcID_IDX] AS [x]), SEEK:([x].[UsgSvcID]=[d].[UsgSvcID]) ORDERED FORWARD) | | | | | |--Index Seek(OBJECT:([Core].[dbo].[ProductCatalog].[ProductCatalogPK] AS [y]), SEEK:([y].[SvcTypeID]=[x].[SvcTypeID]) ORDERED FORWARD) | | | | |--Row Count Spool | | | | |--Filter(WHERE:(isnumeric([albhm01wsoinf12].[serviceprofile].[dbo].[tblBusinessCatalog].[BusinessCatalogValue])=1)) | | | | |--Remote Query(SOURCE:(albhm01wsoinf12), QUERY:(SELECT Tbl1013."BusinessCatalogValue" "Col1079" FROM "serviceprofile"."dbo"."tblBusinessCatalog" Tbl1013 WHERE Tbl1013."CGId"=? AND Tbl1013."BusinessCatalogKey"='NUSC' AND ?=CONVERT(int,Tbl1013."BusinessCatalogValue",0))) | | | |--Clustered Index Seek(OBJECT:([Core].[dbo].[UsgSvcATAInformation].[IX_UsgSvcATAInformation] AS [j]), SEEK:([j].[UsgSvcID]=[d].[UsgSvcID]) ORDERED FORWARD) | | |--Index Seek(OBJECT:([Core].[dbo].[UsgSvcProvOrderInfo].[UsgSvcProvOrderInfoPK] AS [f]), SEEK:([f].[UsgSvcID]=[d].[UsgSvcID]) ORDERED FORWARD) | |--Remote Query(SOURCE:(GAATL01WSVINS), QUERY:(SELECT nep."UserId" "Col1099",nep."Password" "Col1100",nep."rootdevicekey" "Col1101",nep."SIPAuthenticationId" "Col1102" FROM "NEProvisioning"."dbo"."vw_LineRegistrations" nep WHERE nep."CustomerAcctNumber"=? ORDER BY nep."UserId" ASC)) |--Compute Scalar(DEFINE:([Expr1030]=Convert(isnull([x].[StartDate], 'Jan 1 1900 12:00AM')), [Expr1031]=If (isnull([x].[EndDate], 'Jan 1 2000 12:00AM')='Jan 1 2000 12:00AM') then '' else Convert([x].[EndDate]), [Expr1032]='', [Expr1033]='', [Expr1034]=isnull([y].[SvcDesc], ''), [Expr1035]=0, [Expr1036]='', [Expr1037]='', [Expr1038]='', [Expr1039]='')) |--Filter(WHERE:(isnull([y].[SvcDesc], '')<>'')) |--Nested Loops(Left Outer Join, OUTER REFERENCES:([c].[CustID])) |--Table Scan(OBJECT:([Core].[dbo].[Customer] AS [c]), WHERE:([c].[SalesID]=Convert([@SalesPersonId]) AND substring([c].[CustomerAcctNumber], 1, 10)=substring([@CustomerAcctNumber], 1, 10))) |--Filter(WHERE:([y].[VendorNumber]='1')) |--Bookmark Lookup(BOOKMARK:([Bmk1029]), OBJECT:([Core].[dbo].[ProductCatalog] AS [y])) |--Nested Loops(Inner Join, OUTER REFERENCES:([x].[SvcTypeID])) |--Bookmark Lookup(BOOKMARK:([Bmk1028]), OBJECT:([Core].[dbo].[NonUsgSvc] AS [x])) | |--Index Seek(OBJECT:([Core].[dbo].[NonUsgSvc].[NonUsgSvc_CustID_IDX] AS [x]), SEEK:([x].[CustID]=[c].[CustID]) ORDERED FORWARD) |--Index Seek(OBJECT:([Core].[dbo].[ProductCatalog].[ProductCatalogPK] AS [y]), SEEK:([y].[SvcTypeID]=[x].[SvcTypeID]) ORDERED FORWARD) |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
abhishekmadas
Starting Member
19 Posts |
Posted - 2010-06-30 : 17:09:45
|
Core database is on SQL Server 2000 instance.Core.dbo.CustomerBillToNameNdx(Non-Unique,Non-Clusterd)BillingGroupIDNdx(Non-Unique,Non-Clusterd)CustNameNdx(Non-Unique,Non-Clusterd)CustomerAcctNumberAK(Unique,Non-Clusterd)CustomerPK(Unique,Non-Clusterd)Core.dbo.UsgSvcUsgSvc_SvcTypeID_IDX(Non-Unique,Non-Clusterd)UsgSvcCustIDNdx(Non-Unique,Non-Clusterd)UsgSvcOrderNumberNdx(Non-Unique,Non-Clusterd)UsgSvcPK(Unique,Non-Clusterd)UsgSvcServiceIDNdx(Non-Unique,Non-Clusterd)Core.dbo.NonUsgSvcNonUsgSvc_CustID_IDX(Non-Unique,Non-Clusterd)nonusgsvc_parentnonusgsvcid_idx(Non-Unique,Non-Clusterd)NonUsgSvc_SvcTypeID_idx(Non-Unique,Non-Clusterd)NonUsgSvc_UsgSvcID_IDX(Non-Unique,Non-Clusterd)NonUsgSvcPK(Unique,Non-Clusterd)Core.dbo.productcatalogProductCatalogPK(Unique,Non-Clusterd)core.dbo.usgsvcATAInformation IX_UsgSvcATAInformation(Clustered)Core.dbo.UsgSvcProvOrderInfoUsgSvcProvOrderInfoPK(Unique,Non-Clustered)SQL Server 2005 instancealbhm01wsoinf12.serviceprofile.dbo.tblBusinessCatalogPK_tblBusinessCatalog(Clustered)tblBusinessCatalog_IDX(Non-Unique,Non-Clustered) |
|
|
|
|
|
|
|