› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
stanhou
V2EX  ›  MySQL

如何提高这个 QUERY3 的运行效率?

  •  
  •   stanhou · Mar 3, 2016 · 2653 views
    This topic created in 3924 days ago, the information mentioned may be changed or developed.

    Table articles:
    id|category_id|title|created|updated
    Index:
    ADD KEY `category_id` (`category_id`,`created`)

    My testing:

    query1

    SELECT sql_no_cache * FROM `articles` WHERE category_id=1 order by created limit 0,15
    Average time: 0.0003

    query2

    SELECT sql_no_cache * FROM `articles` WHERE category_id=1 order by updated limit 0,15
    Average time: 0.0019

    query3

    SELECT sql_no_cache * FROM `articles` WHERE category_id in (1,2,3) order by created limit 0,15
    Average time: 0.0018

    query4

    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 的查询效率?

    realpg
    realpg
    Mar 3, 2016
    1
    category_id create 联合索引
    category_id updated 联合索引

    注意顺序, category 在前
    stanhou
    stanhou
    OP
    Mar 3, 2016
    2
    @realpg 你都没看清我问的是什么
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   918 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 21:53 · PVG 05:53 · LAX 13:53 · JFK 16:53
    ♥ Do have faith in what you're doing.