今天测试一下 1 亿条数据,MySQL 和 PostgreSQL 的性能表现 。说明下 , 只是做一些基本的测试,并没有用一些数据库 Benchmark 工具进行测试 。
准备建表语句:
CREATE TABLE user_mysql / user_postgresql (id SERIAL PRIMARY KEY,username VARCHAR(50),emAIl VARCHAR(100),password VARCHAR(100),first_name VARCHAR(50),last_name VARCHAR(50),address VARCHAR(200),city VARCHAR(50),state VARCHAR(50),zip_code VARCHAR(10),country VARCHAR(50),phone_number VARCHAR(50),date_of_birth DATE,gender VARCHAR(10),occupation VARCHAR(100),education_level VARCHAR(50),registration_date TIMESTAMP,last_login TIMESTAMP,is_active BOOLEAN,is_admin BOOLEAN,additional_field1 VARCHAR(100),additional_field2 VARCHAR(100));
接下来记录一下相关数据 。
1.插入耗时
- MySQL:≈ 67分钟
- PostgreSQL:≈ 55分钟
mydatabase> select count(*) from user_mysql[2023-09-26 22:22:24] 1 row retrieved starting from 1 in 45 s 877 ms (execution: 45 s 767 ms, fetching: 110 ms)
PostgreSQL:8 s 169 ms , 明细如下:postgres.public> select count(*) from user_postgresql[2023-09-26 22:24:08] 1 row retrieved starting from 1 in 8 s 169 ms (execution: 8 s 133 ms, fetching: 36 ms)
文章插图
1亿数据量
3.根据主键查询数据MySQL:47 ms , 明细如下:
mydatabase> select * from user_mysql where id = 19279833[2023-09-26 22:28:10] 1 row retrieved starting from 1 in 47 ms (execution: 16 ms, fetching: 31 ms)
PostgreSQL:46 ms,明细如下:postgres.public> select * from user_postgresql where id = 19279833[2023-09-26 22:29:51] 1 row retrieved starting from 1 in 46 ms (execution: 15 ms, fetching: 31 ms)
4.根据username查询(无索引)MySQL:1 m 56 s 986 ms,明细如下:// 查询第99279833行数据mydatabase> select * from user_mysql where username = '10190439674'[2023-09-26 22:36:09] 1 row retrieved starting from 1 in 1 m 56 s 986 ms (execution: 1 m 56 s 939 ms, fetching: 47 ms)
PostgreSQL:38 s 73 ms,明细如下:// 同样查询第99279833行数据postgres.public> select * from user_postgresql where username = '14998727834'[2023-09-26 22:38:25] 1 row retrieved starting from 1 in 38 s 73 ms (execution: 38 s 18 ms, fetching: 55 ms)
5.创建索引耗时MySQL创建B+TREE索引:5 m 31 s 276 ms,明细如下:mydatabase> ALTER TABLE user_mysql ADD INDEX idx_name (username)[2023-09-26 22:47:37] completed in 5 m 31 s 276 ms
PostgreSQL创建B-TREE索引:9 m 20 s 847 ms,明细如下:postgres.public> CREATE INDEX idx_name ON user_postgresql (username)[2023-09-26 22:57:59] completed in 9 m 20 s 847 ms
6.根据username查询(有索引)MySQL:93 ms,明细如下:// 查询第99279833行数据mydatabase> select * from user_mysql where username = '10190439674'[2023-09-26 23:01:48] 1 row retrieved starting from 1 in 93 ms (execution: 0 ms, fetching: 93 ms)
PostgreSQL:63 ms,明细如下:// 同样查询第99279833行数据postgres.public> select * from user_postgresql where username = '14998727834'[2023-09-26 23:00:07] 1 row retrieved starting from 1 in 63 ms (execution: 0 ms, fetching: 63 ms)
7.根据username修改(有索引)MySQL:16 ms,明细如下:mydatabase> update user_mysql set email='myemail' where username = '10190439674'[2023-09-26 23:06:05] 1 row affected in 16 ms
PostgreSQL:15 ms , 明细如下:postgres.public> update user_postgresql set email='myemail' where username = '14998727834'[2023-09-26 23:07:13] 1 row affected in 15 ms
8.分页查询(不加条件)MySQL:1 m 40 s 265 ms , 明细如下:mydatabase> select * from user_mysql limit 89999980, 20[2023-09-26 23:10:54] 20 rows retrieved starting from 1 in 1 m 40 s 265 ms (execution: 1 m 40 s 234 ms, fetching: 31 ms)
PostgreSQL:27 s 750 ms,明细如下:postgres.public> select * from user_postgresql limit 20 offset 89999980[2023-09-26 23:12:32] 20 rows retrieved starting from 1 in 27 s 750 ms (execution: 27 s 688 ms, fetching: 62 ms)
9.分页查询(加条件 , 条件为索引)MySQL:94 ms,明细如下:mydatabase> select * from user_mysql where id >= 89999980 limit 20[2023-09-26 23:13:34] 20 rows retrieved starting from 1 in 94 ms (execution: 0 ms, fetching: 94 ms)
PostgreSQL:78 ms,明细如下:推荐阅读
- 三个要点,掌握Spring Boot单元测试
- RouterSploit:一款功能强大的嵌入式设备渗透测试框架
- 喝酒后多久才能开车 喝酒后多久才能开车交警测试
- 秋葵该不该焯一下切?吃秋葵的十大禁忌
- 补钙“最快”的食物排行榜,芹菜倒数第1,虾皮第2,不妨了解一下
- 鸽子炖汤要不要过一下水 鸽子炖汤要过一下水吗
- 陈凯歌前妻洪晃被骂惨了!买苹果15手机发文称炫耀一下,评论区沦陷
- 炒花菜要不要用水焯一下
- 身边好听到爆的名字 讨论一下身边好听的名字
- 买的春卷皮要回来蒸一下吗 买的春卷皮要回来蒸一下吗多久