zoukankan      html  css  js  c++  java
  • Mysql的分页查询优化

    先创建一个数据库test, 再建立一个表格devices,(这里建立多个字段来演示效果)

    CREATE TABLE `devices`  (
      `id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
      `TVName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `TVModelNumber` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `TVSerialNumber` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `TVRoomID` int(11) DEFAULT NULL,
      `TVMACAddress` varchar(17) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `TVIPAddress` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `VSecureTVID` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `Type` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `PowerStatus` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `TVUniqueID` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `FirmwareId` int(11) DEFAULT NULL,
      `CloneId` int(11) DEFAULT NULL,
      `LastCloneRename` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '{"old":"Unknown","new":"Unknown"}',
      `Status` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `Progress` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `TVStatus` text CHARACTER SET utf8 COLLATE utf8_general_ci,
      `si_clone_Identifiers` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `si_firmware_Identifier` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `tv_clone_Identifiers` varchar(8000) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `tv_firmware_Identifier` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `success_siclone_Identifier` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `success_tvclone_Identifier` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `clone_color` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT 'black',
      `fw_color` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT 'black',
      `CreatedDate` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `ModifiedDate` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `Lastonline` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `clone_mode` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'Upgrade',
      `upload_progress` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT 'ST',
      `upload_session_id` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `upload_session_start` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `upload_session_end` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `upload_session_status` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `channel_color` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `app_color` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `upgrade_type` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `si_Identifiers` text CHARACTER SET utf8 COLLATE utf8_general_ci,
      `networkInterfaceIp` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
      `clone_type` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT 'None',
      PRIMARY KEY (`id`) USING BTREE,
      INDEX `FirmwareId`(`FirmwareId`) USING BTREE,
      INDEX `CloneId`(`CloneId`) USING BTREE
    ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;

    我这里想这个表devices里面添加了8000条数据.

    SELECT * FROM `devices` limit 7000,10   #0.015s这里消耗的时间是0.015s

    select * from `devices` where id > (select id from devices limit 7000,1) limit 10 #0.002s这里消耗的时间是0.002s

    同样的分页查询, 消耗时间不一样


    待续…

  • 相关阅读:
    FPM
    Docker记录
    阿里云ECS发送企业邮件
    git操作
    vscode+vagrant+xdebug调试
    Spring Security开发安全的REST服务
    559. Maximum Depth of N-ary Tree
    《算法图解》之散列表
    766. Toeplitz Matrix
    893. Groups of Special-Equivalent Strings
  • 原文地址:https://www.cnblogs.com/xumBlog/p/12708281.html
Copyright © 2011-2022 走看看