【问题标题】:Performance when make Pagination on category with losts of records对具有大量记录的类别进行分页时的性能
【发布时间】:2012-04-12 14:09:28
【问题描述】:

我有一个有很多记录的大类别。 我必须对它进行排序 topic_lastpost_time

但是当我这样做时,mysql 似乎很慢。 3秒完成查询 我索引了 topic_lastpost_time 字段

这是一个例子。我怎样才能加速它?

# Query_time: 3  Lock_time: 0  Rows_sent: 50  Rows_examined: 36075
SELECT   t.topic_id,
         t.m_id,
         t.m_username, 
         t.topic_title,
         t.topic_lastpost_time
FROM     p_topics t
WHERE    t.fc_id = '21'
         AND t.topic_state = '1'
ORDER BY t.topic_type DESC, 
         t.topic_lastpost_time DESC 
LIMIT    0,50;

【问题讨论】:

  • fc_idtopic_state 是否也被编入索引?
  • fc_idtopic_state 上可能缺少索引。请发布SHOW CREATE TABLE p_topics 的结果以进行验证。
  • 是的,fc_id,topic_state 已经编入索引。

标签: mysql sorting optimization


【解决方案1】:

尝试改变order by子句的顺序

SELECT   t.topic_id,
     t.m_id,
     t.m_username, 
     t.topic_title,
     t.topic_lastpost_time
FROM     p_topics t
WHERE    t.fc_id = '21'
     AND t.topic_state = '1'
ORDER BY t.topic_lastpost_time DESC  ,
t.topic_type DESC
LIMIT    0,50;

【讨论】:

  • 我需要 topic_type 的优先级,因为我需要最重要的主题在最高位置。
猜你喜欢
  • 2014-04-05
  • 2013-05-06
  • 1970-01-01
  • 2011-11-05
  • 1970-01-01
  • 1970-01-01
  • 2020-01-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多