Question

I'm fairly new to the language, and I was wondering if tail calls were optimized. In other language I could examinate the machine code or an intermediate representation and figure it for myself but I have no idea about how to do that in PL/SQL.

Thanks in advance.

Was it helpful?

Solution

The online docs suggest not:

http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14261/subprograms.htm#i2884

Each recursive call creates a new instance of any items declared in the subprogram, including parameters, variables, cursors, and exceptions. Likewise, new instances of SQL statements are created at each level in the recursive descent.

And:

At least one path must lead to a terminating condition. Otherwise, the recursion would go on until PL/SQL runs out of memory and raises the predefined exception STORAGE_ERROR.

If tail call optimisation was available, it wouldn't run out of storage (though it might hit some timeout if you let it run for too long.)

You may be able to experimentally see what it does: write a recursive function that ends with a tail call to itself, and observe the memory usage of the Oracle process when you call it, or see what error message you get. See if you can get it to hang indefinitely without using increasing memory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top