Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Paging Optimization of sqlserver2005

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "the paging optimization of sqlserver2005". In the daily operation, I believe that many people have doubts about the paging optimization of sqlserver2005. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "paging optimization of sqlserver2005". Next, please follow the editor to study!

1. Hibernate paging hibernate pseudo-paging of MsSql

Paging is an indispensable function in web projects. Paging technology must be used when large amounts of data cannot be fully displayed. I believe everyone is familiar with the pagination in hibernate:

Java code

Public Query setMaxResults (int maxResults)

Public Query setFirstResult (int firstResult)

Java code

Public Query setMaxResults (int maxResults)

Public Query setFirstResult (int firstResult)

As long as these two methods are called and the parameters are set, hibernate automatic paging completely blocks the underlying paging technology, which is one of the reasons why many developers like hibernate.

There is a strange problem in project development. The database uses Sql Server 2005, and the above two parameters are set, but each SQL statement sent to the database side is select top. Statement. Even if you query section 10w, there is only one select top statement, which inevitably gives rise to doubts about hibernate's implementation of sql server paging. The paging method implemented by hibernate for different databases is encapsulated in the dialect of the corresponding database and transformed into the paging algorithm of the corresponding database through the getLimitString method.

Take the dialect MySQLDialect of the common Mysql database as an example:

Java code

Public String getLimitString (String sql, boolean hasOffset) {

Return new StringBuffer (sql.length () + 20)

.append (sql)

.append (hasOffset? "limit?,": "limit?")

.toString ()

}

Java code

Public String getLimitString (String sql, boolean hasOffset) {

Return new StringBuffer (sql.length () + 20)

.append (sql)

.append (hasOffset? "limit?,": "limit?")

.toString ()

}

The familiar limit is used for paging.

Dialect Oracle9iDialect of the database:

Java code

StringBuffer pagingSelect = new StringBuffer (sql.length () + 100)

If (hasOffset) {

PagingSelect.append ("select * from (select row_.*, rownum rownum_ from ("))

}

Else {

PagingSelect.append ("select * from ("))

}

PagingSelect.append (sql)

If (hasOffset) {

PagingSelect.append (") row_ where rownum?")

}

Else {

PagingSelect.append (") where rownum? and RowNumber? and RowNumber

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report