Skip to content

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

Open
@roji

Description

@roji

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions