Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination doesn't work with MSSQL for some query #1342

Closed
DavideD opened this issue Jun 17, 2022 · 0 comments · Fixed by #1343
Closed

Pagination doesn't work with MSSQL for some query #1342

DavideD opened this issue Jun 17, 2022 · 0 comments · Fixed by #1343
Assignees
Labels
bug Something isn't working
Milestone

Comments

@DavideD
Copy link
Member

DavideD commented Jun 17, 2022

In Sql Server, we run different queries for pagination based on the type of query.
Here's an extract from SQLServer2012LimitHandler#processSql:

	@Override
	public String processSql(String sql, RowSelection selection) {
		// SQLServer mandates the following rules to use OFFSET/LIMIT
		//  * An 'ORDER BY' is required
		//  * The 'OFFSET ...' clause is mandatory, cannot use 'FETCH ...' by itself.
		//  * The 'TOP' clause isn't permitted with LIMIT/OFFSET.
		if ( hasOrderBy( sql ) ) {
			if ( !LimitHelper.useLimit( this, selection ) ) {
				return sql;
			}
			return applyOffsetFetch( selection, sql, getInsertPosition( sql ) );
		}
		return super.processSql( sql, selection );
	}

The error happens for queries without an order-by clause.

Here's a test case to add to FilterWithPaginationTest:

@Test
public void testMaxResultsAndOffsetWithStageWithoutOrderAndFilters(TestContext context) {
	test( context, openSession()
			.thenCompose( session -> session.createQuery( "from FamousPerson p" )
					.setMaxResults( 2 )
					.setFirstResult( 1 )
					.getResultList() )
			.thenAccept( list -> assertThat( list ).containsExactly( rebeccaActress, rebeccaSinger ) )
	);
}

This will fail because we don't replace the parameters placeholder (?) with the one for MSSQL (@P1).

Quarkus issue: eclipse-vertx/vertx-sql-client#1203

@DavideD DavideD added the bug Something isn't working label Jun 17, 2022
@DavideD DavideD added this to the next milestone Jun 17, 2022
@DavideD DavideD self-assigned this Jun 17, 2022
DavideD added a commit to DavideD/hibernate-reactive that referenced this issue Jun 17, 2022
The MSSQL dialect generates set the pagination in the query
in different ways depending on the presence of the order by
clause.
DavideD added a commit to DavideD/hibernate-reactive that referenced this issue Jun 17, 2022
DavideD added a commit to DavideD/hibernate-reactive that referenced this issue Jun 17, 2022
The MSSQL dialect generates set the pagination in the query
in different ways depending on the presence of the order by
clause.
DavideD added a commit to DavideD/hibernate-reactive that referenced this issue Jun 17, 2022
DavideD added a commit to DavideD/hibernate-reactive that referenced this issue Jun 17, 2022
blafond pushed a commit that referenced this issue Jun 22, 2022
The MSSQL dialect generates set the pagination in the query
in different ways depending on the presence of the order by
clause.
DavideD added a commit to DavideD/hibernate-reactive that referenced this issue Jun 30, 2022
The MSSQL dialect generates set the pagination in the query
in different ways depending on the presence of the order by
clause.
DavideD added a commit to DavideD/hibernate-reactive that referenced this issue Jun 30, 2022
blafond pushed a commit to blafond/hibernate-reactive that referenced this issue Sep 30, 2022
The MSSQL dialect generates set the pagination in the query
in different ways depending on the presence of the order by
clause.
blafond pushed a commit to blafond/hibernate-reactive that referenced this issue Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant