In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.