最近在做项目时遇到了一个问题,感觉随着时间的推移想出的解决方法的过程很有趣,所以拿出来和大家讨论一下。如果有好的建议的话,也可以学习一下。
一、事情起因:
事情是这样的,别人写的功能出问题了,让楼主来修改。前台使用的是element-ui,后台则是springboot+mybatis-plus,测试环境用的是mysql库。前台分页展现数据,每页10条记录。原来的代码使用IPage来做分页,相关数据从两张表中取数,分别是data_city_area_customer_rel和data_city_area_customer_rel_extend,测试环境上每张表里只有两万的数据,所以原开发人员写了如下的SQL:
SELECT USR.cust_id ,
USR.thing_number ,
USR.class_type,
(select class_name from data_class_code t where t.class_type_code=USR.class_type) AS class_type_name,
USR.open_dealaddress_id ,
USR.open_deal_id ,
USR.cust_type ,
USR.in_date ,
USR.status_tag ,
(select data_name from data_static_thing t where t.type_id='status' and t.data_id=USR.status_tag) AS status_TAG_NAME,
USR.product_id ,
(select product_name from data_product_thing t where t.product_id=USR.product_id) AS product_name,
REL.crmu_id ,
USR.cust_name ,
REL.city_code ,
(select t.zone_name from data_zone_thing t where t.zone_code=REL.city_code) AS city_name,
REL.piple_code ,
(select t.piple_name from data_piple_thing t where t.piple_code=REL.piple_code) AS piple_name,
REL.client_clustering_u AS USER_ATTR,
(select t.attr_value from data_attr_thing t where t.attr_type='USER_ATTR' and t.attr_code=REL.client_clustering_u) AS USER_ATTR_NAME,
REL.org_code ,
REL.grid_id,
(select t.org_name from data_org_thing t where t.org_code=REL.org_code) AS org_name,
(select t.grid_name from data_grid_thing t where t.grid_id=REL.grid_id) AS grid_name,
REL.GRID_boss_ID,
REL.SALE_boss_ID,
REL.HOLD_boss_ID,
(select t.deal_name from data_deal_thing t where t.deal_id=REL.HOLD_boss_ID) AS hold_boss_NAME,
REL.grid_boss_ID ,
(select t.deal_name from data_deal_thing t where t.deal_id=REL.grid_boss_ID) AS grid_boss_NAME,
REL.calls_boss_ID,
REL.update_staff_id ,
REL.update_depart_id ,
REL.update_time ,
USR.destroy_time ,
REL.develop_type ,
REL.develop_staffid ,
(select t.deal_name from data_deal_thing t where t.deal_id=REL.develop_staffid) AS DEVELOP_STAFF_NAME,
REL.develop_type_id ,
USR.LINK_NAME,
USR.LINK_PHONE,
REL.client_clustering_c ,
(select t.attr_value from data_attr_thing t where t.attr_type='CLIENT_ATTR' and t.attr_code=REL.client_clustering_c) AS CLIENT_CLUSTERING_NAME,
REL.develop_departid ,
(select t.org_name from data_org_thing t where t.org_code=REL.develop_departid) AS DEVELOP_DEPART_NAME,
REL.client_clustering_u ,
REL.cilent_type ,
USR.cust_address ,
USR.agent_depart ,
(select t.org_name from data_org_thing t where t.org_code=REL.agent_depart)