查询方案一
1)首先根据条件查询主键ID
2)然后根据Id查询所有的工单数据
3)然后组装需要的数据
第一次查询用时:11200
第二次查询用时:8297
第三次查询用时:7868
第四次用时:11211
第五次用时:9488
第六次用时:8584
第七次查询用时:7997
平均用时:9235
方案二:
1)根据条件拼sql查询能管理表的数据
2)组装需要的数据
第一次查询:8287
第二次查询:8392
第三次查询:10873
第四次查询:10568
第五次查询:8203
第六次查询:7588
第七次查询:9018
平均用时:8989.9
下面是单独查询ID和拼接sql的用时情况sql的新能情况
Sql1
SELECT
s.id
FROM sms_sos s
LEFT JOIN prod_equipment_temp pet ON s.equ_id = pet.id
LEFT JOIN imp_pes_cust_scores ipcs ON ipcs.so = s.ID
第一次查询:0.12秒
第二次查询:0.11秒
第三次查询:0.12秒
sql 2 拼接sql
SELECT
s.parent_id as parentId,
s.org_id as orgId,
s.src_type as srcType,
s.wechat_id as weChatId,
s.created_at as createdAt,
s.docno as docno,
s.status as status,
s.tos_id as tosId,
s.project_id as projectId,
s.product_id as productId,
s.product_category_id as productCategoryId,
s.equ_id as equId,
pet.name as equipmentName,
s.contact_name as contactName,
s.contact_phone as contactPhone,
s.custom_id as customId,
s.custom_name as customName,
s.custom_category_id as customCategoryId,
s.pos_id as posId,
s.se_id as seId,
s.service_content as serviceContent,
s.position_id as positionId,
s.country,
s.province,
s.city,
s.district,
s.street,
s.address,
s.specification,
s.urgency,
s.qa_type as qaType,
s.handle_method as handleMethod,
s.appoint_service_time as appointServiceTime,
s.handle_dept_id as handleDeptId,
s.handle_person_id as handlePersonId,
s.is_overdue as isOverdue,
s.is_break as isBreak,
s.break_reason as breakReason,
s.break_at as breadAt,
s.is_settled as isSettled,
s.completed_at as completedAt,
s.total_hours as totalHours,
s.service_contract_id as serviceContractId,
s.task_plan_id as taskPlanId,
s.dispatched_at as dispatchedAt,
s.is_change_dispatched as isChangeDispatched,
s.is_auto_confirm as isAutoConfirm,
s.logistics_company as logisticsCompany,
s.logistics_number as logisticsNumber,
s.confirm_at as confirmAt,
s.received_at as receivedAt,
s.install_work_id as installationJobId,
s.is_auto_dispatch as isAutoDispatch,
s.pubts,
s.transaction_type_id as transactionTypeId,
s.LAST_MODIFIED as lastModified,
s.LAST_MODIFY_USER as lastModifyUser,
s.CREATE_TIME as createTime,
s.CREATE_USER as createUser,
s.id,
s.tenant_id as tenantId,
pet.snum as equipNum,
pet.code as equipCode
FROM sms_sos s
LEFT JOIN prod_equipment_temp pet ON s.equ_id = pet.id
LEFT JOIN imp_pes_cust_scores ipcs ON ipcs.so = s.ID
时间分析:
第一次 0.57秒
第二次 0.59秒
第三次 0.58秒
从上面可以看出只查Id和所有数据之间存在的新能还是不少的。但是这两种设计方式总的性能好像并不是相差很远,反而第一种方案维护性更好,特别是在迭代比较快的情况下!可能目前数据少不能体现太多的差异。但是就因为选择第一种和第二次方案我和领导争论了很久!!!不知道大家有没有高见!!!