這是我的查詢,它至少需要1分鐘在遠程MySQL服務器上執行。如何提高MySQL中的性能或查詢執行時間?
select
a.z_companyid_pk 'z_companyid_pk',
a.company_name 'Client',
a.display_name 'Display_Name',
a.z_parentcompanyid_fk 'Parent_Company',
a.z_resellerid_fk 'Reseller',
(select
company_name
from
company_mst
where
z_companyid_pk = a.z_resellerid_fk) 'Reseller_name',
(select
if(count(*) >= 1, 'YES', 'NO')
from
webprofile
where
z_boxid_fk in (select
z_boxid_pk
from
box_mst
where
z_companyid_fk = a.z_companyid_pk)) 'V1_Website',
(select
if(count(*) >= 1, 'YES', 'NO')
from
webapp_mst
where
z_companyid_fk = a.z_companyid_pk) 'V2_Website',
(select
if(count(*) > 0, 'YES', 'NO')
from
widget_mst
where
widget_status = 1
and type in ('templated-menu' , 'menus')
and z_companyid_fk = a.z_companyid_pk) 'Widgets_with_my_menu',
(select
if(count(imagehtml) > 0, 'YES', 'NO')
from
image_mst
where
length(imagehtml) > 0
and z_companyid_fk = a.z_companyid_pk) 'HTML_menus',
(select
max(login_datetime)
from
loginlog_mst a
LEFT OUTER JOIN
contact_mst b ON a.z_contactid_fk = b.z_contactid_pk
where
b.z_companyid_fk = a.z_companyid_pk) 'LCI',
k.z_boxid_pk 'DMB_Box_ID',
k.box_name,
(select
box_lastcheck
from
box_online
where
z_boxid_fk = k.z_boxid_pk) 'LCI_last_Checked_in_Date',
(select
websitelink
from
company_profile
where
z_companyid_fk = a.z_companyid_pk) 'Website',
(select
company_email
from
company_profile
where
z_companyid_fk = a.z_companyid_pk) 'Primary_Contact_Email',
concat(a.company_address_line1,
a.company_address_line2) 'address',
(select
city_name
from
city_mst
WHERE
z_cityid_pk = a.z_cityid_fk) 'city',
(select
state_name
from
state_mst
WHERE
z_stateid_pk = a.z_stateid_fk) 'Province',
(select
country_name
FROM
country_mst
where
z_countryid_pk = z_countryid_fk) 'country_name',
a.company_postalcode 'zip_postal_code',
(select
telephone
from
company_profile
where
z_companyid_fk = a.z_companyid_pk) 'company_telephone',
a.z_timezoneid_fk,
b.timezone 'time_Zone',
(select
facebooklink
from
company_profile
where
z_companyid_fk = a.z_companyid_pk) 'facebook',
(select
twitterlink
from
company_profile
where
z_companyid_fk = a.z_companyid_pk) 'twitter',
(SELECT
bizurl
FROM
user_settings us
INNER JOIN
asset_mst am ON (us.userid = am.userid)
where
us.isiteid = 1
and am.z_companyid_fk = a.z_companyid_pk) 'Yelp',
(SELECT
bizurl
FROM
user_settings us
INNER JOIN
asset_mst am ON (us.userid = am.userid)
where
us.isiteid = 2
and am.z_companyid_fk = a.z_companyid_pk) 'Urbanspoon',
(SELECT
bizurl
FROM
user_settings us
INNER JOIN
asset_mst am ON (us.userid = am.userid)
where
us.isiteid = 3
and am.z_companyid_fk = a.z_companyid_pk) 'Trip_Advisor',
(SELECT
bizurl
FROM
user_settings us
INNER JOIN
asset_mst am ON (us.userid = am.userid)
where
us.isiteid = 4
and am.z_companyid_fk = a.z_companyid_pk) 'Citysearch',
(SELECT
bizurl
FROM
user_settings us
INNER JOIN
asset_mst am ON (us.userid = am.userid)
where
us.isiteid = 5
and am.z_companyid_fk = a.z_companyid_pk) 'Open_Table',
(SELECT
bizurl
FROM
user_settings us
INNER JOIN
asset_mst am ON (us.userid = am.userid)
where
us.isiteid = 6
and am.z_companyid_fk = a.z_companyid_pk) 'ZAGAT',
(SELECT
bizurl
FROM
user_settings us
INNER JOIN
asset_mst am ON (us.userid = am.userid)
where
us.isiteid = 32
and am.z_companyid_fk = a.z_companyid_pk) 'Zomato',
d.z_contactid_fk 'Email_contact_ID',
d.username 'Email_User_Name',
d.contact_firstname,
d.contact_lastname,
d.status,
(select
max(login_datetime)
from
loginlog_mst
where
z_contactid_fk = d.z_contactid_fk) 'last_login_date',
(select
GROUP_CONCAT(groupname)
from
contact_group_mst
where
z_companyid_fk = a.z_companyid_pk) 'group_name'
from
company_mst a
LEFT OUTER JOIN
timezone_mst b ON a.z_timezoneid_fk = b.z_timezoneid_pk
LEFT OUTER JOIN
company_profile c ON a.z_companyid_pk = c.z_companyid_fk
LEFT OUTER JOIN
(select
v.z_contactid_fk,
v.z_companyid_fk,
w.username,
w.contact_firstname,
w.contact_lastname,
if(contact_wtaccess = 1, 'Veryfied', 'Not Veryfied') 'status'
from
priviledge_mst v
LEFT OUTER JOIN contact_mst w ON v.z_contactid_fk = w.z_contactid_pk
where
w.type <> 'Staff') d ON a.z_companyid_pk = d.z_companyid_fk
LEFT OUTER JOIN
(select
z_boxid_pk, box_name, asset_mst.z_companyid_fk
from
box_mst
INNER JOIN asset_mst ON (box_mst.userid_fk = asset_mst.userid)
where
asset_mst.status = 0
and type = 'menubox') k ON a.z_companyid_pk = k.z_companyid_fk
where
a.status <> 0
and a.z_companyid_pk in (101089 , 104001, 103863)
ORDER BY a.company_name
請幫助我建議一些技術或修改或任何提示,我可以應用此查詢以提高性能。
表結構,列上的索引呢?查詢的執行計劃? – Olli