数据库有100万条数据,至于怎么插入,参看前一篇文章。
执行简单一句:select * from cardtotalinfo where networkid=1004
需要15.11秒
没有建索引,有主键为自增id。
在networkid建立索引:
CREATE INDEX idx_cardtotalinfo_networkid ON cardtotalinfo(networkid);
更新表
update cardtotalinfo set purchaseprice = 12 where networkid=1004
受影响的行: 93
时间: 0.953秒
查询表
select * from cardtotalinfo where networkid=1004
受影响的行: 0
时间: 0.000秒
插入表
INSERT INTO `cardtotalinfo`(`code`,`companyid`, `faceprice`,`purchaseprice` ,`purchasetime` ,`networkid`,`isfirst` , `sendtime`, `issaled`,`saletime` ,`networkmoney` ,`nwmoneytime` , `isspended`,`companymoney` , `cpmoneytime`) VALUES ('ADFE3993', '1', '10.5', '6', '2011-11-30 12:43:03', '1004', '', '2011-11-30 12:43:12', '', '2011-11-30 12:43:19', '7', '2011-11-30 12:43:29', '', '6', '2011-11-30 12:43:37');
受影响的行: 1
时间: 0.062秒
删除表记录
delete from cardtotalinfo where networkid=1004
受影响的行: 95
时间: 0.078秒
再建立一个索引
CREATE INDEX idx_cardtotalinfo_companyid ON cardtotalinfo(companyid);
花费5分50秒。
查询
select * from cardtotalinfo where companyid=734
受影响的行: 0
时间: 7.781秒
1011条记录
select * from cardtotalinfo where networkid=5566
受影响的行: 0
时间: 0.578秒
92条记录
select * from cardtotalinfo where companyid=734 and networkid = 2045
时间: 0.047秒
31条记录
看来查询效率和返回的记录条数有关系
select * from cardtotalinfo where companyid=794 and code = 'Abc13'
时间: 7.250秒
91条记录
select * from (
select * from cardtotalinfo where companyid=384 ) as c
where code = 'Abc13'
时间: 6.719秒
91条记录
看来where条件的字段不建索引,怎么查都慢