MySQL UPDATE and SELECT in one pass

后端 未结 6 1381
轮回少年
轮回少年 2020-11-28 14:05

I have a MySQL table of tasks to perform, each row having parameters for a single task.
There are many worker apps (possibly on different machines), performing tasks in

6条回答
  •  盖世英雄少女心
    2020-11-28 15:10

    If you are looking for a single query then it can't happen. The UPDATE function specifically returns just the number of items that were updated. Similarly, the SELECT function doesn't alter a table, only return values.

    Using a procedure will indeed turn it into a single function and it can be handy if locking is a concern for you. If your biggest concern is network traffic (ie: passing too many queries) then use the procedure. If you concern is server overload (ie: the DB is working too hard) then the extra overhead of a procedure could make things worse.

提交回复
热议问题