Click here to Skip to main content
15,914,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In following query ROW_NUMBER() function causes long delay when records are more than 35000. Here Row number function is used to get sequence number like 1,2,3,4 and so on as first column in listctrl with checkbox. Please let me know how can I do other way down to reduce delay.As issue is at client side ,it needs to fixed as early as possible.


SQL
SELECT R.ReadNo,ROW_NUMBER() OVER (ORDER BY R.ResultID_PK) AS Number,CONVERT(VARCHAR(20),R.ReadTime,113) AS ResultDate,TS.SampleID,ISNULL(P.FirstName + ' ' + P.LastName,'') AS Name,ISNULL(P.PatientID,'') AS PatientID,T.TestCode,TP.PlateNo,R.Result AS RESULT,ISNULL([DBEIAQUANT].[dbo].[GetUnit] (U.Unit,R.TestTypeRun),'') AS Unit,R.Flag,TR.FinalOD,ISNULL([DBEIAQUANT].[dbo].[GetCOV] (R.CutOff,T.TestType),'') AS CutOff,R.ReCalcResult AS RecalResult,R.ReCalcFlag AS RecalFlag,ISNULL(TS.PatientID,0) AS PatientID FROM TblResults R
INNER JOIN TblPlateMaster TP ON (TP.PlateID_PK = R.PlateID)
 INNER JOIN TblSchedule S ON (S.ScheduleID_PK = R.ScheduleID)
 INNER JOIN TblSample TS ON (TS.SampleID_PK = S.SampleID AND TS.Status = '1')
  INNER JOIN TblTestMaster T ON (T.TestCode_PK = R.TestCode)
   INNER JOIN TblReadings TR ON (TR.ReadNo_PK = R.ReadNo)
   LEFT OUTER JOIN TblUnitMaster U ON (U.UID_PK = R.Unit)
    LEFT OUTER JOIN TblPatient P ON (P.PatientId_PK = TS.PatientID) WHERE R.ReadTime
    BETWEEN '2014-04-28 00:00:00' AND '2015-11-14 23:59:59'
Posted
Comments
Patrice T 14-Nov-15 1:18am    
Why do you need ROW_NUMBER() at all ?
adityarao31 14-Nov-15 1:33am    
We fill listctrl through query with custom function FillListCtrl which is common function throughout application. For a particular list ctrl I cannot use separate function.
adityarao31 14-Nov-15 3:04am    
I got hint from your question ,its true I dont need ROW_NUMBER in first place I feel customising my function is only fastest solution
George Jonsson 14-Nov-15 1:45am    
If you describe more in detail how you use the row number and what kind of control you are using on the client side, maybe someone can come up with an alternative solution.
Maybe this is a stupid question, but why don't you generate the row number on the client side in the control used to present the data?
Maciej Los 14-Nov-15 1:48am    
You have to fetch less portion of data. It's called: pagination.

Please, read all comments to the question.

There's tons of articles about query performance. Follow this link[^].
 
Share this answer
 
When you have a performance issue, there is only 1 question: "What do I really need to do ?"
And the answer is usually to simplify the request by removing all what is not needed.
Another approach is to see if one can change the request to make it simpler and faster to the server.

Sometime it is the database that is not organized in the optimum way.

As per your comment, I see my question was useful.

links of solution 1 are certainly interesting.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900