Bug #24720 Allow recursive stored functions
Submitted: 30 Nov 2006 10:25 Modified: 22 Dec 2006 12:49
Reporter: Maciej Pilichowski Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S4 (Feature request)
Version:5.0.26 OS:Linux (opensuse 10.0)
Assigned to: CPU Architecture:Any
Triage: D5 (Feature request)

[30 Nov 2006 10:25] Maciej Pilichowski
Description:
I have read in a pretty decent book (about MySQL) about recurrent functions. Pretty obvious for me, so it was a bit of surprise that I am using much newer version of the MySQL than the author of the book and I cannot use recursion.

How to repeat:
Just run any function with recursion.

Suggested fix:
Please, allow functions to use recursion.
[1 Dec 2006 15:17] Valeriy Kravchuk
Thank you for a problem report. Please, read the manual, http://dev.mysql.com/doc/refman/5.0/en/stored-procedures.html (about max_sp_recusion_depth). This is documented behaviour.
[1 Dec 2006 15:39] Maciej Pilichowski
I set it for the feature request, so I would like to see this feature implemented again -- I am not saying it is a bug ;-). Here is verbatim quote from the help you mentioned:

"recursive statements. That is, stored functions cannot be used recursively."

And this (I can just assume the book is correct) someday worked before.
[3 Dec 2006 8:02] Valeriy Kravchuk
Just set max_sp_recursion_depth to a recursion depth you may need (up to 255), and it will work again. See http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html for the details:

"- max_sp_recursion_depth

The number of times that a stored procedure may call itself. The default value for this option is 0, which completely disallows recursion in stored procedures. The maximum value is 255.

This variable can be set globally and per session."
[3 Dec 2006 8:10] Maciej Pilichowski
Valeriy, please, FUNCTIONS not PROCEDURES. I am NOT talking about PROCEDURES you are the only person here who mention it again and again.
[3 Dec 2006 8:11] Maciej Pilichowski
And I have set max_sp_recursion_depth (global) to 255 but it is NOT for functions.

So my wish is still valid -- please provide recurrent FUNCTIONS.
[22 Dec 2006 12:49] Valeriy Kravchuk
Yes, you are right: stored functions can not be recursive now. It is a documented limitation. Read http://dev.mysql.com/doc/refman/5.0/en/routine-restrictions.html, for example.

I think, it is a valid feature request to allow recursive functions creation again. But I am not sure when it will be implemented.