Aquila
04-15-2004, 12:42 PM
Hello,
Im having a large performance problem and I need to rewrite a very important part of my front end.
Heres my problem.
I pull a set of data... say the top 50 records of a 500,000 record table. once the user scrolls through that top 50 via a listview control it re-polls the database to get the NEXT 50 records... (should the user decide then to go back UP the program queiries again for the 50 records before the current 50)
What I do when I have these chunks of data is just completley reload the list view and highlight the first or last record (Depending on what direction the user is "Scrolling"
THe problem is the dataset has to be sorted by whatever criteria the user has selected... SO.. what I do is simple (Yet horribly slow)
I do the query based on the sort, then I put that data into a temp table so I can have the id of the record. so I can mathmaticly sort through that.
I.E. if I had a table with 10 records numbered 1..10 but sorted on say last name It could not go in numerical order.
tblData
UserID | Name | LName
-----------------------
1 | John | Williams
2 | Jessica | Bryan
3 | Bethany | Jackson
etc etc
So the sort could be... by last name the ID's would be in 2,3,1 or by first name 3,2,1 or by ID 1,2,3 or whatever.
So what my temp table does is provide me a reference point that I can say..
Give me the top 20 records where the TEMPTable ID is less than... whatever. and that gives me the results.
But like I said it is horribly horribly slow as every time it does this it has to sort a 500,000 record table.. put it in the temp table (Even though I only use a created identy column and the PK identity from the source table) and THEN pull the data for ID whatever to whatever.
Is there a simpler way and MUCH MUCH more efficient way to do this? I tried throwing ram at the SQL server (It now has 4 gigs in it) but that didnt even seem to help in the least.
I'm pretty desperate here.
Im having a large performance problem and I need to rewrite a very important part of my front end.
Heres my problem.
I pull a set of data... say the top 50 records of a 500,000 record table. once the user scrolls through that top 50 via a listview control it re-polls the database to get the NEXT 50 records... (should the user decide then to go back UP the program queiries again for the 50 records before the current 50)
What I do when I have these chunks of data is just completley reload the list view and highlight the first or last record (Depending on what direction the user is "Scrolling"
THe problem is the dataset has to be sorted by whatever criteria the user has selected... SO.. what I do is simple (Yet horribly slow)
I do the query based on the sort, then I put that data into a temp table so I can have the id of the record. so I can mathmaticly sort through that.
I.E. if I had a table with 10 records numbered 1..10 but sorted on say last name It could not go in numerical order.
tblData
UserID | Name | LName
-----------------------
1 | John | Williams
2 | Jessica | Bryan
3 | Bethany | Jackson
etc etc
So the sort could be... by last name the ID's would be in 2,3,1 or by first name 3,2,1 or by ID 1,2,3 or whatever.
So what my temp table does is provide me a reference point that I can say..
Give me the top 20 records where the TEMPTable ID is less than... whatever. and that gives me the results.
But like I said it is horribly horribly slow as every time it does this it has to sort a 500,000 record table.. put it in the temp table (Even though I only use a created identy column and the PK identity from the source table) and THEN pull the data for ID whatever to whatever.
Is there a simpler way and MUCH MUCH more efficient way to do this? I tried throwing ram at the SQL server (It now has 4 gigs in it) but that didnt even seem to help in the least.
I'm pretty desperate here.