2014-03-03 208 views
-1

我sql查询我的头文件,使主页只需要太多的时间。MySQL查询需要太多的时间来执行

"select 
t1.*,t2.ID,t2.post_title,t2.post_content,t5.name as itemCat,t4.taxonomy as itemType 
from 
$wpdb->postmeta as t1 
inner join $wpdb->posts as t2 on t2.ID=t1.post_id 
inner join $wpdb->term_relationships as t3 on t3.object_id=t2.ID 
inner join $wpdb->term_taxonomy as t4 on t4.term_taxonomy_id=t3.term_taxonomy_id 
inner join $wpdb->terms as t5 on t5.term_id=t4.term_id 
where t2.post_status='publish' AND t1.meta_key = '_ait-dir-item' and t1.meta_value 
LIKE '%".$url->cityName."%' group by t2.ID,itemType" 
+0

使用的任何索引? – Neels

+0

如何制作索引? – User1988

+0

“%anything”不能使用索引。但“任何%”都可以。 – Strawberry

回答

0

如果您有权在数据库中执行DDL操作,则可以继续尝试在表上创建一些索引。

如果数据库的规模巨大,查询数据库中的花费很长的时间内扫描通过各种记录,那么索引可以为他们有效减少扫描所花费的时间是有用的。

来创建索引,你可以探索下面的教程:

https://dev.mysql.com/doc/refman/5.5/en/create-index.html

对于理解指标是如何工作的,什么是索引的有效的方式,你可以通过以下页面:

https://dev.mysql.com/doc/refman/5.5/en/optimization-indexes.html

因为一些其他因素,如缓慢的RAM和较少的内存在服务器上运行,因此您的查询需要花费时间,那么您可能需要更改先验在您的服务器机器上运行的进程的类型。

希望你找出什么是路障在这里。