Mysql中sql语句中not in的优化方法

Mysql中sql语句中not in的优化方法left join

  • 优化前
  • 优化后

优化前

SELECT
	`mdz_anchor`.* 
FROM
	`mdz_anchor`
	
	WHERE id not in ( select anchor_id from  `activity_center`.`mdz_live` where mdz_live.status=0 	AND STATUS = 0 
	AND company_id =2 )
	
	AND STATUS = 0 
	AND company_id =2

Mysql中sql语句中not in的优化方法_第1张图片

优化后

SELECT
	`mdz_anchor`.* 
FROM
	`mdz_anchor`
	LEFT JOIN `activity_center`.`mdz_live` ON mdz_live.anchor_id = mdz_anchor.id 
WHERE
	mdz_live.anchor_id IS NULL 
	AND mdz_anchor.STATUS = 0 
	AND mdz_anchor.company_id =2

Mysql中sql语句中not in的优化方法_第2张图片

你可能感兴趣的:(Mysql)