Skip to content
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

Translate primitive collections with composed LINQ operators via PG array constructor #3208

Open
roji opened this issue Jun 23, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@roji
Copy link
Member

roji commented Jun 23, 2024

When a primitive collection has a LINQ operator composed on top of it, we convert it to a rowset via unnest, insert it via a lateral join into the query, and then process the query as usual:

_ = await context.Blogs
    .Select(b => b.Ints.Select(i => i + 1).ToArray())
    .ToListAsync();

Current SQL:

SELECT b."Id", i.value + 1, i.ordinality
FROM "Blogs" AS b
LEFT JOIN LATERAL unnest(b."Ints") WITH ORDINALITY AS i(value) ON TRUE
ORDER BY b."Id" -- currently missing ordinality, #3207

Instead, we could simply use the array constructor operator to convert the subquery directly into an array:

SELECT ARRAY(SELECT i + 1 FROM unnest(b."Ints"))
FROM "Blogs" AS b

The tricky part here is to figure out exactly when to wrap the subquery in ARRAY(), as opposed to when to leave the classical relational translation with lateral join.

@roji roji added the enhancement New feature or request label Jun 23, 2024
@roji roji added this to the 9.0.0 milestone Jun 23, 2024
@roji roji self-assigned this Jun 23, 2024
@roji roji modified the milestones: 9.0.0, Backlog Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant