mysql count分页优化_分页中count(*)该如何优化?

你的位置:

问答吧

-> MySQL

-> 问题详情

分页中count(*)该如何优化?

开发中使用mysql,内容分页上,不可避免的使用了count(*)。

先数据量变大100w左右,在应用上sql语句类似

select count(*) from a,b,c

where * and * and *

每次记录下的慢查询都是count(*)占多,目前的方法是放入memcache中,但是首次查询的时候依然会很慢。

大家有什么好的解决方法没有?

作者: cares

发布时间: 2009-10-12

where * and * and *条件是否合理呢?????

EXPLAIN下执行计划....贴出来看看

作者: jinguanding

发布时间: 2009-10-13

何种引擎

作者: lamp110

发布时间: 2009-10-13

mysql> explain SELECT count(*) FROM profile, profile_address, match, account where 1 and (profile.usr_id=profile_address.usr_id) and (profile.usr_id=match.usr_id) and (profile.usr_id=account.usr_id)   and account.engine='2' and (profile.usr_id<>'12356') and (profile.gender='1') and profile.height<='230' and (DATE_SUB(CURDATE(),INTERVAL '59' year)<=profile.birthday) limit 1;

+----+-------------+-------------------------+--------+----------------------------------+----------+---------+------------------------------------+-------+--------------------------+

| id | select_type | table                   | type   | possible_keys                    | key      | key_len | ref                                | rows  | Extra                    |

+----+-------------+-------------------------+--------+----------------------------------+----------+---------+------------------------------------+-------+--------------------------+

|  1 | SIMPLE      | profile         | ref    | PRIMARY,height,birthday,gender_2 | gender_2 | 8       | const                              | 54943 | Using where              |

|  1 | SIMPLE      | account         | eq_ref | PRIMARY,engine,engine2           | PRIMARY  | 3       | datingdb_cn.profile.usr_id |     1 | Using where              |

|  1 | SIMPLE      | profile_address | eq_ref | PRIMARY                          | PRIMARY  | 8       | datingdb_cn.profile.usr_id |     1 | Using where; Using index |

|  1 | SIMPLE      | match           | eq_ref | PRIMARY                          | PRIMARY  | 8       | datingdb_cn.profile.usr_id |     1 | Using where; Using index |

+----+-------------+-------------------------+--------+----------------------------------+----------+---------+------------------------------------+-------+--------------------------+

4 rows in set

[ 本帖最后由 cares 于 2009-10-14 14:33 编辑 ]

作者: cares

发布时间: 2009-10-14

搞张新表,以查询条件的HASH值为主键,然后记录对应的行数。

作者: yueliangdao0608

发布时间: 2009-10-16

楼上,这个东西咋搞的?

作者: Steven_1981

发布时间: 2009-10-16

老杨,说说看啊

作者: justin033

发布时间: 2009-10-21

profile表的索引是不是都是单列索引?

创建个多列索引看看有没有效果

作者: Germin

发布时间: 2009-10-21

超过100mb的数据 最好分表吧,这样能提高 不少速度 还有where里面关于时间的要写成只等不能出现>或

作者: sun820220

发布时间: 2009-10-22

mysql貌似默认是bitmap index,所以最好写成=号,不用<.>

但我们也可以建成btree index

作者: viadeazhu

发布时间: 2009-10-25

crc32(查询条件) 得到hash值

作者: ymhtt

发布时间: 2009-12-04

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值