Table articles:
id|category_id|title|created|updated
Index:
ADD KEY `category_id` (`category_id`,`created`)
My testing:
SELECT sql_no_cache * FROM `articles` WHERE category_id=1 order by created limit 0,15
Average time: 0.0003
SELECT sql_no_cache * FROM `articles` WHERE category_id=1 order by updated limit 0,15
Average time: 0.0019
SELECT sql_no_cache * FROM `articles` WHERE category_id in (1,2,3) order by created limit 0,15
Average time: 0.0018
SELECT sql_no_cache * FROM `articles` WHERE category_id in (1,2,3) order by updated limit 0,15
Average time: 0.0018
created 做了二级索引, query1 明显用了索引(对比 query2 ),但是 query3 没用索引。请问如何索引提高 query3 的查询效率?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.