cockroachdb / cockroachdb/cockroach
sql: support tail-call optimization for recursive routines
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
We currently implement tail-call optimization to reduce overhead for the sub-routines of a PL/pgSQL routine (in particular, for loops). This issue tracks adding support for the same optimization for explicit tail-recursion in routines, both SQL and PL/pgSQL. The optimizer will have to determine whether a nested call is in tail-call position somehow, and keep track of this property in a way that forms execution. There will also have to be some work to make exception handlers work with more general TCO; specifically, `sql.routineGenerator` will have to track exception handlers on a stack, rather than only looking at the handler for the current routine.
Jira issue: CRDB-36412
Contributor guide
Assessment
This issue has not been assessed yet.