完整SQL如下:
explain
select count(distinct tmp.id)
from (
select o.id, o.created_date
from `order` o, order_item oi, product p, customer c
where o.deleted=false
and ((o.account_id>0 and o.account_id=c.account_id))
and o.shop_id=12345
and o.id=oi.order_id and oi.product_id=p.id
and
(
(
o.id like "%"'abc'"%"
or o.contact_information like "%"'abc'"%"
or c.last_name like "%"'abc'"%"
or c.email like "%"'abc'"%"
or p.title like "%"'abc'"%"
or exists (
select refer_id from address a where o.id=a.refer_id
and ( a.last_name like "%"'abc'"%"
or a.address like "%"'abc'"%")
)
)
)
union all
select o.id, o.modified_date
from `order` o, order_item oi, product p, customer c
where o.deleted=false
and o.account_id=0 and o.customer_id=c.id
and o.shop_id=12345
and o.id=oi.order_id and oi.product_id=p.id
and
(
(
o.id like "%"'abc'"%"
or o.contact_information like "%"'abc'"%"
or c.last_name like "%"'abc'"%"
or p.title like "%"'abc'"%"
or exists (
select refer_id from address a where o.id=a.refer_id
and ( a.last_name like "%"'abc'"%"
or a.address like "%"'abc'"%")
)
)
)
) tmp