使用ORDER BY中的索引和来自不同表的两列

时间:2012-04-03 12:37:19

标签: mysql indexing performance

我有这个问题:

SELECT ...
FROM property as p FORCE INDEX (property_order)
INNER JOIN property_attribute as pa ON pa.property_attribute_property_id = p.property_id
WHERE ...
ORDER BY p.property_featured DESC, p.property_ranking_date DESC

此查询运行良好,但如果我在ORDER BY中添加property_attribute中的字段,则使用偶数文件排序会使性能变得非常糟糕。

更改:

ORDER BY 
  p.property_featured DESC, 
  pa.property_attribute_minimum_photo_1, 
  p.property_ranking_date DESC
事实上事情很奇怪。如果我从查询中删除FORCE INDEX,我会在解释的第一行收到:

1   SIMPLE  agent   ref PRIMARY,agent_published,agent_id    agent_published 1   const   1   Using temporary; Using filesort

好吧,s a problem in my 'agent' table? So, when I remove the all ORDER BY, the filesort disappears. There在ORDER BY中的代理表中没有字段...

我的问题是:

  1. 我应该在property_attribute表中添加一个索引来演变' pa.property_attribute_minimum_photo_1'场?

    • 如果是,在那里添加索引,我应该在INNER JOIN子句中使用索引吗?

    • 如果不是,我应该在哪里添加索引?

  2. 有没有办法在不同的表中的一个索引列中合并?

0 个答案:

没有答案
相关问题