Home > database >  Mysql paging query problem
Mysql paging query problem

Time:09-16

Scene: database data article 500 w, paging query 100000,

1. Query takes 18.87 s
Select c * from t_order where c.i d in (select b.i d the from (select from Anderson, d t_order a limit of 4000000, 10) b);
2. The query takes 3.71 s
The select b.i d the from (select from Anderson, d t_order a limit of 4000000, 10) b.
3. The query takes 0.005 s
In the select c. * from t_order where c.i d (x1, x2,... , x10);
The result of the x1 - x2 for the above 2

As a rule 1 time consuming of SQL=2 SQL takes + 3 SQL time-consuming

Why the difference so big?
In addition to heavy if paging query if the page number, you is how to optimize?

CodePudding user response:

Two questions ha:
1, to confirm whether the cache problem,
2, some of the time it must be equal to 2, 1 + 1 for example, if you run 1000 meters, need to 2 minutes, then 4 minutes to run 2000 meters?

CodePudding user response:

Confirmation is not cache problem

CodePudding user response:

Confirmation is not caused by the cache

CodePudding user response:

Posted the explain the execution of the plan to see, or can only be cheated foolishly

Speculation is 3 is executed for a fixed value and orderly, and mysql has been optimized, scan data accuracy directly after the first traversal went back
But 1 execution time and can't sure you want to in what records, so for every id scanning again
  • Related