免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1541 | 回复: 0
打印 上一主题 下一主题

mysql 性能问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-24 12:15 |只看该作者 |倒序浏览
1,
slave
mysql  Ver 14.12 Distrib 5.0.45, for unknown-linux-gnu (x86_64) using readline 5.0
2cpu
4G ram



SELECT order_id FROM T_ORDER WHERE  state!=10020 and state!=10001 and pay_type=10300
  16144 rows in set (0.50 sec)
  +----+-------------+---------+------+-------------------+---------+---------+-------+--------+-------------+
| id | select_type | table   | type | possible_keys     | key     | key_len | ref   | rows   | Extra       |
+----+-------------+---------+------+-------------------+---------+---------+-------+--------+-------------+
|  1 | SIMPLE      | T_ORDER | ref  | state_idx,PAY_IDX | PAY_IDX | 4       | const | 228000 | Using where |
+----+-------------+---------+------+-------------------+---------+---------+-------+--------+-------------+




SELECT order_id FROM T_ORDER WHERE  state!=10020 and state!=10001
  101667 rows in set (0.09 sec)
  
+----+-------------+---------+-------+---------------+-----------+---------+------+--------+--------------------------+
| id | select_type | table   | type  | possible_keys | key       | key_len | ref  | rows   | Extra                    |
+----+-------------+---------+-------+---------------+-----------+---------+------+--------+--------------------------+
|  1 | SIMPLE      | T_ORDER | range | state_idx     | state_idx | 5       | NULL | 145471 | Using where; Using index |
+----+-------------+---------+-------+---------------+-----------+---------+------+--------+--------------------------+



MASTER
mysql  Ver 14.12 Distrib 5.0.51a, for redhat-linux-gnu (x86_64) using readline 5.0
4cpu
8G ram

explan 结果和上面一致

SELECT order_id FROM T_ORDER WHERE  state!=10020 and state!=10001 and pay_type=10300
16141 rows in set (0.75 sec)

SELECT order_id FROM T_ORDER WHERE  state!=10020 and state!=10001
101664 rows in set (0.13 sec)

没有负载差异。记录有50W左右。


为啥就没有slave 快呢? 都是innodb .
但是下面情况

slave
SELECT order_id FROM T_ORDER WHERE buyer='dahai';
Empty set (0.88 sec)
+----+-------------+---------+------+---------------+------+---------+------+--------+-------------+
| id | select_type | table   | type | possible_keys | key  | key_len | ref  | rows   | Extra       |
+----+-------------+---------+------+---------------+------+---------+------+--------+-------------+
|  1 | SIMPLE      | T_ORDER | ALL  | NULL          | NULL | NULL    | NULL | 601630 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+--------+-------------+


master
SELECT order_id FROM T_ORDER WHERE buyer='dahai';
Empty set (0.79 sec)

再不使用索引的情况下就master 快。。

还有master 用的是独享表空间。slave 共享表空间

这是为啥?

2,order_by 索引问题
还有mysql order by 的时候索引很难用到。各位有什么好办法

select * from a where a=xx order by a (a 有索引)  这样情况能用到索引。
但是 where 后面 a=xx and b=yy(b 也有索引) 这时候再order by a  就用不到索引。要建联合索引 a,b 可以。
如果 我的条件涉及很多列 几个索引要order by a 的话就要建立很多列的联合索引才行嘛?

请教下
谢谢

[ 本帖最后由 dahai01 于 2008-10-24 17:47 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP