手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Mysql>列表

MySQL两种表存储结构性能比较测试过程

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

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] DB\n"%(db_host,db_user,db_user_passwd,db_name)

if len(argv) > 2:

tableid = argv[1]

testcount = int(argv[2]) #

for test in testtables:

#每次操作前都重写建立数据库连接


try:

mdb = MySQLdb.connect(db_host, db_user, db_user_passwd, db_name)

except MySQLDb.OperationalError,error:

print "Connect MySQL[%s %s/%s %s] DB Error:"%(db_host,db_user,db_user_passwd,db_name),error,"\n"

sys.exit(1)

else:

c = mdb.cursor()

table,autocommit,trans = test

starttime = time.time()

print table," ",time.strftime("%y-%m-%d %H:%M:%S",time.localtime())

if autocommit != None:

AutoCommit(autocommit)

if trans == 1:

BeginTrans()

for i in xrange(testcount):

tablestring = "0d"%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

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!