Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Stored Procedure vs. complex query

Tags:

How is the performance of a Stored Procedure? Is it worth using them instead of implementing a complex query in a PHP/MySQL call?

like image 892
Arsham Avatar asked Jul 20 '09 00:07

Arsham


People also ask

Which is better stored procedure or query?

where as stored procedure is compiled when it is submitted for the first time & this compiled content is stored in something called procedure cache,for subsequent calls no compilation,just execution & hence better performance than query.

Is stored procedure faster than query in MySQL?

In MySQL or any other SQL server as MSSQL or Oracle, stored procedures increase dramatically the speed of the queries involved because this are already compiled.

Which is faster SQL query or stored procedure?

Stored procedures are precompiled and optimised, which means that the query engine can execute them more rapidly. By contrast, queries in code must be parsed, compiled, and optimised at runtime.

Why we use stored procedure instead of query?

A stored procedure is invoked as a function call instead of a SQL query. Stored procedures can have parameters for both passing values into the procedure and returning values from the call. Results can be returned as a result set, or as an OUT parameter cursor.


1 Answers

Stored procedures will give you a small performance boost, but mostly they are for doing tasks that are difficult or impossible to do with a simple query. Stored procedures are great for simplifying access to data for many different types of clients. Database administrators love them because they control how the database is used as opposed to leaving those details to the developer.

Look to indexes and proper table design to get better performance.

like image 154
Robert Casto Avatar answered Oct 08 '22 01:10

Robert Casto