对比视频1:https://www.bilibili.com/video/BV1sU4y14741/
对比视频2:https://www.bilibili.com/video/BV1mf4y1k7mb/
MySQL 配置文件my.cnf
PostgreSQL 配置文件postgres.conf
机器:Macbook Air M1 16G+512G
- MySQL
create table log_access
(
id varchar(40) default (uuid()) not null primary key,
v_method varchar(10),
v_uri varchar(200),
v_ip varchar(15),
i_status integer,
v_type varchar(2),
v_browser varchar(20),
b_success boolean,
v_application varchar(10),
v_data_id varchar(80),
v_alias_at_app_module varchar(30),
v_alias_at_app_module_function varchar(45),
b_skip boolean,
id_at_auth_user varchar(40),
t_create timestamp,
v_body varchar(70),
id_at_app_module varchar(40),
v_device varchar(10)
);
- PostgreSQL
create table log_access
(
id varchar default gen_random_uuid() not null primary key,
v_method varchar,
v_uri varchar,
v_ip varchar,
i_status integer,
v_type varchar,
v_browser varchar,
b_success boolean,
v_application varchar,
v_data_id varchar,
v_alias_at_app_module varchar,
v_alias_at_app_module_function varchar,
b_skip boolean,
id_at_auth_user varchar,
t_create timestamp,
v_body varchar,
id_at_app_module varchar,
v_device varchar
);
id | v_method | v_uri | v_ip | i_status | v_type | v_browser | b_success | v_application | v_data_id | v_alias_at_app_module | v_alias_at_app_module_function | b_skip | id_at_auth_user | t_create | v_body | id_at_app_module | v_device |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
bba5ef6a_76cf_4811_a5dd_182ceaf51a15 | GET | /api/platform/dictcategory/view/CARRIER_UNIT/children/app_dict | 0:0:0:0:0:0:0:1 | 200 | 06 | Chrome 8 | true | platform | CARRIER_UNIT | dictcategory | view | true | b66f83d8_e87c_4fe9_bec6_357bd2e998bd | 2020-12-02 16:10:56.629945 | NULL | 179b0a11_94c9_41bb_a788_79a99f6096e7 | PC |
648a04ca_8e13_4c63_9fea_8fa69308217c | GET | /api/szda/lendMnt/lendView | 0:0:0:0:0:0:0:1 | 200 | 06 | Chrome 8 | true | szda | NULL | lendMnt | lendView | true | b66f83d8_e87c_4fe9_bec6_357bd2e998bd | 2020-12-02 16:11:00.161490 | NULL | 53a8e8ee_98ee_4e32_8425_4042891d5b20 | PC |
d7fb3d8a_da8d_4699_8c54_e2a37329a128 | GET | /api/szda/digitalArchive/detailView | 0:0:0:0:0:0:0:1 | 200 | 06 | Chrome 8 | true | szda | NULL | digitalArchive | detailView | true | b66f83d8_e87c_4fe9_bec6_357bd2e998bd | 2020-12-02 16:12:28.795853 | NULL | 457338e5_abe8_44fd_aa78_01f789e47289 | PC |
285077fc_0c4d_43bf_bf91_51dd4fb60bb9 | GET | /api/msg/app/inBox/b66f83d8_e87c_4fe9_bec6_357bd2e998bd | 0:0:0:0:0:0:0:1 | 200 | 06 | Chrome 8 | true | msg | b66f83d8_e87c_4fe9_bec6_357bd2e998bd | app | inBox | true | b66f83d8_e87c_4fe9_bec6_357bd2e998bd | 2020-12-02 16:13:26.954893 | NULL | NULL | PC |
483e8486_c340_40f6_bc87_5ea7afa302aa | GET | /api/platform/dictcategory/view/SECRET_LEVEL/children/app_dict | 0:0:0:0:0:0:0:1 | 200 | 06 | Chrome 8 | true | platform | SECRET_LEVEL | dictcategory | view | true | b66f83d8_e87c_4fe9_bec6_357bd2e998bd | 2020-12-02 16:13:27.138294 | NULL | 179b0a11_94c9_41bb_a788_79a99f6096e7 | PC |
-
仅主键存在情况下,count(*)全表
select count(*) from log_access; # 返回结果为128000000
时间 MySQL 02:42 PostgreSQL 01:37 -
对
v_method
创建索引时间create index log_access_v_method_index on log_access (v_method);
时间 索引大小 MySQL 10:44 6722MB PostgreSQL 00:58 846MB -
有
v_method
索引后,count(*)全表select count(*) from log_access; # 返回结果为128000000
时间 MySQL 02:41 PostgreSQL 00:01.507 -
有
v_method
索引后,对v_method
加条件,再count(*)select count(*) from log_access where v_method = 'GET'; # 返回结果为113032192
时间 MySQL 19.72s PostgreSQL 1.39s select count(*) from log_access where v_method != 'GET'; # 返回结果为14964736
时间 MySQL 2.49s PostgreSQL 1.8s select count(*) from log_access where v_method not in ('GET', 'PUT'); # 返回结果为14948608
时间 MySQL 3.52s PostgreSQL 2.6s select * from log_access where v_method is null;
时间 MySQL 0.9s PostgreSQL 0.19s -
创建组合索引
create index log_access_v_method_i_status_v_device_index on log_access (v_method, i_status, v_device);
时间 MySQL 13:24 PostgreSQL 02:26 -
对组合索引的使用
select * from log_access where v_method = 'POST' and i_status = 516 and v_device = 'Android';
时间 MySQL 0.763s PostgreSQL 0.164s select * from log_access where i_status = 516 and v_device = 'Android';
时间 MySQL 385.9s PostgreSQL 1.0s select v_device, count(*) from log_access group by v_device;
时间 MySQL 45s PostgreSQL 5s