|
当然这里要说的分页性能优化是有前提:mysql的主键是自增的 看看这个案例你是否能看得明白吧,不明白请回复大家可以沟通下的2 n; j3 T: I$ M; |, \9 p! l# O
5 h4 @4 P) N3 O场景1:未优化0 ^/ A( C9 j6 }0 D2 q0 ?2 t) B
SELECT8 j2 U- q4 `& S& u
*" J0 F6 W4 `8 y" Z
FROM
+ J$ y; | X x, n' o) `* O8 T: Z act
+ \( z6 |: l* f8 u5 v5 k' sLIMIT 10000000,' F- `% @# _& n4 c+ I6 Y2 y, z) ~; v' l. d
10 ( B5 I6 O u2 E# q% B2 U
, W+ i% h: }6 f7 n5 G+ l8 x# ]. q
) i `. ?9 |6 U5 J场景2:优化后
% }! [' D0 q' f- kSELECT
- i: ?8 {# m7 z% ] *; c8 u& \0 M) H _" R0 J
FROM* T! P4 m8 N' d3 i3 r$ D: p! U
act, f# d. i* z" T1 x5 e) R& U: R
WHERE) z, G/ ~0 ]! L5 m
id >= (9 I/ H( C. m: \( R
SELECT
% Q4 l$ m" h0 Z4 J( C5 j1 R- _ id
: T" y+ E3 F5 M4 W# d- O1 p) c FROM8 ]! r- Z- W9 y5 O% C. a
act
+ K8 }0 o$ Z- L* } I* O( l1 B) t ORDER BY
/ @: O) _2 a3 S6 ~5 [ id, F0 S2 }, w0 C4 p9 V3 @
LIMIT 10000000,
% O) @8 q& R0 ?& a: B6 z 1
E( ?# K0 u/ m )
0 Y& e1 U, {" C+ Y0 ]+ W9 MLIMIT 10;4 t0 z; G* z5 s$ K
, F3 N1 B0 H6 _$ [' H' m! N4 F6 e( C# h
看看吧 朋友!
( y- [) \7 S7 r3 m" M+ D; N' z" \: g" D2 ~% g
|
|