-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: implement nested SRFs #26234
Comments
So here are some investigation steps:
Learned:
Learned: If the result of a SRF is used in a larger scalar context, the operation is performed by inserting an additional regular projection on top of the "project set" operator.
Learned: as an exception to rule 1 above, if rule 2 has caused the introduction of a render stage, then that render stage is used to render non-SRF expressions.
Learned: if the input of a SRF is a scalar expression, the "project set" oeprator is able to evaluate it itself (i.e. it does not need a projection "underneath")
Learned: if there are multiple SRFs at the same level of projection, a single "project set" operator is used (but see below).
Learned: a SRF in render position with a single input table is a project set with that table as relational operand.
Learned: a SRF in render position with a complex FROM clause uses a single "project set" clause with the entire relational expression of the original FROM clause as operand.
Learned: the Drawing the line so far, suppose we introduce a new relational operator Then here are the "simple case" transformations on input queries:
All this is not considering SRFs as argument to other SRFs. |
Nested SRFs. For the analysis I'll be writing
Let's analyze this recursion. On the left:
A few observations already:
We have something like a recursion. Let's make an attempt to define it. Let's define
Let's try this:
This is equivalent to the observed structure above, looking good! |
Let's try to extend our attempt to define XFORM above to support simple, non-SRF columns. Let's denote We have already:
And we can add:
|
Now that I knew what the recursion would look like, I knew how to recognize it in pg's own source code, and here it is:
|
The algorithm to perform this substitution is split into two phases:
|
@RaduBerinde moving to planning |
Still a thing. |
for example:
Jira issue: CRDB-5683
The text was updated successfully, but these errors were encountered: