Can MySql nested SP be a bottleneck?

后端 未结 2 1949
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 02:16

We have this MySQL SP, which calls a nested SP. It seems it does NOT perform well under load.

It is possible that this SP becomes slow under load because it calls a nes

2条回答
  •  离开以前
    2021-01-23 02:40

    Yes, it's possible. We don't have measurements of how long this takes, but one can expect a temp table to cause some overhead as you create it, write data into it, query it, then drop it. How often is this being called?

    Also, MySQL's stored procedures are generally known to be pretty inefficient. They don't retain the compiled form of the procedure, as they do in Oracle and other RDBMS brands. In other words, every session recompiles each procedure it uses the first time it is called.

    First, I would suggest eliminating the temp table. Just design the nested procedure to build the right SQL query as a string, and return that string. Then the outer procedure executes the query is its result. You should be able to skip the create/drop of the temp table, and the insert into the temp table.

    Second, if I were designing this app, I don't see any need for either stored procedure. I'd recommend writing code to build the right SQL query in your application, and then just execute that query from the application.

提交回复
热议问题