我正在使用MySQL查询从WordPress数据库中提取一些数据。该查询花费的时间太长,仅在phpmyadmin中加载。我需要帮助,以便可以提高性能。
我正在运行一个MySQL查询,该查询从WordPress数据库中提取数据。我有一个带有48 GB RAM和16核心vcpu的高端服务器。以下是我的查询。
select
main.post_author as agent_id,
pt.meta_value as portal,
(
select count(wp_posts.id) from wp_posts
left join wp_postmeta as fdadt ON (wp_posts.id = fdadt.post_id AND fdadt.meta_key in ('hgsc_data_assigned_date','warrantyactivation_data_assigned_date'))
left join wp_postmeta as fdpt ON (wp_posts.id = fdpt.post_id AND fdpt.meta_key in ('hgsc_portal','warrantyactivation_portal'))
where ((date_format(fdadt.meta_value,'%Y-%m-%d') >='2019-07-08') and (date_format(fdadt.meta_value,'%Y-%m-%d') <='2019-07-08'))
and wp_posts.post_author=main.post_author
and fdpt.meta_value=pt.meta_value
and wp_posts.post_type in ('hg-scratch-card','hg-warranty-act')
and wp_posts.post_status='publish'
)
as fresh_data
from wp_posts main
LEFT JOIN wp_postmeta as pt ON (main.id = pt.post_id AND pt.meta_key in ('hgsc_portal','warrantyactivation_portal'))
where
main.post_type in ('hg-scratch-card','hg-warranty-act')
and
main.post_status='publish'
group by agent_id,portal
order by agent_id asc
我需要再添加几个子查询。我想知道性能是否可以提高。