fetch subselect in unordered paginated query

Description

When no sort order is specified in a paginated query and the child collections of the queried models are loaded not all child collection items might be returned.

I guess to avoid an SQL exceptions the implementers decided to use CURRENT_TIMESTAMP for ordering. But this might not produce the same result-set when querying for the child collections as the query plan might be different if only the model Id is requested.

I logged the following SQL statements:
Query for the Model:
SELECT this_.Id as Id0_0_, this_.Name as Name0_0_
FROM Member this_
ORDER BY CURRENT_TIMESTAMP OFFSET 1 ROWS FETCH FIRST 25 ROWS ONLY

Query for the subselect
SELECT division0_.MemberId as MemberId0_, division0_.Division as Division0_
FROM MemberDivision division0_
WHERE division0_.MemberId in (select this_.Id FROM Member this_ ORDER BY CURRENT_TIMESTAMP OFFSET 1 ROWS FETCH FIRST 25 ROWS ONLY)

Mapping
<class name="Member" table="Member">
<id name="Id" column="Id" type="System.Int32" >
<generator class="identity" />
</id>
<property name="Name" length="100" />

<set name="Division" table="MemberDivision" fetch="subselect" >
<key column="MemberId" />
<element column="Division" type="System.Int32" />
</set>
</class>

Model
public class Member
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }

public virtual ISet<Division> Division { get; protected set; }

public Member()
{
this.Division = new HashSet<Division>();
}

}

public enum Division
{
Unknown,
General,
Professional,
}

Environment

Win, SQLAzure/MsSql2012Dialect

Activity

Show:
Duplicate

Details

Assignee

Reporter

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?

Created April 14, 2016 at 3:55 PM
Updated April 11, 2017 at 12:49 AM
Resolved April 11, 2017 at 12:49 AM
Who's Looking?