数据库冗余存储设计对读取性能影响的测试

两张表

CREATE TABLE `test1` (
  `a` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `b` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `c` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `d` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `e` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `f` varchar(100) NOT NULL DEFAULT '0',
  `g` varchar(100) NOT NULL DEFAULT '',
  `h` varchar(100) NOT NULL DEFAULT '',
  `i` mediumint(8) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=1000001 DEFAULT CHARSET=utf8
CREATE TABLE `test2` (
  `i` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `j` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `k` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `l` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `m` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `n` varchar(100) NOT NULL DEFAULT '0',
  `o` varchar(100) NOT NULL DEFAULT '',
  `p` varchar(100) NOT NULL DEFAULT '',
  PRIMARY KEY (`i`)
) ENGINE=InnoDB AUTO_INCREMENT=1000001 DEFAULT CHARSET=utf8

使用存储过程各自填充100万条数据,使两张表的数据长度均达到约230MB

CREATE DEFINER=`root`@`localhost` PROCEDURE `test`.`my_test_data`()
begin
 declare i int;
 declare ss char(100);
    set i=100001;
    while(i<=1000000) do
    
    	set ss=concat(md5(rand()*16777015), md5(rand()*16777015));
    
        INSERT INTO test.test1 
        (b, c, d, e, f, g, h, i) 
        VALUES( rand()*16777015, rand()*16777015, rand()*16777015, rand()*16777015, ss, concat(md5(rand()*16777015), md5(rand()*16777015)), concat(md5(rand()*16777015), md5(rand()*16777015)), i);

        INSERT INTO test.test2 
        (j, k, l, m, n, o, p)
        VALUES( rand()*16777015, rand()*16777015, rand()*16777015, rand()*16777015, ss, concat(md5(rand()*16777015), md5(rand()*16777015)), concat(md5(rand()*16777015), md5(rand()*16777015)));
       
        set i=i+1;
    end while;
end

然后使用mysqlslap分别压测两天SQL语句

第一条:

select d, e from test1;

第二条:

select test2.l, test2.m from test1 inner join test2 on test1.i = test2.i;

命令:

mysqlslap.exe -h127.0.0.1 -uroot -p --concurrency=2 --iterations=1 --create-schema=test --query=D:\logs\wwj.sql --engine=innodb --number-of-queries=100

结果:

第一条sql:

Benchmark
        Running for engine innodb
        Average number of seconds to run all queries: 43.953 seconds
        Minimum number of seconds to run all queries: 43.953 seconds
        Maximum number of seconds to run all queries: 43.953 seconds
        Number of clients running queries: 2
        Average number of queries per client: 50

第二条sql:

Benchmark
        Running for engine innodb
        Average number of seconds to run all queries: 202.594 seconds
        Minimum number of seconds to run all queries: 202.594 seconds
        Maximum number of seconds to run all queries: 202.594 seconds
        Number of clients running queries: 2
        Average number of queries per client: 50

可以看到反范式设计使读取性能提高到范式设计的5倍。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值