且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

由于SQL查询执行时间过长,我在浏览器上遇到了超时错误

更新时间:2022-10-26 09:16:10

和?您对我们的期望是什么? :笑:



从SQL开始并描述查询:如何:使用SQL事件探查器 [ ^ ]

这将为您提供一堆信息,以便查看并查找查询速度慢的地方 - 然后您可以重新组织数据或重新处理查询以改进速度。



我们不能这样做:我们无法访问您的数据,因此如果我们想要的话,我们甚至无法运行查询!

my query is taking long time to execute due to this facing error timed out on browser

here is my query

What I have tried:

SELECT DISTINCT
View_DistributorRetailerDetailLedger.CompanyName AS SellerName, ISNULL(SumOfContributionAmountBuyerWiseNF.NetworkFamilyAmount, 0)
+ ISNULL(SumOfContAmntManuallyWinnerBuyerWiseNetwork.ScehemAmount, 0) AS NetworkFamilyAmount,
ISNULL(SumOfContributionAmountBuyerWiseShopkeeper.ShopkeeperAmount, 0) + ISNULL(SumOfContAmntManuallyWinnerByerWiseShopkeeper.ScehemAmount, 0)
AS ShopkeeperAmount, Config_SchemeName_1.Name as SchemeName
FROM SumOfContributionAmountBuyerWiseShopkeeper INNER JOIN
SchemeSetup ON SchemeSetup.AmountTarget * 1000000 <= SumOfContributionAmountBuyerWiseShopkeeper.BusinessAmount INNER JOIN
Config_LedgerDuration ON SumOfContributionAmountBuyerWiseShopkeeper.LedgerDurationID = Config_LedgerDuration.LedgerDurationID AND
SchemeSetup.StartDate = Config_LedgerDuration.StartDate AND SchemeSetup.EndDate = Config_LedgerDuration.EndDate INNER JOIN
Config_SchemeName AS Config_SchemeName_1 ON SchemeSetup.SchemeNameID = Config_SchemeName_1.ID RIGHT OUTER JOIN
Invoices ON SumOfContributionAmountBuyerWiseShopkeeper.SellerID = Invoices.SellerID AND
SumOfContributionAmountBuyerWiseShopkeeper.SellerTypeID = Invoices.SellerTypeID RIGHT OUTER JOIN
View_DistributorRetailerDetailLedger LEFT OUTER JOIN
SumOfContAmntManuallyWinnerBuyerWiseNetwork RIGHT OUTER JOIN
Invoices AS Invoices_1 LEFT OUTER JOIN
Config_LedgerDuration AS Config_LedgerDuration_1 INNER JOIN
SchemeSetup AS SchemeSetup_1 INNER JOIN
SumOfContributionAmountBuyerWiseNF ON SchemeSetup_1.AmountTarget * 1000000 <= SumOfContributionAmountBuyerWiseNF.BusinessAmount ON
Config_LedgerDuration_1.StartDate = SchemeSetup_1.StartDate AND Config_LedgerDuration_1.EndDate = SchemeSetup_1.EndDate ON
Invoices_1.SellerID = SumOfContributionAmountBuyerWiseNF.SellerID AND Invoices_1.SellerTypeID = SumOfContributionAmountBuyerWiseNF.SellerTypeID ON
SumOfContAmntManuallyWinnerBuyerWiseNetwork.SellerID = SumOfContributionAmountBuyerWiseNF.SellerID AND
SumOfContAmntManuallyWinnerBuyerWiseNetwork.SellerTypeID = SumOfContributionAmountBuyerWiseNF.SellerTypeID ON
View_DistributorRetailerDetailLedger.ID = SumOfContributionAmountBuyerWiseNF.SellerID AND
View_DistributorRetailerDetailLedger.TypeID = SumOfContributionAmountBuyerWiseNF.SellerTypeID ON
SumOfContributionAmountBuyerWiseShopkeeper.SellerID = View_DistributorRetailerDetailLedger.ID AND
SumOfContributionAmountBuyerWiseShopkeeper.SellerTypeID = View_DistributorRetailerDetailLedger.TypeID LEFT OUTER JOIN
SumOfContAmntManuallyWinnerByerWiseShopkeeper ON
SumOfContributionAmountBuyerWiseShopkeeper.SellerID = SumOfContAmntManuallyWinnerByerWiseShopkeeper.SellerID AND
SumOfContributionAmountBuyerWiseShopkeeper.SellerTypeID = SumOfContAmntManuallyWinnerByerWiseShopkeeper.SellerTypeID
WHERE (SchemeSetup.SchemeNameID =@SchemeID) AND (View_DistributorRetailerDetailLedger.ID <> 138)

And? What do you expect us to do about it? :laugh:

Start with SQL and profile the query: How To: Use SQL Profiler[^]
This will give you a heap of information to look though and work out where your query is slow - you can then work on either reorganising your data or reworking the query to improve the speed.

We can't do that: we don't have any access to your data, so we couldn't even run the query if we wanted to!