Cursors on MySQL - Good or Bad

送分小仙女□ 提交于 2019-12-03 04:23:42

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.

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

d-live

Cursors by nature are Iterative - they are definitely going to be slower irrespective of any database type. You should therefore do whatever to avoid them and try to find solutions using SQL queries. They are however there for problems which cannot be solved with queries - so use them only when absolutely necessary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!