我的SQL有点生疏,有些帮助通过一些左手连接提高这个速度......
SELECT
distinct FN.field_first_name_value as "First Name",
LN.field_last_name_value as "Last Name",
u.mail,
IFNULL(
(SELECT (
select
CASE
WHEN status = 4 THEN "Expiring Soon"
WHEN status = 3 THEN "Active Payments Complete"
WHEN status = 0 THEN "Expired / Inactive"
WHEN status = 2 THEN "Cancelled"
END AS status
FROM memberships smm
where u.uid = smm.uid
limit 1
)
FROM users_roles SUR1
WHERE SUR1.uid = u.uid
AND SUR1.rid = 4
LIMIT 1
)
,"No") AS "Paying Member",
IFNULL(
(SELECT "Yes"
FROM users_roles SUR
WHERE SUR.uid = u.uid
AND SUR.rid = 10
LIMIT 1
)
,"No") AS "Newsletter Subscriber"
FROM
users u,
field_data_field_first_name FN,
field_data_field_last_name LN,
role R,
scio_users_roles SUR
where
u.uid = FN.entity_id
AND
u.uid = LN.entity_id
Thje查询返回结果,因为我想要它们,但它需要太长时间。我意识到我需要改进查询的构建方式,但我不确定如何实现左手连接。
非常感谢任何帮助!
答案 0 :(得分:1)
Fisrt all在开始时使用EXPLAIN执行此语句。查看您的查询是否对所有表使用索引。
第二件事,尝试使用"新格式" join语句,使用JOIN tableA ON tableB而不是tableA,tableB staments。
检查您的查询是否正在使用所有联接的索引。解释应该为您提供有用的信息。