Translate primitive collections with composed LINQ operators via PG array constructor

Offen
#3,208 0 Kommentare 1 Reaktion 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@roji arbeitet bereits daran.

Seit 23.6.2024.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

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.

Vorherrschende Sprache
C#
Sterne
1.8k
Forks
268
Ø Merge
2 Std. 35 Min.
Gemergte PRs (30 T.)
136

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus npgsql/efcore.pg

Alle Issues in npgsql/efcore.pg

Ähnliche Issues

Weitere Issues zu C#

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.