sql> INSERT INTO articles(id, title, body) VALUES (1, 'title', 'body')
[2017-02-11 19:54:53] 1 row affected in 9ms
sql> SELECT * FROM articles WHERE id = 1
[2017-02-11 19:54:56] 1 row retrieved starting from 1 in 14ms
(execution: 7ms, fetching: 7ms)
sql> UPDATE articles SET title = 'new_title'
[2017-02-11 19:54:59] 1 row affected in 13ms
sql> DELETE FROM articles WHERE id = 1
[2017-02-11 19:55:01] 1 row affected in 13ms
sql> SELECT COUNT(*) as count FROM articles WHERE id = 1
[2017-02-11 19:57:21] 1 row retrieved starting from 1 in 18ms (execution: 12ms, fetching: 6ms)
sql> SELECT max(id) as count FROM articles WHERE id = 1
[2017-02-11 19:57:49] 1 row retrieved starting from 1 in 30ms (execution: 9ms, fetching: 21ms)
。。。。没有可比性啊
为什么聚合要和增查改一起比较呢
有可比性吗?
很有意思的问题,一直以来,我们都知道:
查询: 主键查询最快,索引查询次之,where条件中有函数再次之;扫描行数越少越快。
插入:根据索引数量,索引越多插入越慢。插入行数越多越慢,因为会导致重建索引。
删除:行数越多越慢,索引数量越多越慢,因为会导致重建索引
更新:同删除,因为索引列数据改变会导致重建索引
但是以上这些,都是我们从教科书中得到的经验。在座的有几个真正去测试过这些经验呢?
我们来做个试验,下面是对1条数据做的增删改查统计测试
插入:9 ms
查询:7 ms
更新:13 ms
删除:13 ms
统计:9、12 ms
因为数据量小。所以几乎看不出实质差别,且测试结果可能因为主机繁忙程度而产生误差。
所以我们需要用更多的数据,才能得出实实在在的无可辩驳的数据。
下面,我们用1W条数据来测试