mysql pagination

The second paging method:

select t.* from (select id from t where thread_id = 771025 and deleted = 0 order by gmt_create asc limit 0, 15) a, t where a.id = t.id;

 

Premise: Assume that the primary key of the t table is the id column, and there is a covering index secondary key: (thread_id, deleted, gmt_create)

 

Principle: First, use the covering index to retrieve the primary key id for sorting according to the filter conditions, and then perform the join operation to retrieve other fields. Data access cost = index IO + table data IO corresponding to the result after index paging (15 rows in the example).

 

Pros: Each page turn consumes basically the same amount of resources and time as turning the first page. Applicable scenario: It is applicable when the query and sorting fields (that is, the fields involved in the where clause and the order by clause) have corresponding covering indexes, and the intermediate result set is large.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325993809&siteId=291194637