When I run this query mysql server cpu usages stays at 100% and chokes the server. What am I doing wrong?
SELECT *
FROM projects p, orders o, invoices i
WHERE p.project_state = 'product'
AND (
p.status = 'expired'
OR p.status = 'finished'
OR p.status = 'open'
)
AND p.user_id = '12'
AND i.projectid =0
GROUP BY i.invoiceid
LIMIT 0 , 30
You are including the orders table but not joining to it. This will make a full cross join that can potentially produce millions of rows.