存档

‘mysql’ 分类的存档

sql常规变态顺序

2010年8月1日 effect 没有评论

SELECT id, concat( ‘,’, id, ‘,’ ) AS test, substring_index( concat(‘,’,replace( ‘7,4,12,6,3,2′, ‘,’, ‘,,’ ),’,') , concat( ‘,’, id, ‘,’ ), 1 )
FROM `tablename`
WHERE id
IN ( 7, 4, 12, 6, 3, 2 )
ORDER BY substring_index( concat(‘,’,replace( ‘7,4,12,6,3,2′, ‘,’, ‘,,’ ),’,') , concat( ‘,’, id, ‘,’ ), 1 ) ;

谁能看明白 哈哈哈哈哈

感谢同事老王

分类: mysql 标签:

百万级的limit

2010年8月1日 effect 没有评论

先把表名和表的结构说一下:
表名:blog
字段:
id title type content
索引为:type
自增主键:id

一个很简单的分页SQL查询:
select * from blog where type=1 order by id desc limit 100,10;

这条语句没问题,效率非常高,我普通的电脑在0.1秒之内。

但是当blog表是一个超过百万记录的大表的时候:
select * from blog where type=1 order by id desc limit 100000,10;
这条查询如果在生产环境下,估计你会想哭。我这跑了几十秒。
阅读全文…

分类: mysql, 性能优化 标签: