cockroachdb / cockroachdb/cockroach

opt: add With expressions to tail-call logic

Open
#140,014 0 comments 0 reactions 0 assignees View on GitHub
A-sql-plpgsql A-sql-routine C-enhancement C-performance E-quick-win T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

We analyze the body of a routine in `memo.ExtractTailCalls` to determine when it is possible to apply tail-call optimization to its execution. Now that CTEs are supported within routines, we should add support for them to this function. A routine call embedded within the (main) input expression of a `WithExpr` is a valid tail call, provided it satisfies the other conditions within `ExtractTailCalls`.

Jira issue: CRDB-46960

Contributor guide

Open the contributing guide

Research direction

Start with memo.ExtractTailCalls and trace its existing tail-call conditions, then inspect how a WithExpr exposes its main input expression. The work is complete when a routine call in that input is recognized as a valid tail call while the existing conditions remain enforced.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.