日期:2014-05-16  浏览次数:20707 次

MySql 查询优化总结(一)

1、大数据分页查询,varchar 等大字段懒加载

通常代码:

SELECT
  aj.N_BH,
  aj.C_AM,
  aj.C_AH
FROM
  t_aj AS aj
ORDER BY
  aj.D_LARQ DESC
LIMIT 100,
		10

?10W 条数据,查询时间大约 ?0.73s

?

优化后:

select 
 aj.C_AM,
 aj.C_AH,
 aj.N_BH
FROM
(
SELECT
  aj.N_BH,
  aj.D_LARQ
FROM
  t_aj AS aj
ORDER BY
  aj.D_LARQ DESC
LIMIT 100,
		10
) T inner join t_aj aj on t.N_BH = aj.N_BH

?10W 条数据,查询时间大约 ?0.17s

?