I made a very simple procedure (a while loop) in MySQL:
BEGIN
DECLARE start INT;
DECLARE ending INT;
SET start = 1;
SET ending = 4000000;
WHILE (start <= ending) DO
SET start = start + 1;
END WHILE;
END
This takes ~26 seconds on a dual core machine (each core on 100%) and I don't understand why.
Could you give me an answer?
Yes, Stored Procedures are very slow compared to other programming languages like C# or Java. Computational wise that is. The same code would be slow in SQL Server aswell. Probably faster than MySQL, but you'd still be waiting a few seconds untill it's fully executed. You'll be better of by doing that in a programming language, which completes such a task in under a second.
So with other words:
Slow stored procedure performance is one of the reasons why it usually isn’t wise to implement computationally expensive business logic in the database. With networks not being the bottleneck they once were it is often better to extract the data to the application layer and process it in the programming language of your choice, even if that takes a few extra round trips to the database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With