在user_accout和user_phone上分别加索引 select sum(a) from ( SELECT COUNT(0) as a FROM xxxxx WHERE ROW_ID!=1773 and USER_ACCOUNT = '18969662823' AND USER_PHONE_YZ_FLAG = '1' union all SELECT COUNT(0) as a FROM xxxxx WHERE ROW_ID!=1773 and USER_PHONE = '18969662823' AND USER_PHONE_YZ_FLAG = '1')T
select sum(k) from ( SELECT COUNT(0) as k FROM xxxxx WHERE ROW_ID!=1773 and USER_ACCOUNT = '18969662823' union all SELECT COUNT(0) FROM xxxxx WHERE ROW_ID!=1773 and USER_PHONE = '18969662823' AND USER_PHONE_YZ_FLAG = '1' ) t然后创建索引。 create index xx1 on xxxxx(USER_ACCOUNT,ROW_ID); create index xx2 on xxxxx(USER_PHONE,USER_PHONE_YZ_FLAG,ROW_ID);
select sum(a) from (
SELECT COUNT(0) as a FROM xxxxx WHERE ROW_ID!=1773 and USER_ACCOUNT = '18969662823' AND USER_PHONE_YZ_FLAG = '1'
union all
SELECT COUNT(0) as a FROM xxxxx WHERE ROW_ID!=1773 and USER_PHONE = '18969662823' AND USER_PHONE_YZ_FLAG = '1')T
SELECT COUNT(0) as k FROM xxxxx
WHERE ROW_ID!=1773
and USER_ACCOUNT = '18969662823'
union all
SELECT COUNT(0) FROM xxxxx
WHERE ROW_ID!=1773
and USER_PHONE = '18969662823' AND USER_PHONE_YZ_FLAG = '1'
) t然后创建索引。
create index xx1 on xxxxx(USER_ACCOUNT,ROW_ID);
create index xx2 on xxxxx(USER_PHONE,USER_PHONE_YZ_FLAG,ROW_ID);