Hi there, I'm new to this forum, but I've come here quite a bit to find solutions to problems other people have encountered... I'm currently trying to query a database up to 5000 times as fast as possible to retrieve certain pricing data for a list of companies. I've run into a few queries that seem to be taking much longer then others and ultimately slow down my function call to a point where it is no longer useful. For instance... I have 2 different catalogues for different sources of data... one holds information regarding pricing, the other holds information regarding the trading volume.... the pricing query executes for all 5000 companies in less then 10 seconds, but the trading volume takes upwards of 5 minutes. There are 2 queries for each catalogue that seem to be running slow... I've tried to eliminate computational items from the queries to speed things up, but this still does not help. Here are 2 of the slow queries(as stored procedures):
I'm not an SQL guy... my forte is much more C++/C#, so please keep that in mind if you have a solution or any ideas to help speed things up.
The tables have upwards of 100,000 entries each and in some cases more then 300 columns. Would doing a subquery for the columns I need and then filtering the results speed things up?
Thanks! - Will
Code:
ALTER PROCEDURE dbo.GetQuarterlyEPS ( @Gvkey int, @StartDate smalldatetime, @EndDate smalldatetime ) AS SELECT gvkey, datadate, epspxq FROM co_ifndq WHERE (gvkey = @Gvkey) AND consol = 'C' AND datadate <= @StartDate AND datadate > @EndDate ORDER BY datadate DESC RETURN ALTER PROCEDURE dbo.GetMeanEstimate ( @ibtic nchar(3), @StartFirstDate smalldatetime, @EndFirstDate smalldatetime, @StartSecondDate smalldatetime, @EndSecondDate smalldatetime ) AS SELECT IBESStatisticalPeriod, MeanEstimate FROM USSummaryStatisticsAdjusted WHERE IBESTicker = @ibtic AND ( (IBESStatisticalPeriod <= @StartFirstDate AND IBESStatisticalPeriod > @EndFirstDate) OR (IBESStatisticalPeriod <= @StartSecondDate AND IBESStatisticalPeriod > @EndSecondDate) ) AND ForecastPeriodIndicator = 1 ORDER BY IBESStatisticalPeriod DESC RETURN
The tables have upwards of 100,000 entries each and in some cases more then 300 columns. Would doing a subquery for the columns I need and then filtering the results speed things up?
Thanks! - Will
Comment