MySQL两种表存储结构性能比较测试过程
2008-12-19 11:16:28 来源:WEB开发网4、InnoDB关闭AutoCommit,用事务:
CREATE TABLE `INNODB_NA_BE` (
`TableId` int(11) NOT NULL default '0',
`TableString` varchar(21) NOT NULL default ''
) ENGINE=InnoDB;
5、InnoDB开启AutoCommit,不用事务:
CREATE TABLE `INNODB_AU_NB` (
`TableId` int(11) NOT NULL default '0',
`TableString` varchar(21) NOT NULL default ''
) ENGINE=InnoDB;
6、InnoDB开启AutoCommit,用事务:
CREATE TABLE `INNODB_AU_BE` (
`TableId` int(11) NOT NULL default '0',
`TableString` varchar(21) NOT NULL default ''
) ENGINE=InnoDB;
测试的Python脚本如下:
#!/usr/bin/env Python
'''
MyISAM,InnoDB性能比较
作者:空心菜(Invalid)
时间:2004-10-22
'''
import MySQLdb
import sys
import os
import string
import time
c = None
testtables = [("MyISAM_NT",None,0),
("MyISAM_TS",None,1),
("INNODB_NA_NB",0,0),
("INNODB_NA_BE",0,1),
("INNODB_AU_NB",1,0),
("INNODB_AU_BE",1,1)
]
def BeginTrans():
print "ExecSQL:BEGIN;"
c.execute("BEGIN;")
return
def Commit():
print "ExecSQL:COMMIT;"
c.execute("COMMIT;")
return
def AutoCommit(flag):
print "ExecSQL:Set AUTOCOMMIT = "+str(flag)
c.execute("Set AUTOCOMMIT = "+str(flag))
return
def getcount(table):
#print "ExecSQL:select count(*) from "+table
c.execute("select count(*) from "+table)
return c.fetchall()[0][0]
def AddTable (Table,TableId,TableString):
sql = "INSERT INTO "+Table+"(TableId, TableString) VALUES( "+ TableId+ ",'" + TableString +"')"
try:
c.execute(sql)
except MySQLdb.OperationalError,error:
print "AddTable Error:",error
return -1;
return c.rowcount
def main():
argv = sys.argv
if len(argv) < 2:
print 'Usage:',argv[0],' TableId TestCount n'
sys.exit(1)
global c #mysql访问cursor
db_host = "localhost"
db_name = "demo"
db_user = "root"
db_user_passwd = ""
print "Config:[%s %s/%s %s] DBn"%(db_host,db_user,db_user_passwd,db_name)
if len(argv) > 2:
tableid = argv[1]
testcount = int(argv[2]) #
for test in testtables:
更多精彩
赞助商链接