Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cursors on MySQL - Good or Bad [closed]

I have always heard people saying bad about using cursors and this is especially in Microsoft SQL Server as they are very slow.

Is this the case with Cursors on MySQL as well? Does cursors in MySQL reduce performance as well? Can someone please advice on the usage of cursors in MySQL?

like image 398
Abishek Avatar asked Aug 09 '11 15:08

Abishek


2 Answers

Most modern databases (including MySQL) are designed to perform set based operations. The problem with cursors is that they perform row based (or procedural) operations. Because of this you will almost always see a performance hits when you are using cursors to do a job that can be done without cursors on a modern DBMS.

Take a look at this article, which does a decent job going over the two. It is written with SQL Server in mind but most of the concepts apply.

like image 158
Abe Miessler Avatar answered Sep 30 '22 12:09

Abe Miessler


Just create and fill a temporary table. That is how most RDBMS's implement cursors anyway.

like image 25
Ruud H.G. van Tol Avatar answered Sep 30 '22 13:09

Ruud H.G. van Tol