嗨 friend 们谁能告诉我我的查询有什么问题。当我执行时,它会锁定数据库5到10分钟,请帮我优化这个查询。
SELECT
u.username,
u.email,
u.created_at,
p.firstname,
p.lastname,
p.address,
p.address_2,
p.city,
p.country,
p.state,
p.zip,
p.phone,
p.phone_2,
u.last_ip,
u.last_login_at,
u.auto_login,
u.registration_page,
s.product_name
FROM
users AS u
Left Join subscriptions AS s ON u.id = s.user_id
Left Join profiles AS p ON u.id = p.user_id
where u.registration_page='Chris_Cleanse' and
u.id not in (select user_id from goal_sheets) and
u.id not in(select user_id from sheet_user_popup_not_adam) and
s.expired=TRUE ORDER BY u.id DESC;
最佳答案
我认为您的 where 条件中的子查询包含过多的数据。 也许你可以尝试像下面这样优化你的SQL:
SELECT
u.username,u.email
FROM
users AS u
Left Join subscriptions AS s ON u.id = s.user_id
Left Join profiles AS p ON u.id = p.user_id
Left Join goal_sheets gs ON u.id = gs.user_id
Left Join sheet_user_popup_not_adam sa ON u.id = sa.user_id
where u.registration_page='Chris_Cleanse'
and gs. user_id is null
and sa.user_id is null
s.expired=TRUE ORDER BY u.id DESC;
关于php - 如何解决执行查询时的数据库锁定问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22142126/