gpt4 book ai didi

mysql - PostgreSQL 9.2 比 MySQL 5.5 慢 10 倍?

转载 作者:行者123 更新时间:2023-11-29 01:06:56 25 4
gpt4 key购买 nike

<分区>

我的笔记本电脑上安装了 PostgreSQL 9.2 和 MySQL 5.5 (InnoDB)。两个数据库引擎都使用默认安装并从同一个 CSV 文件填充。我有 ca 的 'sales_reports' 表。 70 万行。

场景 1:

  • 以下查询:

    select name, year, region, branch from sales_reports group by name, year, region, branch;

  • PostgreSQL 9.2:总查询运行时间:42.14 秒,检索到 18064 行

  • PostgreSQL 解释:
    Group  (cost=165091.16..174275.61 rows=73476 width=58) (actual time=35196.959..41896.739 rows=18064 loops=1)->  Sort  (cost=165091.16..166928.05 rows=734756 width=58) (actual time=35196.956..41704.549 rows=734756 loops=1)    Sort Key: name, year, region, branch    Sort Method: external merge  Disk: 49920kB    ->  Seq Scan on sales_reports  (cost=0.00..38249.56 rows=734756 width=58) (actual time=0.048..282.331 rows=734756 loops=1)Total runtime: 41906.628 ms
  • MySQL 5.5:总查询运行时间:4.4 秒,检索到 18064 行
  • MySQL 解释:
    +----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+| id | select_type | table         | type | possible_keys | key  | key_len | ref  | rows   | Extra                           |+----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+|  1 | SIMPLE      | sales_reports | ALL  | NULL          | NULL | NULL    | NULL | 729433 | Using temporary; Using filesort |+----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+
  • PostgreSQL 慢 10 倍

场景 2:

  • 以下查询:
    select name, year, region, branch, sum(sale) as sale from sales_reports group by name, year, region, branch;
  • PostgreSQL 9.2:总查询运行时间:42.51 秒,检索到 18064 行
  • PostgreSQL 解释:
    GroupAggregate  (cost=165091.16..176847.26 rows=73476 width=64) (actual time=35160.911..42254.060 rows=18064 loops=1)->  Sort  (cost=165091.16..166928.05 rows=734756 width=64) (actual time=35160.489..41857.986 rows=734756 loops=1)    Sort Key: name, year, region, branch    Sort Method: external merge  Disk: 54760kB    ->  Seq Scan on sales_reports  (cost=0.00..38249.56 rows=734756 width=64) (actual time=0.047..296.347 rows=734756 loops=1)Total runtime: 42264.790 ms
  • MySQL 5.5:总查询运行时间:8.15 秒,检索到 18064 行
  • MySQL 解释:
    +----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+| id | select_type | table         | type | possible_keys | key  | key_len | ref  | rows   | Extra                           |+----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+|  1 | SIMPLE      | sales_reports | ALL  | NULL          | NULL | NULL    | NULL | 729433 | Using temporary; Using filesort |+----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+
  • PostgreSQL 慢 5 倍

场景 3:

  • 以下查询:
    select name, year, region, sum(sale) as sale from sales_reports group by name, year, region;
  • PostgreSQL 9.2:总查询运行时间:1 秒,检索到 18064 行
  • PostgreSQL 解释:
    HashAggregate  (cost=45597.12..45655.62 rows=5850 width=37) (actual time=758.396..759.756 rows=4644 loops=1)->  Seq Scan on sales_reports  (cost=0.00..38249.56 rows=734756 width=37) (actual time=0.061..116.541 rows=734756 loops=1)Total runtime: 760.133 ms
  • MySQL 5.5:总查询运行时间:5.8 秒,检索到 18064 行
  • MySQL 解释:
    +----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+| id | select_type | table         | type | possible_keys | key  | key_len | ref  | rows   | Extra                           |+----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+|  1 | SIMPLE      | sales_reports | ALL  | NULL          | NULL | NULL    | NULL | 729433 | Using temporary; Using filesort |+----+-------------+---------------+------+---------------+------+---------+------+--------+---------------------------------+
  • PostgreSQL 快 5 倍

知道为什么前两个场景在 PostgreSQL 上这么慢吗?

顺便说一句,我为我在 PostgreSQL 上的查询中使用的字段创建了索引,我没有在 MySQL 上创建任何索引。

谢谢,

马立克

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com