› 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
xmbaozi
V2EX  ›  MySQL

Mysql 关于复合索引的顺序。a 在前?b 在前?

  •  
  •   xmbaozi · May 27, 2014 · 7848 views
    This topic created in 4549 days ago, the information mentioned may be changed or developed.
    有个表5000w的记录,要给a、b列建唯一索引。其中a为int,大概分布在1-1500左右;b为varchar(32),8-32个字符,b中出现重复的极低。
    现在考虑到where a=x1 and b=x2的情况,这个索引顺序怎么建比较科学,然后理由?

    已经google过了,如
    http://blog.segmentfault.com/waterblog/1190000000473085
    5.联合索引的顺序问题:将选择性高的索引放到前面


    众神什么看?
    4 replies  •  2014-05-28 12:19:42 +08:00
    duzhe0
    duzhe0
    May 27, 2014❤️1
    1
    测一下实际效果看看。估计差别不大, 没必要那么纠结。我猜b-a可能好一点
    tonitech
    tonitech
    May 28, 2014❤️1
    2
    楼主做个测试再给个答案吧
    cyyever
    cyyever
    May 28, 2014❤️1
    3
    根据选择率是a-b,但是有个问题,这样做索引会比b-a大,因为a-b中a出现了1500次,b也出现了1500次,如果是key buffer比较稀缺的话,还不如b-a,毕竟查内存索引总比查磁盘索引快吧
    我建议楼主两个索引都创建一下,然后用show table status看下index大小。然后结合服务器资源综合考虑
    我的看法是内存再慢也比io快,redis就是省内存,比memcached现在发展得好。。虽然它单个操作可能比memcached慢。。
    tonic
    tonic
    May 28, 2014❤️1
    4
    (b, a) use where b= and a=
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4061 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 06:51 · PVG 14:51 · LAX 22:51 · JFK 01:51
    ♥ Do have faith in what you're doing.