Zhang Hao
At present, many enterprises use the SpringJDBC framework as the data access layer, and I am currently working on integrating SpringJDBC into the J-Hi platform through surveys.
In the past, I did not perform in-depth analysis on the paging processing of various databases. I just had a superficial understanding that SQL server uses top, Oracle uses rownum, and MySQL uses limit to perform paging processing through SQL statements, I always think that you can get the specified number of data entries through the keywords of the corresponding database, and the data can be completed at the database end at one time. For example, if you only retrieve the 10 records that meet the condition 11-20, then the ResultSet will have only 10 results, but this is not the case, and it is mainly entangled in SQLServer.
Through J-Hi's integrated development of SpringJDBC, I realized that SQLServer2000 could not meet our actual needs, but it was only through SQLServer2005 that the situation had changed, let's analyze the paging processing of SQLServer as follows:
SQLServer2000, because it only provides top keywords, and top only serves the first few records that meet the conditions, when processing paging, it extracts the first number of records that meet the conditions, for example, 10 records on each page. When the second page is displayed, the SQL statement is
Select top 20 HI_Org. * from HI_Org: in other words, the first 20 records will be discarded to java at a time to form a result set of 20 records. For us, because the second page contains 10 records per page, that is to say, as long as the last 10 records of the 20 records are useless junk data, such a processing mechanism will not only greatly reduce the efficiency, but also increase the number of pages, for example, if we want to flip to 1,000th pages, there will be 10000 records in the result set, which also results in a waste of resources. As a result, we can estimate that the performance will be lower when pages are turned back. This low performance not only increases the amount of useless data, but also results in time loss for these useless data processing.
Funny times, SQL server that has been used for so long is not unknown. It was supplemented and modified when SQL Server was deemed by Microsoft. The following is the SQL statement of SQL Server.
WITH query AS (select ROW_NUMBER
() OVER (order by CURRENT_TIMESTAMP) as _ hi_row_nr __, hi_org. * from hi_org) SELECT * FROM query WHERE _ hi_row_nr _ BETWEEN 11 AND 20 through the preceding statement, we can see that SQLServer2005 provides ROW_NUMBER () method [this method is a bit like rownum of oracle. Maybe Microsoft may not be able to copy oracle databases for this function, haha]. to record the number of rows in the result set, it is still a bit disgusting, if the order by method is not used, it is still invalid.
Through the analysis of a small feature above, I am really disappointed with Microsoft and SQL Server products. Such a feature will be improved after five years, and it is not new, what's more, even free and open-source products like mysql have already been implemented, while SQLServer is still a commercial operation, I really don't know how Microsoft's SQLServer feels in some aspects like open-source products?