Php wordpress中的Mysql查询执行时间太长
我的头文件中有sql查询,所以主页只会占用太多时间Php wordpress中的Mysql查询执行时间太长,php,mysql,Php,Mysql,我的头文件中有sql查询,所以主页只会占用太多时间 "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
"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"
如果您有权在数据库中执行DDL操作,则可以继续尝试在表上创建一些索引 如果数据库的大小很大,并且查询在扫描数据库中的各种记录时花费了很长时间,那么索引会很有用,因为它们减少了有效扫描所需的时间 要创建索引,可以浏览以下教程: 要了解索引如何工作以及什么是有效的索引方式,您可以浏览以下页面: 如果您的查询由于其他一些因素(如较慢的RAM和服务器上运行的内存较少)而需要花费时间,那么您可能需要更改服务器上运行的进程的优先级 希望您能找到这里的障碍。“%anything”不能使用索引。但“任何%”都可以。