Can MySql nested SP be a bottleneck?

牧云@^-^@ 提交于 2019-12-02 02:11:46

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.

Maxim Eliseev

It seems nested SPs was NOT the main bottleneck.

I've changed temp tables to MEMORY engine and it really did the trick and made AMAZING difference. Solution was suggested in

https://dba.stackexchange.com/questions/52825/can-mysql-nested-sp-be-a-bottleneck/52863?noredirect=1#52863

create temporary table areas (
    id int not null,
    code varchar(30),
    name varchar(100),
    shortName varchar(100),
    levelid int not null,
    sortOrder int not null,
    key (id)
) ENGINE=MEMORY;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!