nhibernate-core icon indicating copy to clipboard operation
nhibernate-core copied to clipboard

Small enhancement for in memory evaluation of polymorphic query

Open csharper2010 opened this issue 8 months ago • 0 comments

Currently, we get the warning...

firstResult/maxResults specified on polymorphic query; applying in memory!

... quite often with queries having set a MaxRows row selection on a base entity class of polymorphic nature.

There are situations where it is absolutely correct to warn in such a case:

  • some results should be skipped with set FirstResult: the skipped records need to be calculated in memory
  • the query has an order by clause: the ordering is not handled correctly

In my case, I have the situation where I want to check if there are entities for a certain criteria or I just want to find some of them as a worklist for now. I don't care about sort order (there is no order by clause in the query).

In this case I would expect

  • to get the query translators are evaluated step by step until I reach the MaxRows limit
  • to not get a warning

In each iteration over the translators, we can calculate the maximum number of to-be-fetched rows as the difference between the total MaxRows and the already fetched rows. Additionally, I would like to change the includedCount variable to be zero-based and not minus-one-based because that's counterintuitive.

csharper2010 avatar Feb 26 '25 16:02 csharper2010