Skip to content

Instantly share code, notes, and snippets.

@prgTW
Last active July 9, 2020 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prgTW/655722dae829ddb9322f6017b0d1a786 to your computer and use it in GitHub Desktop.
Save prgTW/655722dae829ddb9322f6017b0d1a786 to your computer and use it in GitHub Desktop.
SET profiling = 1; -- don't worry, it's per-session setting
SELECT 1
FROM `agreement`
LEFT JOIN `product1` ON (
`agreement`.`id`=`product1`.`agreement_id`
AND `product1`.`status` IN ('active', 'expiring')
)
LEFT JOIN `product2` ON (
`agreement`.`id`=`product2`.`agreement_id`
AND `product2`.`status` IN ('active', 'expiring')
)
WHERE `agreement`.customer_id = :id
GROUP BY agreement.id
HAVING count(product1.id) > 0 OR count(product2.id) > 0
LIMIT 1;
SHOW PROFILE ALL FOR QUERY 1; -- now, we show our profile in most detailed way
-- SET profiling = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment