Slide 23
Slide 23 text
SQL 2 SQL 1
Entity Framework Core
Performance-Optimierung aus der Praxis
Lets try with SQL …
Understanding Queries
SELECT
( SELECT TOP(1) p.Id FROM Products p WHERE g.Id = p.ProductGroupId ) AS FirstProductId,
( SELECT TOP(1) p.Name FROM Products p WHERE g.Id = p.ProductGroupId ) AS FirstProductName
FROM
ProductGroups g
SELECT p.Id, p.Name
FROM
ProductGroups g
LEFT JOIN
(
SELECT Id, Name, ProductGroupId
FROM
(
SELECT Id, Name, ProductGroupId, ROW_NUMBER() OVER(PARTITION BY ProductGroupId ORDER BY Id) AS row
FROM Products
) p
WHERE row <= 1
) p ON g.Id = p. ProductGroupId
2 sub-selects
Window function
“ROW_NUMBER”