码迷,mamicode.com
首页 > 其他好文 > 详细

接口性能优化评审文档

时间:2016-09-20 16:28:48      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

接口性能优化评审文档

接口性能优化评审文档

一、pc、wap投资列表接口优化

接口地址:api/productInvest/queryProductInvestRecord

1.1 添加索引

jz_product_invest_record添加索引:

ALTER TABLE `jz_product_invest_record` ADD INDEX ix_pir_productNo (`productNo`);

1.2 SQL优化

原SQL:

SELECT 
  r.applyNo,
  r.id,
  r.investAmount,
  r.payDate AS buyDate,
  IFNULL(r.investSource, pc) AS investSource,
  CONCAT(
    LEFT(u.userName, 3),
    ******,
    RIGHT(u.userName, 2)
  ) AS userName,

  r.investmentClient,

-- 快奖
  (SELECT 
    prizeStatus 
  FROM
    `jz_product_invest_speed` a 
  WHERE a.`productNo` = r.`productNo` 
    AND a.applyNo = r.`applyNo` 
    AND a.medalType = first) AS isFirst,

--     豪奖
  (SELECT 
    prizeStatus 
  FROM
    `jz_product_invest_speed` a 
  WHERE a.`productNo` = r.`productNo` 
    AND a.applyNo = r.`applyNo` 
    AND a.medalType = wealthy) AS isWealthy,

-- 准奖
  (SELECT 
    prizeStatus 
  FROM
    `jz_product_invest_speed` a 
  WHERE a.`productNo` = r.`productNo` 
    AND a.applyNo = r.`applyNo` 
    AND a.medalType = last) AS isLast,

--     当前最高
  (SELECT 
    Y 
  FROM
    DUAL 
  WHERE r.`applyNo` = 
    (SELECT 
      jpir.`applyNo` 
    FROM
      jz_product_invest_record jpir 
    WHERE jpir.`productNo` = r.`productNo` 
      AND jpir.`investStatus` IN (PAYED, CHECKED, SETTLED) 
    ORDER BY jpir.`investAmount` DESC,
      jpir.`payDate` ASC 
    LIMIT 0, 1) 
    AND EXISTS 
    (SELECT 
      1 
    FROM
      jz_product_invest_speed 
    WHERE productNo = SLJ2016060500000233
      AND medalType = wealthy 
      AND prizeStatus = INIT)) AS isCurrentMax 

FROM
  jz_product_invest_record r 
  LEFT JOIN jz_user u 
    ON r.uid = u.id 
WHERE r.investStatus IN (PAYED, CHECKED, SETTLED) 
  AND r.productNo = SLJ2016060500000233
ORDER BY isWealthy DESC,
  isCurrentMax DESC,
  isFirst DESC,
  isLast DESC,
  r.payDate DESC 

现SQL:

SELECT 
  r.applyNo,
  r.id,
  r.investAmount,
  r.payDate AS buyDate,
  IFNULL(r.investSource, pc) AS investSource,
  CONCAT(
    LEFT(u.userName, 3),
    ******,
    RIGHT(u.userName, 2)
  ) AS userName,
  r.investmentClient,
  -- 快奖
  (
    IF(
      p.medalType = first,
      p.`prizeStatus`,
      NULL
    )
  ) AS isFirst,
  -- 豪奖
  (
    IF(
      p.medalType = wealthy,
      p.`prizeStatus`,
      NULL
    )
  ) AS isWealthy,
  -- 准奖
  (
    IF(
      p.medalType = last,
      p.`prizeStatus`,
      NULL
    )
  ) AS isLast,
  -- 当前最高
  (SELECT 
    Y 
  FROM
    DUAL 
  WHERE r.`applyNo` = 
    (SELECT 
      jpir.`applyNo` 
    FROM
      jz_product_invest_record jpir 
    WHERE jpir.`productNo` = SLJ2016060500000233 
      AND jpir.`investStatus` IN (PAYED, CHECKED, SETTLED) 
    ORDER BY jpir.`investAmount` DESC,
      jpir.`payDate` ASC 
    LIMIT 0, 1) 
    AND EXISTS 
    (SELECT 
      1 
    FROM
      jz_product_invest_speed 
    WHERE productNo = SLJ2016060500000233 
      AND medalType = wealthy 
      AND prizeStatus = INIT)) AS isCurrentMax 
FROM
  jz_product_invest_record r 
  LEFT JOIN jz_user u 
    ON r.uid = u.id 
  LEFT JOIN 
    (SELECT 
      pis.`applyNo`,
      pis.`prizeStatus`,
      pis.`medalType` 
    FROM
      `jz_product_invest_speed` pis 
    WHERE pis.`productNo` = SLJ2016060500000233) p 
    ON p.applyNo = r.`applyNo` 
WHERE r.investStatus IN (PAYED, CHECKED, SETTLED) 
  AND r.productNo = SLJ2016060500000233 
ORDER BY isWealthy DESC,
  isCurrentMax DESC,
  isFirst DESC,
  isLast DESC,
  r.payDate DESC 

1.3 优化结果

数据行数为113行,未考虑索引的情况下:

  • 原sql执行时间:0.0256sec
  • 现sql执行时间:0.0245sec

二、产品详情接口优化

接口地址:/api/product/queryProductDetail

2.1 添加索引

ALTER TABLE `jz_file_business_rl` ADD INDEX ix_fbr_BustypeBusid(`businessType`,`businessId`);

三、博饼游戏记录查询接口优化

接口地址:/api/boCake/getGameInfo

3.1 添加索引

ALTER TABLE `jz_activity_bo_cake_record` ADD INDEX ix_abcr_cakeId(`cakeId`);
ALTER TABLE `jz_activity_prize_record` ADD INDEX ix_apr_openId(`openId`);

原SQL:

SELECT 
  w.`headImgUrl`,
  w.`openId`,
  r.`diceResult`,
  r.`prizeDesc`,
  r.`prizeNo`,
  pr.`openId`,
  pr.`receiveStatus`,
  w.nickName AS `name`,
  IF(
    pr.`receiveStatus` = 0 
    AND pr.`openId` = oVVT_swNma3fBoaRKqgWUwIKmvIo,
    true,
    false
  ) AS unclaimed 
FROM
  jz_activity_bo_cake_record r 
  INNER JOIN jz_wechat_user_info w 
    ON w.`openId` = r.`openId` 
  LEFT JOIN `jz_activity_prize_record` pr 
    ON pr.`openId` = r.`openId` 
WHERE cakeId = 2016091400000453 
  AND pr.`sourceId` = r.`id` 
  AND pr.`activityType` = ZQHD_BOCAKE 

现SQL:

SELECT 
  wui.`headImgUrl`,
  wui.`openId`,
  r.`diceResult`,
  r.`prizeDesc`,
  r.`prizeNo`,
  pr.`receiveStatus`,
  wui.nickName AS `name`,
  IF(
    pr.`receiveStatus` = 0,
    true,
    false
  ) AS unclaimed 
FROM
  jz_activity_bo_cake_record r,
  jz_wechat_user_info wui,
  `jz_activity_prize_record` pr
WHERE r.cakeId = 2016091400000453 
  AND r.`openId` = wui.`openId` 
  AND r.`openId` = pr.`openId` 
  AND r.`id` = pr.`sourceId` 
  AND pr.`activityType` = ZQHD_BOCAKE 

 

接口性能优化评审文档

标签:

原文地址:http://www.cnblogs.com/caogenit/p/5889068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!