数据有4W多条,不多,但是模糊查询
起来特别慢。
1,尝试过用 select * from (select * from a union all select * from b。。。很多表union) as tempTable where name like "%a%" and person_id like "%1%",发现太慢了。。
2,尝试使用具体的字段,而不是*,即
select id,name,person_id from (select id,name,person_id from a
union all select id,name,person_id from b。。。很多表union) as tempTable where name like "%a%" and person_id like "%1%",虽然快了点儿,但是不是特别快。。
3,尝试把where放在每一个select语句中,不需要汇聚成一个表了,即少了别名:
select id,name,person_id from a where name like "%a%" and person_id like "%1%"
union all select id,name,person_id from b where name like "%a%" and person_id like "%1%", 卧槽,出乎意料地快!解决了问题。
4,mybatis配置文件如下:
模糊查询的总数:
模糊查询的详细: