Refactoring MySQL Cursors
by Roland Bouman
My name is Roland Bouman, and I'm a certification developer for MySQL AB. This is my first post on the O'Reilly database weblog, and I figured it would be nice to start with a technical article about MySQL cursors, a subject I have written about before on my blogger weblog.
The first part of this article explains why cursors are usually unnecessary.
A few common problems with cursors are briefly discussed.
Also, typical stored procedure pattern is described that uses a cursor,
and a demonstration is given that shows how it can be refactored
to an equivalent procedure that uses a single SQL statement instead.
In the second part of this article,
the negative performance implications of using cursors are illustrated with a few benchmarks,
and the cases where a cursor might be useful after all are briefly discussed.
|Jason P Sage
Nice Article. I've always believed cursors were a bit much and that SQL itself is fairly powerful in it of itself.
|It was interesting to read|
Great article, thanks!
Hey, a minor thing - in the very last code snippet you should probably replace r.id_res with l.id_res.
|I never knew that there is something like UPDATE with JOINs, but today it just saved my life!! Greeaaat article!|