Paging query optimization

One, background

Query all data, time-consuming, consuming memory directly from the database, changed some data paging query

 

Second, the conventional query 

1. mysql: limit start data from the m, n data query

select * from table limit m,n 

2. sql server: top + subqueries

3. Principle: From the first record of the database to begin scanning

More backward, i.e. the greater the m, the slower the query

The more data queries, that n, the more slow query

 

Third, the use of sub-query optimization, first find a id, then the limit according to id, identify data

 

Fourth, according to defined optimization do id, the id as a condition where

 

Fifth, optimize the use of temporary table, first find out all the id, and then find out in the trial data

 

Guess you like

Origin www.cnblogs.com/june0816/p/6757383.html