当前位置:数码通 > 软件

PostgreSQL [9.5.0] vs MariaDB [10.1.11] vs MySQL 性能比较

来源于 数码通 2023-09-28 22:23

在 2015年12月的时候我做了一个类似的性能测试,但是在这个测试中我犯了一些错误,导致结果相对于 MySQL 来说是不公平的。

所以我对之前那个性能测试做了改进,新的测试脚本和安装方法请看 Github Repo.

注意事项以及 FAQ

  • 为什么使用默认的数据库配置 / 为什么不同数据库的配置是不同的:
    • 该测试使用默认的配置,并通过 Docker 映像的方式提供
    • 消耗时间用于标准化数据库配置
    • 默认配置提供了一个最基础的建议
  • 为什么没有对索引进行测试,包括数据传输时间等:
    • 这在待办列表中
    • 或许你可以增强一下我的这个脚本 script.
  • 为什么在 VM 中运行,这会导致测试不那么可靠
    • 不想花费额外的钱来购买物理机或者云主机
    • 让测试去中心化,有笔记本就可以运行测试
    • 让开发者对数据库执行过程有个粗略的认识

测试环境 (Vagrant)

  • Ubuntu wily werewolf (15.10)
  • 1 core CPU, 100% execution cap
  • 1024 MB memory

测试环境 (Docker)

  • mariadb:10.1.11
  • mysql:5.7.10
  • postgres:9.5.0

测试详情

完整详情请看 this Github Repo Folder

Total Rows: 1 million

Queries:

  1. SELECT * FROM testing LIMIT 1000
  2. SELECT * FROM testing WHERE int_col > 5000 LIMIT 1000
  3. SELECT * FROM testing WHERE int_col + int_col2 > 12345
  4. SELECT COUNT(*) FROM testing WHERE int_col + int_col2 > 12345
  5. SELECT * FROM testing WHERE int_col > 5000 ORDER BY word_col ASC LIMIT 1000
  6. SELECT * FROM testing WHERE word_col LIKE '%lim%' ORDER BY word_col DESC LIMIT 1000

MariaDB Summary:

average write time: 50.02ms/10000rows
average query time (q1): 3.87ms
average query time (q2): 4.36ms
average query time (q3): 5.18ms
average query time (q4): 261.69ms
average query time (q5): 741.55ms
average query time (q6): 639.75ms

MySQL Summary:

average write time: 50.86ms/10000rows
average query time (q1): 3.42ms
average query time (q2): 3.91ms
average query time (q3): 5.33ms
average query time (q4): 246.77ms
average query time (q5): 6686.11ms
average query time (q6): 508.9ms

PostgreSQL Summary:

average write time: 79.2ms/10000rows
average query time (q1): 3.27ms
average query time (q2): 3.62ms
average query time (q3): 4.0ms
average query time (q4): 169.18ms
average query time (q5): 229.33ms
average query time (q6): 207.01ms

结论

  • MariabDB & MySQL 数据库在写操作上有微弱优势
  • PostgreSQL 在简单的数据库读查询上有微弱优势
  • PostgreSQL 在复杂的数据库度查询上优势明显

因此,我认为 PostgreSQL 是更好的选择。

登录后参与评论