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
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;
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.