Performance downgrade moving from .net framework odata to .net core odata
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
We are movilng our odata project from .net framework 4.6 to .net core. we are using AspNetCoreOData 8-rc.
Query we have problem with is:
odata/application?$select=Id,ProcessId,LoanAmount,Term,CreationDate,Status,DeviceModel,DeviceModelRef,FirstPaymentDate,DeviceLockSystemType,ActivationStatus&$expand=Customer($select=FullName,NationalIdNumber,CultureName,CellPhone;$expand=TimeZone),DeviceModelRef($select=FullDescription,Model),Contract($select=Id;$expand=Devices($select=Imei;$orderby=LastSeenDate+desc;$top=1)),ContractFile($select=Name,Uri),FinancialAgreementFile($select=Name,Uri)&$filter=SalesmanId+eq+738&$orderby=Id%20desc&$top=40
Most important part is
Contract($select=Id;$expand=Devices($select=Imei;$orderby=LastSeenDate+desc;$top=1))
where we expand View 'Device' and asking for 1 last record by date
The issue is how query is built
.net framework 4.6
OUTER APPLY (SELECT TOP (1) [Project2].[DeviceId] AS [DeviceId], [Project2].[Imei] AS [Imei], [Project2].[C1] AS [C1], [Project2].[C2] AS [C2], [Project2].[C3] AS [C3], [Project2].[C4] AS [C4]
FROM ( SELECT
[Extent7].[DeviceId] AS [DeviceId],
[Extent7].[Imei] AS [Imei],
[Extent7].[LastSeenDate] AS [LastSeenDate],
1 AS [C1],
N'97b3c9cb-e307-4d66-af87-71e9c76152e0' AS [C2],
N'Id' AS [C3],
N'Imei' AS [C4]
FROM [dbo].[Device] AS [Extent7]
WHERE [Limit1].[ContractId] = [Extent7].[ContractId]
) AS [Project2]
ORDER BY [Project2].[LastSeenDate] DESC ) AS [Limit2]
.net core
LEFT JOIN (
SELECT [t1].[Imei], [t1].[DeviceId], [t1].[ContractId], [t1].[LastSeenDate]
FROM (
SELECT [d0].[Imei], [d0].[DeviceId], [d0].[ContractId], ROW_NUMBER() OVER(PARTITION BY [d0].[ContractId] ORDER BY [d0].[LastSeenDate] DESC) AS [row], [d0].[LastSeenDate]
FROM [Device] AS [d0]
) AS [t1]
WHERE [t1].[row] <= 1
) AS [t2] ON [c0].[ContractId] = [t2].[ContractId]
Issue here that Row_Number forces full table scan and filter by contractId after data sorted by ORDER BY [d0].[LastSeenDate] DESC, while in .net framework 4.6 it filtered first and then sorted
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the OData query and the two generated SQL examples in the issue, then trace how the nested Devices expansion with ordering and top 1 is translated in AspNetCoreOData 8-rc. Compare the SQL plans for the .NET Framework and .NET Core forms, and verify that the resulting query avoids unnecessary full-table work while preserving the requested latest device per contract.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- api, databases, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100