mysql数据库优化:MySQL数据库索引查询优化的分享来源: 发布时间:星期六, 2008年12月20日 浏览:2次 评论:0
="t18">问题描述:
我们要访问 ![]() ![]() ![]() ![]() ![]() ![]() ![]() 执行 ![]() select * from program_access_log where program_id between 1 and 4000 这条SQL非常慢 ![]() 我们原以为处理记录太多 ![]() ![]() ![]() ![]() select * from program_access_log where id between 1 and 500000 and program_id between 1 and 4000 但是这条SQL仍然很慢 ![]() ![]() ![]() Mysql处理50万条记录 ![]() ![]() ![]() ![]() ![]() 问题分析: 这张表大约容量30G ![]() ![]() ![]() ![]() ![]() 这条SQL有两个条件 ![]() ![]() ![]() ![]() ![]() ![]() ![]() 先通过索引文件找出了所有program_id在1到4000范围里所有 ![]() ![]() ![]() 接下来要通过这些id找出表里 ![]() ![]() ![]() ![]() ![]() ![]() 而这个表又非常大 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 问题解决方案: 1. 以program_id为条件对表进行分区 2. 分表处理 ![]() ![]() ![]() 然而 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 所以我们采取了第 3种办法: select * from program_access_log where id between 1 and 500000 and program_id between 1 and 15000000 现在program_id ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 整理总结: 这是 ![]() ![]() ![]() ![]() ![]() 0
相关文章
读者评论
发表评论 |