Hi,
i created a view and called this in stored procedure. Current execution time is 2 Seconds.Now i need to reduce the execution time from 2 sec to 1/2 sec. i need to get only top 25 latest orders.
Distinct and Order By causing Issues.
I Created non-clustered index for Order Id but no use.
Please help me to improve performance
Regards,
Ramakrishna
What I have tried:
View:
SELECT RO.GenerateId, RO.CompanyId, RO.DeliveryDate, RO.DeliveryTime, RO.UserId, RO.Name, APD.AppName, L.LocationName, RO.CreatedDate, RO.ItemState,
CONVERT(varchar, RO.TotalPrice, 1) AS TotalPrice, CONVERT(varchar, RO.DeliveryFee, 1) AS DeliveryFee, RO.LocationId, CONVERT(varchar, RO.Tax, 1)
AS Tax, CONVERT(varchar, RO.Tip, 1) AS Tip, RO.EntityType, RO.PromotionCode, RO.PromotionType, RO.TotalWeight, RO.ItemWeight, CONVERT(varchar,
RO.ConvenienceFeePercentage, 1) AS ConvenienceFee, RO.ConvenienceFee AS ConvenienceFeePercentage, RO.PromotionDiscount, RO.PhoneNumber,
RO.PaymentType, RO.Note, A.Line1, A.Line2, A.City, A.State, A.Country, A.Zip, RI.CommissionPercentage, RO.Commission, RI.Currency, OCS.AssignedTo,
RO.GroupId, RO.OrderType, UL.UserId AS UALUserId, RO.ZoneId, OCS.ClaimedBy
FROM dbo.Locations AS L INNER JOIN
dbo.Address AS A ON L.AddressId = A.Id INNER JOIN
dbo.UserAccessLocations AS UL ON L.LocationId = UL.LocationId INNER JOIN
dbo.AppDetails AS APD ON L.AppId = APD.AppId INNER JOIN
dbo.RestaurantAppInfo AS RI ON L.AppId = RI.AppId AND
L.LocationId = RI.LocationId INNER JOIN
dbo.OrderClaimStatus AS OCS INNER JOIN
dbo.RestaurantOrders AS RO ON OCS.OrderId = RO.GenerateId
ON L.LocationId = RO.LocationId AND UL.LocationId = RO.LocationId
WHERE (OCS.OrderType IS NULL) AND (RO.DeliveryDate >= DATEADD(day, - 30, GETDATE())) AND (RO.OrderStatus = '1') AND (RO.ItemState <> 'Order Canceled')
stored procedure:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER proc [dbo].[GetAllOrders]
as
begin
SET NOCOUNT ON;
select distinct top 25 GenerateId,CompanyId,DeliveryDate,DeliveryTime,UserId,Name,AppName,LocationName,CreatedDate,ItemState,TotalPrice,DeliveryFee,LocationId,Tax,Tip,EntityType,PromotionCode,PromotionType,null as ItemWeight,TotalWeight,
ConvenienceFee,ConvenienceFeePercentage,PromotionDiscount,PhoneNumber,
PaymentType,Note,Line1,Line2,City,State,Country,Zip,CommissionPercentage,Commission,Currency,AssignedTo,GroupId,OrderType
from vwOrdersforManageUsers Order By GenerateId desc
end