• sql优化 二次侧


    二次侧 一千多万条数据

    SELECT
        count(1)
    FROM
        d_secondminutehandledata

    SELECT
        count(1)
    FROM
        d_secondminutehandledata
    WHERE
    collectionTime BETWEEN '2022-01-13'
    AND '2023-03-01'

     

     没有索引的时候,一个count都这么的慢

    SELECT
        count(1)
    FROM
        d_secondminutehandledata
    WHERE
        stationBranchId = 533
    AND collectionTime BETWEEN '2022-01-13'
    AND '2023-03-01'

     用到索引是非常快的

    SELECT
        count(1)
    FROM
        d_secondminutehandledata
    WHERE
        stationBranchId = 533

    用到索引的第一个字段也是非常快的

    SELECT
        collectionTime,
        stationBranchId,
        beforeBranchMeterAccHeat,
        beforeBranchMeterAccFlow,
        twoMeterAccHeat,
        twoSupplyAccFlow,
        mixingwaterAccHeat,
        mixingwaterAccFlow,
        oneBranchReplenishmentTankAccFlow,
        Data_FMeter_V1TO2SFlow,
        fillWaterAccFlow,
        oneBranchTotalElectricMeterElectricity,
        cyclePumpElectricMeterElectricity
    FROM
        d_secondminutehandledata
    WHERE
        stationBranchId = 533
    AND collectionTime BETWEEN '2022-01-13'
    AND '2023-03-01'
    ORDER BY
        collectionTime DESC
    LIMIT 10000

     

    SELECT
        b.*, beforeBranchMeterAccHeat,
        beforeBranchMeterAccFlow,
        twoMeterAccHeat,
        twoSupplyAccFlow,
        mixingwaterAccHeat,
        mixingwaterAccFlow,
        oneBranchReplenishmentTankAccFlow,
        Data_FMeter_V1TO2SFlow,
        fillWaterAccFlow,
        oneBranchTotalElectricMeterElectricity,
        cyclePumpElectricMeterElectricity
    FROM
        d_secondminutehandledata a
    RIGHT JOIN (
        SELECT
            collectionTime,
            stationBranchId
        FROM
            d_secondminutehandledata
        WHERE
            stationBranchId = 533
        AND collectionTime BETWEEN '2022-01-13'
        AND '2023-03-01'
        ORDER BY
            collectionTime DESC
        LIMIT 10000
    ) b ON a.stationBranchId = b.stationBranchId
    AND a.collectionTime = b.collectionTime

     二次侧的数据查询好快

    这就不对劲了,一次侧的数据量好像还要小一点的

    SELECT
        count(1)
    FROM
        d_firstminutehandledata

     但是一次侧数据查询为啥这么慢?

    难道是一次侧表的操作过于频繁?

     又试了一下,这下count快很多,难道是刚巧刚刚操作一次侧的表的代码减少了?

  • 相关阅读:
    数据仓库的直白概述
    Google准实时数据仓库Mesa(一)
    活动预告丨易盾CTO朱浩齐将出席2018 AIIA大会,分享《人工智能在内容安全的应用实践》
    3招搞定APP注册作弊
    【0门槛】PR稿的自我修养
    Hive中文注释乱码解决方案(2)
    Hive中文注释乱码解决方案
    网易考拉Android客户端网络模块设计
    有运气摇号来不及挑选?网易有数帮你科学选房
    selenium下拉框踩坑埋坑
  • 原文地址:https://www.cnblogs.com/LcxSummer/p/16140918.html
Copyright © 2020-2023  润新知