seek() slowness


Author
Message
Keith Chisarik
Keith Chisarik
StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
I have some code that loops through about 1/4 of a million records, it is taking a very long time (I stopped it after 15 minutes and it wasn't close to done).



I took out all the processing in the loop so that all it was doing was the loop with a single seek() and it was still slow. I replaced the seek() with "if 1 =2 then" and it went as expected (about 20 seconds).



I am seek()ing against a single integer field that I have an index on in SQL. Help????



Code:

searchstr = "rent_RPMrecnum = " & "'" & currow("record_number") & "'"

'If Me.RentitemsBO1.Seek(searchstr) Then

‘do nothing

Else

‘still do nothing for testing purposes

End if





Thanks.










Keith Chisarik
Replies
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
By "set based" I'm referring to the way SQL does things the most efficiently. It works best on sets of records, not on individual records (or rows). Looping through the BO (in SQL Server, cursors) is row based. Row based manipulation provide lots of power as to what can get done, but is not as fast (generally) as using SQL to manipulate a whole set at once (that is not as fast for SQL server to get the work done. Languages like .NET are more efficient at row based manipulation. Which is fastest would probably depend on all sorts of variables, like efficiency of code, hardward, connectivity, ect.).



Set based manipulation is great if you have something you want to do to the data based on some criterion. E.g. lets say you have a database containing a table of movie rentals. You want to mark all rentals more than a year old as needing maintenance (like polishing the DVDs). It is more efficient to use an update statement than to loop through the rows:



Update rentals -- table with rentals

Set MaintenanceStatus = 1 -- lets say this means it need maintenance

Where PurchaseDate <= DateAdd(year,-1,GetDate()) -- gets date one year ago




Since this sort of thing only needs to be done infrequently, the user doesn't actually need to see the data to get the job done, a SQL statement is the way to go. You could create a sproc (for max speed, as it would be precompiled in SQL) or you could just create a method in a BO.



However, there are times when this won't work too well. If what you need to do is complicated or not data related or the data is in another database or the user needs to see all the data to decide what to do (the data would thus be on the client anyway), then row level processing is needed. It turns out that it isn't actually needed very often though.



I hope this helps. I come from MS Access background, not a VFP, so I had to learn a lot about SQL Server as I had it doing lots of work to speed up things. Sounds like VFP was speedy (always heard that, but I wasn't allowed to use it when I started doing db development...long story). The whole disconnected data thing in .net is different and I'm still getting used to it. It may be that this world view is now inaccurate or not as accurate, as it might be more efficient to use a loop in .net than in SQL server. I'm watching this post, hoping to learn a lot also Hehe

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Man, if I'd just waited a few minutes, I would have see what Trent posted....Blink



Seems I not as much a dinosaur as I thought w00t
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Keith Chisarik - 19 Years Ago
Greg McGuffey - 19 Years Ago
Keith Chisarik - 19 Years Ago
StrataFrame Team - 19 Years Ago
Keith Chisarik - 19 Years Ago
Keith Chisarik - 19 Years Ago
StrataFrame Team - 19 Years Ago
StrataFrame Team - 19 Years Ago
Keith Chisarik - 19 Years Ago
Keith Chisarik - 19 Years Ago
Keith Chisarik - 19 Years Ago
Keith Chisarik - 19 Years Ago
Trent L. Taylor - 19 Years Ago
Ben Hayat - 19 Years Ago
Greg McGuffey - 19 Years Ago
Greg McGuffey - 19 Years Ago
Keith Chisarik - 19 Years Ago
Ben Hayat - 19 Years Ago
Keith Chisarik - 19 Years Ago
Keith Chisarik - 19 Years Ago
Trent L. Taylor - 19 Years Ago
Greg McGuffey - 19 Years Ago
                     I did! With FORTRAN. :crazy:
Ivan George Borges - 19 Years Ago
                         [quote]I did!

With FORTRAN. [Crazy] [/quote]

IBM...
Ben Hayat - 19 Years Ago
                             What's a punch card? :D
StrataFrame Team - 19 Years Ago
                                 1983 - Keith was 10, Trent was 7, Ben was 2 -- ok I am a little older...
Steve L. Taylor - 19 Years Ago
                                     [quote][b]Steve L. Taylor (04/03/2007)[/b][hr]1983 - Keith was 10,...
Ivan George Borges - 19 Years Ago
                                     [quote][b]Steve L. Taylor (04/03/2007)[/b][hr]1983 - Keith was 10,...
Ben Hayat - 19 Years Ago
                             [quote][b]Ben Hayat (04/03/2007)[/b][hr][quote]I did! With FORTRAN....
Ivan George Borges - 19 Years Ago
                                 [quote][b]Ivan George Borges (04/03/2007)[/b][hr][quote][b]Ben Hayat...
Ben Hayat - 19 Years Ago
                                     OK, back to business... Keith, if you change the column that is the...
StrataFrame Team - 19 Years Ago
                                         I'm going to throw out another approach. Is it possible to just...
Greg McGuffey - 19 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search