mysql-FIND_IN_SET查询优化

优化前

SELECT
	user_id,
	user_name,
	real_name,
	PASSWORD,
	real_org_id,
	real_org_name,
	real_dept_id,
	real_dept_name,
STATUS 
FROM
	sys_user 
WHERE
	is_del = 0 
	AND find_in_set( 'lilong', login_user_account )

mysql-FIND_IN_SET查询优化_第1张图片

优化后

SELECT
	user_id,
	user_name,
	real_name,
	PASSWORD,
	real_org_id,
	real_org_name,
	real_dept_id,
	real_dept_name,
STATUS 
FROM
	sys_user 
WHERE
	user_id =(
	SELECT
		user_id 
	FROM
		sys_user 
	WHERE
		is_del = 0 
		AND FIND_IN_SET( 'lilong', login_user_account ) 
		LIMIT 0,1 
)

mysql-FIND_IN_SET查询优化_第2张图片

优化后,将查询改为子查询速度快了不少(数据量越大,效果越明显)

你可能感兴趣的:(mysql,数据库)