Blog Post

Cursors and high gas prices

,

Using cursors is a controversal topic. As a former developer, that is the way I thought about processing data at one time. I gave a talk to a VB group a couple of years ago where I compared using cursors, correlated subqueries, etc., to other techniques to show the performance differences. A lively discussion ensued as the audience members were shocked that the ways they were updating and retrieving data might not be the best. 

I recently came up with an analogy to explain why processing one row at a time is generally a bad idea. Suppose you have a 10 item grocery list. What are the steps to get the groceries to your pantry? If we process one item at a time, it will look something like this:

 

for each item in list
    walk to the car
    get in the car
    start the car
    drive to the store
    stop the car
    walk into store
    locate food package that matches item
    retrieve food package from store shelf
    cross off list
    pay for package
    leave store
    walk to the car
    get in car
    start car
    drive home
    stop car
    get out of the car
    walk in house with package
    put package away
next item

With the high gasoline prices, you can see why this might not be a good idea.  


 
 
 

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating