自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

又一個選擇PostgreSQL的理由:單表1億性能對比

數(shù)據(jù)庫 MySQL PostgreSQL
今天測試一下 1 億條數(shù)據(jù),MySQL 和 PostgreSQL 的性能表現(xiàn)。說明下,只是做一些基本的測試,并沒有用一些數(shù)據(jù)庫 Benchmark 工具進(jìn)行測試。

今天測試一下 1 億條數(shù)據(jù),MySQL 和 PostgreSQL 的性能表現(xiàn)。說明下,只是做一些基本的測試,并沒有用一些數(shù)據(jù)庫 Benchmark 工具進(jìn)行測試。

準(zhǔn)備

建表語句:

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)
);

接下來記錄一下相關(guān)數(shù)據(jù)。

1.插入耗時

  • MySQL:≈ 67分鐘
  • PostgreSQL:≈ 55分鐘

2.count(*)耗時

MySQL:45 s 877 ms,明細(xì)如下:

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,明細(xì)如下:

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億數(shù)據(jù)量1億數(shù)據(jù)量

3.根據(jù)主鍵查詢數(shù)據(jù)

MySQL:47 ms,明細(xì)如下:

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,明細(xì)如下:

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.根據(jù)username查詢(無索引)

MySQL:1 m 56 s 986 ms,明細(xì)如下:

// 查詢第99279833行數(shù)據(jù)
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,明細(xì)如下:

// 同樣查詢第99279833行數(shù)據(jù)
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.創(chuàng)建索引耗時

MySQL創(chuàng)建B+TREE索引:5 m 31 s 276 ms,明細(xì)如下:

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創(chuàng)建B-TREE索引:9 m 20 s 847 ms,明細(xì)如下:

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.根據(jù)username查詢(有索引)

MySQL:93 ms,明細(xì)如下:

// 查詢第99279833行數(shù)據(jù)
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,明細(xì)如下:

// 同樣查詢第99279833行數(shù)據(jù)
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.根據(jù)username修改(有索引)

MySQL:16 ms,明細(xì)如下:

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,明細(xì)如下:

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,明細(xì)如下:

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,明細(xì)如下:

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,明細(xì)如下:

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,明細(xì)如下:

postgres.public> select * from user_postgresql where id >= 89999980 limit 20
[2023-09-26 23:14:12] 20 rows retrieved starting from 1 in 78 ms (execution: 0 ms, fetching: 78 ms)

總結(jié)

在數(shù)據(jù)量達(dá)到1億時,數(shù)據(jù)庫操作的開銷都會比較大,尤其是不走索引的操作和DDL操作等。因此在生產(chǎn)環(huán)境時,不建議數(shù)據(jù)量太大,數(shù)據(jù)庫特別大的情況下,建議使用更強(qiáng)大的數(shù)據(jù)庫,不建議分表分庫。對大表進(jìn)行DDL操作時也需要謹(jǐn)慎操作。

聲明:這些數(shù)據(jù)均為本機(jī)測試,并未用專業(yè)測試軟件測試,僅供參考。

責(zé)任編輯:華軒 來源: 今日頭條
相關(guān)推薦

2022-02-06 20:55:39

jsEsbuild項目

2020-02-18 20:28:23

AI人工智能

2023-05-14 23:38:43

Glarity用戶視頻

2014-10-11 09:15:36

2022-11-30 10:59:20

2013-03-14 09:37:28

希捷里程碑硬盤

2012-04-12 09:53:02

2017-08-31 10:32:35

交付技術(shù)

2021-12-29 18:18:59

開源MedusaShopify

2021-01-29 09:07:39

數(shù)據(jù)保護(hù)信息安全數(shù)據(jù)隱私

2009-04-22 15:16:30

2011-08-16 17:36:50

SolarisIllumos

2014-12-01 12:57:46

亞馬遜天貓海淘

2012-06-25 10:20:22

敏捷開發(fā)

2018-09-30 08:00:15

區(qū)塊鏈碳排放氣候

2009-08-17 08:54:56

2015-07-09 14:41:15

2020-07-23 08:24:14

CSS偽類選擇器

2022-07-27 12:07:58

云計算公有云云支出

2021-08-19 09:44:44

SGX1 內(nèi)核SGX
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號