JsonApiDotNetCore icon indicating copy to clipboard operation
JsonApiDotNetCore copied to clipboard

Suspect suboptimal query logic when combining primary filter, paging and included resource

Open bjornharrtell opened this issue 6 months ago • 2 comments

SUMMARY

I've been looking into performance issues when making a filtered request that also includes some related resource collection and pagination is enabled and I suspect the query strategy is suboptimal.

DETAILS

It seems the query that is being built will use row_number window function on the full set of related resources, filtering applied afterwards.

STEPS TO REPRODUCE

Not available yet. Working on a full reproduction as standalone repo, or possibly as fork of JsonApiDotNetCore.

VERSIONS USED

  • JsonApiDotNetCore version: 5.7.1
  • ASP.NET Core version: Latest on .NET 9.0
  • Entity Framework Core version: 9.0.5
  • Database provider: Npgsql.EntityFrameworkCore.PostgreSQL 9.0.4

bjornharrtell avatar Jun 05 '25 17:06 bjornharrtell

In the case I'm investigating, the related entites are of bounded amounts that we do not need to paginate. So we can actually workaround this by setting page size to 0 for the related included entities. Would be fun go dig deeper though... I'm suspecting the generated query could be optimized by a lateral join or forced filter order by using ctes.

bjornharrtell avatar Jun 05 '25 20:06 bjornharrtell

Thanks for sharing. I'm curious what you'll come up with.

Please use the master branch for exploration. It contains #1735, which eliminates subqueries when pagination is turned off in includes.

bkoelman avatar Jun 05 '25 21:06 bkoelman

@bjornharrtell Are you still working on this?

bkoelman avatar Jun 28 '25 11:06 bkoelman

Is unlikely I will find time for this, unfortunately.

bjornharrtell avatar Jun 30 '25 10:06 bjornharrtell

I'll close this then, it currently is not actionable. Please open a new issue if you have identified a problem in JADNC.

bkoelman avatar Jun 30 '25 11:06 bkoelman