测试用rust重写的postgresql: pgrust

存储库地址:https://github.com/malisper/pgrust

拉取镜像并运行容器,登录容器。

复制代码
C:\Users\lt>wsl
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker pull docker.1ms.run/malisper/pgrust
Trying to pull docker.1ms.run/malisper/pgrust:latest...
Getting image source signatures
Copying blob 7f391b878ec7 done
Copying blob f8e78f820606 done
Copying blob 18c5c781fe83 done
Copying blob 35c2c72582cc done
Copying blob 68629629b516 done
Copying blob 8b6b9b15108d done
Copying blob c1215e3a97b3 done
Copying blob 443d1ff16955 done
Copying blob 8e8e5cc347ba done
Copying blob 565ad44ed903 done
Copying blob ee7165cce1e9 done
Copying blob d3c88b0da8ce done
Copying blob 324555581bf2 done
Copying config 31bacc34e0 done
Writing manifest to image destination
Storing signatures
31bacc34e0d1c4804e81670e798d69c0a36bf9722df3815ac17c22fffa076185
root@DESKTOP-59T6U68:/mnt/c/Users/lt#

root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker run -itd --name pgrust -e POSTGRES_PASSWORD=secret docker.1ms.run/malisper/
pgrust
d9f9162dc1e4c096fe2061aaa2a48ea0577fdad5e69bee16980876a47564b05a
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker exec -it -e PGPASSWORD=secret pgrust psql -h 127.0.0.1 -U postgres
psql (18.4 (Debian 18.4-1.pgdg12+1), server 18.3)
Type "help" for help.

postgres=# select version();
                              version
-------------------------------------------------------------------
 pgrust 18.3 on x86_64-linux-gnu, compiled by clang-21.0.0, 64-bit
(1 row)

测试分组汇总性能。

复制代码
postgres=# \timing
Timing is on.

postgres=# with t as (select i/10000 a,i%10000 b from generate_series(1,100000)i) select a,sum(b)c from t group by a order by c,a limit 3;
 a  |    c
----+----------
 10 |        0
  0 | 49995000
  1 | 49995000
(3 rows)

Time: 294.691 ms
postgres=# with t as (select i/10000 a,i%10000 b from generate_series(1,1000000)i) select a,sum(b)c from t group by a order by c,a limit 3;
  a  |    c
-----+----------
 100 |        0
   0 | 49995000
   1 | 49995000
(3 rows)

Time: 2313.454 ms (00:02.313)
--也支持表别名(列别名)的写法。
postgres=# with t as (select i/10000 a,i%10000 b from generate_series(1,1000000)t(i)) select a,sum(b)c from t group by a order by c,a limit 3;
  a  |    c
-----+----------
 100 |        0
   0 | 49995000
   1 | 49995000
(3 rows)

Time: 2252.353 ms (00:02.252)

与PostgreSQL 17.7比较。

复制代码
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker start pg177
pg177
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker exec -it pg177 bash
root@b3490d8427cd:/# cd /par
root@b3490d8427cd:/par# psql
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  role "root" does not exist
root@b3490d8427cd:/par# psql -U postgres
psql (17.7 (Debian 17.7-3.pgdg13+1))
Type "help" for help.

postgres=# select version();
                                                      version
--------------------------------------------------------------------------------------------------------------------
 PostgreSQL 17.7 (Debian 17.7-3.pgdg13+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 14.2.0-19) 14.2.0, 64-bit
(1 row)

postgres=# \timing on
Timing is on.
postgres=# with t as (select i/10000 a,i%10000 b from generate_series(1,100000)i) select a,sum(b)c from t group by a order by c,a limit 3;
 a  |    c
----+----------
 10 |        0
  0 | 49995000
  1 | 49995000
(3 rows)

Time: 30.019 ms
postgres=# with t as (select i/10000 a,i%10000 b from generate_series(1,1000000)i) select a,sum(b)c from t group by a order by c,a limit 3;
  a  |    c
-----+----------
 100 |        0
   0 | 49995000
   1 | 49995000
(3 rows)

Time: 166.758 ms
postgres=# with t as (select i/10000 a,i%10000 b from generate_series(1,10000000)i) select a,sum(b)c from t group by a order by c,a limit 3;
  a   |    c
------+----------
 1000 |        0
    0 | 49995000
    1 | 49995000
(3 rows)

Time: 1649.096 ms (00:01.649)
postgres=#

可见,这个版本的pgrust的SQL语法和计算结果正确,但性能比postgresql差很多倍。

相关推荐
yiangL_9 小时前
课后作业4:基于 Python 的古诗词词云可视化(P205)
开发语言·python
geovindu11 小时前
rust: Functional Options Pattern
开发语言·后端·设计模式·rust·函数式选项模式·惯用法型模式
喵个咪12 小时前
RushWind Admin — 模块化单体:一个进程与通往微服务的五级阶梯
后端·架构·rust
skywalk816312 小时前
把「假成功」赶出工具层:lightharness 两天升级复盘(4×5 模式矩阵 + 工具层 5 个缺陷)
开发语言·前端·人工智能·lightharness
敲上瘾12 小时前
Qt控件通用属性:geometry、qrc资源到QSS样式表等
开发语言·c++·qt·ui
喵个咪12 小时前
RushWind CMS — 最小微服务实例:微服务架构的最小完备集
后端·架构·rust
听情歌落俗13 小时前
嵌入式学习1-C语言基础语法与STM32实践
c语言·开发语言
小飞在努力14 小时前
【实现负载均匀在线判题⑤】MVC 架构搭建与 Model 题目数据模块实现
c语言·开发语言·c++·笔记·后端
zhangjw3414 小时前
2-4 集合运算 union /union all /intersect/except
数据库·postgresql
Decay__15 小时前
PostgreSQL DBA 日常运维手册 —— 会话、锁阻塞、慢查询、膨胀与每日巡检
运维·数据库·sql·postgresql