zoukankan      html  css  js  c++  java
  • MySQL分区实验

    环境 CentOS5.5,内存256MB,MySQL5.5.16

    一、创建测试表

    CREATE TABLE part_tab(
        c1 INT DEFAULT NULL,
        c2 VARCHAR(30) DEFAULT NULL,
        c3 DATE DEFAULT NULL
    ) ENGINE=myisam CHARSET=utf8
    partition by RANGE(YEAR(c3))(
    partition p0 values less than(1995),
    partition p1 values less than(1996),
    partition p2 values less than(1997),
    partition p3 values less than(1998),
    partition p4 values less than(1999),
    partition p5 values less than(2000),
    partition p6 values less than(2001),
    partition p7 values less than(2002),
    partition p8 values less than(2003),
    partition p9 values less than(2004),
    partition p10 values less than(2010),
    partition p11 values less than MAXVALUE)
    CREATE TABLE `no_part_tab` (
      `c1` int(11) DEFAULT NULL,
      `c2` varchar(30) DEFAULT NULL,
      `c3` date DEFAULT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

    二、创建测试数据

    CREATE PROCEDURE `p1`()
    begin
        declare v int default 0;
        while v<8000000 do
        insert into part_tab values (v,'testing partition',adddate('1995-01-01',(rand(v)*36520) mod 3652));
        set v=v+1;
        end while;
    end

      call p1;

      insert into no_part_tab select * from part_tab

    三、测试

      select count(*) from part_tab where c3>date '1995-01-01' and c3< date '1995-12-31';  #1.875s

      select count(*) from no_part_tab where c3>date '1995-01-01' and c3< date '1995-12-31';  #9.269s

    四、分析

      desc select count(*) from part_tab where c3>date '1995-01-01' and c3< date '1995-12-31' G;

      

      desc select count(*) from no_part_tab where c3>date '1995-01-01' and c3< date '1995-12-31' G;

      

      可以看出慢的原因了

    五、创建索引再测试

      create index idx_of_c3 on part_tab(c3);

      create index idx_of_c3 on no_part_tab(c3);

      select count(*) from no_part_tab where c3>date '1995-01-01' and c3< date '1995-12-31';  #1.49s

      select count(*) from part_tab where c3>date '1995-01-01' and c3< date '1995-12-31';    #1.48s

      查询时间差不多,分析图就想想就知道样子了

    六、使用未索引字段查询

      select count(*) from no_part_tab where c3>date '1995-01-01' and c3< date '1996-12-31' and c2='hello';  #12.274s

      select count(*) from part_tab where c3>date '1995-01-01' and c3< date '1996-12-31' and c2='hello';    #2.74s

    七、分析

      

      

    八、总结

      在数据量较大的情况 使用被作为查询条件较频繁的字段 作为分区的依据。

  • 相关阅读:
    《Android Studio有用指南》4.27 使用演示模式
    深度学习与计算机视觉系列(9)_串一串神经网络之动手实现小样例
    银行业务调度系统的实现
    高通平台读写nv总结【转】
    LTE-A 载波聚合(Carrier Aggregation)介绍【转】
    DSDS,双模,双卡,双待,单待,双通,单通,概念及相互关系?【转】
    【LTE基础知识】SGLTE, SVLTE, CSFB, VoLTE【转】
    SRLTE,SGLTE,SVLTE,CSFB,VoLTE的区别【转】
    高通计划停用MSM 以SDM为移动平台命名【转】
    高通平台文档下载【学习笔记】
  • 原文地址:https://www.cnblogs.com/hwt987/p/3677237.html
Copyright © 2011-2022 走看看