OData / OData/AspNetCoreOData

OData Performance Issue

Open
#1,193 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Hi

OData 8.2.0

We execute the following OData query:
https://localhost:44394/odata/EntitySet('BSL24OMNEH2TCP0')?$expand=observations

Which generates following SQL, which executes normally and we get results as expected:
SQL QUERY 1

SELECT o.source_id, o.col1, o.col2, o.col3, o.col4, o.col5, o.col6, o0.source_id, o0.col1, o0.col2
FROM ParentTableName AS o
LEFT JOIN ChildTableName AS o0 ON o.source_id = o0.source_id
WHERE o.source_id = @__source_id_0
ORDER BY o.source_id, o0.source_id

BUT

When changing the OData query structure to the following:
https://localhost:44394/odata/EntitySet?$expand=observations&$filter=source_id eq 'BSL24OMNEH2TCP0'

The generated SQL is totally different, which causes significantly poor database performance (SQL inner selects, no filtering on the ChildTableName dramatically increase SQL query cost):
SQL QUERY 2

SELECT o.source_id, o.col1, o.col2, o.col3, o.col4, o.col5, o.col6, o0.source_id, o0.col1, o0.col2
FROM (
SELECT o.source_id, o.col1, o.col2, o.col3, o.col4, o.col5, o.col6
FROM ParentTableName AS o
WHERE o.source_id = @__TypedProperty_0
ORDER BY o.source_id
LIMIT @__TypedProperty_4
) AS t
LEFT JOIN (
SELECT t1.source_id, t1.col1, t1.col2
FROM (
SELECT o0.source_id, o0.col1, o0.col2, ROW_NUMBER() OVER(PARTITION BY o0.source_id ORDER BY o0.col1) AS row
FROM ChildTableName AS o0
) AS t1
WHERE t1.row <= @__TypedProperty_2
) AS t0 ON t.source_id = t0.source_id
ORDER BY t.source_id, t0.source_id, t0.col1

QUESTION:
Is there any way to influence the process of generating SQL query from the second OData request to increase the performance on the database side? Alternate suggestions are more than welcome, thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the two OData request shapes in the issue and the generated SQL for OData 8.2.0, then inspect the query options and database execution plans involved. Done means documenting a supported way to influence the second translation for better performance, or confirming the limitation and an alternative request shape.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.