MySQL两种表存储结构MyISAM和InnoDB的性能比较测试

2019-01-03 13:42:10王冬梅
        if autocommit != None:
            AutoCommit(autocommit)

        if trans == 1:
            BeginTrans()
        for i in xrange(testcount):
            tablestring = "%020d"%i
            if (AddTable(table,tableid,tablestring)<1):
                print "AddTable Error",tablestring

        if trans == 1:
            Commit()

        print time.strftime("%y-%m-%d %H:%M:%S",time.localtime())
        endtime = time.time()
        usedtime = endtime-starttime
        print table,"count:",getcount(table)," used time:",usedtime
        c.close()
        mdb.close()

if __name__ == '__main__':
    main()
测试结果如下:

Config:[localhost root/ demo] DB
MyISAM_NT   04-10-22 16:33:24
04-10-22 16:33:26
MyISAM_NT count: 10000  used time: 2.1132440567
MyISAM_TS   04-10-22 16:33:26
ExecSQL:BEGIN;
ExecSQL:COMMIT;
04-10-22 16:33:29
MyISAM_TS count: 10000  used time: 2.65475201607
INNODB_NA_NB   04-10-22 16:33:29
ExecSQL:Set AUTOCOMMIT = 0
04-10-22 16:33:31
INNODB_NA_NB count: 10000  used time: 2.51947999001
INNODB_NA_BE   04-10-22 16:33:31
ExecSQL:Set AUTOCOMMIT = 0
ExecSQL:BEGIN;
ExecSQL:COMMIT;
04-10-22 16:33:35
INNODB_NA_BE count: 10000  used time: 3.85625100136
INNODB_AU_NB   04-10-22 16:33:35
ExecSQL:Set AUTOCOMMIT = 1
04-10-22 16:34:19
INNODB_AU_NB count: 10000  used time: 43.7153041363
INNODB_AU_BE   04-10-22 16:34:19
ExecSQL:Set AUTOCOMMIT = 1
ExecSQL:BEGIN;
ExecSQL:COMMIT;
04-10-22 16:34:22
INNODB_AU_BE count: 10000  used time: 3.14328193665
结论:
由此得知影响速度的主要原因是AUTOCOMMIT默认设置是打开的,
我当时的程序没有显式调用BEGIN;开始事务,导致每插入一条都自动Commit,严重影响了速度。
算来也是个低级错误!
相关参考:
http://dev.mysql.com/doc/mysql/en/COMMIT.html
http://dev.mysql.com/doc/mysql/en/InnoDB_and_AUTOCOMMIT.html

您可能感兴趣的文章:

mysql更改引擎(InnoDB,MyISAM)的方法MySQL存储引擎中的MyISAM和InnoDB区别详解浅谈MySQL存储引擎选择 InnoDB与MyISAM的优缺点分析MySQL数据库修复方法(MyISAM/InnoDB)将MySQL从MyISAM转换成InnoDB错误和解决办法MySQL存储引擎 InnoDB与MyISAM的区别MySQL从MyISAM转换成InnoDB错误与常用解决办法mysql 中InnoDB和MyISAM的区别分析小结浅谈MyISAM 和 InnoDB 的区别与优化使用Python如何测试InnoDB与MyISAM的读写性能
相关文章 大家在看