How/when mysql compiles stored procedures?

前端 未结 2 1429
时光说笑
时光说笑 2021-01-12 18:01

We intend to use mysql stored procedures for handling all database work for one project. There are several applications(different languages) using same database and I am fai

相关标签:
2条回答
  • 2021-01-12 18:46

    No. Query and stored procedures are compiled on demand and then kept in a cache for a while. If you use a specific stored procedure repeatedly the version compiled in the cache will be used, but if it is no longer in cache it must be compiled first, just like any other query you send to a database.

    What MySQL certainly will not do is compile all x-hundred stored procedures at once - in case that was what you were afraid of.

    But all this is somewhat irrelevant The advantage of stored procedures is that you can make sure that multiple applications using the same database, use it in the same way. When your performance is such that you start looking at the compilation cache for speed, you are looking at the wrong place. Speed optimization is better done through either query or database redesign.

    0 讨论(0)
  • 2021-01-12 18:54

    MySQL will not compile all stored procedures at once. They will be executed on demand like queries as per requirement and when you call them.

    With a stored procedure, however, the database compiles the query plan once and reuses the compiled process. This pre-compilation can yield a significant performance advantage.

    0 讨论(0)
提交回复
热议问题