PostgreSQL , HTAP , OLTP , OLAP , 場景與性能測試

PostgreSQL社群的貢獻者衆多,來自全球各個行業,曆經數年,PostgreSQL 每年釋出一個大版本,以持久的生命力和穩定性著稱。
2017年10月,PostgreSQL 推出10 版本,攜帶諸多驚天特性,目标是勝任OLAP和OLTP的HTAP混合場景的需求:
<a href="https://github.com/digoal/blog/blob/master/201710/20171029_01.md">《最受開發者歡迎的HTAP資料庫PostgreSQL 10特性》</a>
1、多核并行增強
2、fdw 聚合下推
3、邏輯訂閱
4、分區
5、金融級多副本
6、json、jsonb全文檢索
7、還有插件化形式存在的特性,如 向量計算、JIT、SQL圖計算、SQL流計算、分布式并行計算、時序處理、基因測序、化學分析、圖像分析 等。
在各種應用場景中都可以看到PostgreSQL的應用:
PostgreSQL近年來的發展非常迅猛,從知名資料庫評測網站dbranking的資料庫評分趨勢,可以看到PostgreSQL向上發展的趨勢:
從每年PostgreSQL中國召開的社群會議,也能看到同樣的趨勢,參與的公司越來越多,分享的公司越來越多,分享的主題越來越豐富,橫跨了 傳統企業、網際網路、醫療、金融、國企、物流、電商、社交、車聯網、共享XX、雲、遊戲、公共交通、航空、鐵路、軍工、教育訓練、咨詢服務等 行業。
接下來的一系列文章,将給大家介紹PostgreSQL的各種應用場景以及對應的性能名額。
環境部署方法參考:
<a href="https://github.com/digoal/blog/blob/master/201710/20171018_01.md">《PostgreSQL 10 + PostGIS + Sharding(pg_pathman) + MySQL(fdw外部表) on ECS 部署指南(适合新使用者)》</a>
阿裡雲 ECS:<code>56核,224G,1.5TB*2 SSD雲盤</code>。
作業系統:<code>CentOS 7.4 x64</code>
資料庫版本:<code>PostgreSQL 10</code>
PS:ECS的CPU和IO性能相比實體機會打一定的折扣,可以按下降1倍性能來估算。跑實體主機可以按這裡測試的性能乘以2來估算。
not in 查詢,多用在排除多個輸入值場景。
實際上PostgreSQL支援很多種排除多個輸入值的文法。
1、<code>not in (...)</code>
2、<code>not in (table or subquery or srf)</code>
3、<code><> all (array)</code>
4、<code>not exists (select 1 from (values (),(),...) as t(id) where x.?=t.id)</code>
5、<code><>? and <>? and <>? and .....</code>
6、<code>left join others b on (a.?=b.?) where b.* is null</code>
7、<code>select ? from a except select ? from b</code>,适用于輸出字段與條件字段相同的情形。
他們的執行計劃分别如下,(1億記錄,排除多個輸入值。):
表越大、或Filter的值越多,使用 left join, not exist, except 的效果越好。
1億記錄,查詢比對多個輸入值的性能。分别輸入1,10,100,1000,10000,100000,1000000個值作為比對條件。
1,10,100,1000,10000,100000,1000000 個輸入值的測試性能
6、<code>a left join others b on (a.?=b.?) where b.* is null</code>
<a href="https://github.com/digoal/blog/blob/master/201706/20170601_02.md">《PostgreSQL、Greenplum 應用案例寶典《如來神掌》 - 目錄》</a>
<a href="https://github.com/digoal/blog/blob/master/201702/20170209_01.md">《資料庫選型之 - 大象十八摸 - 緻 架構師、開發者》</a>
<a href="https://github.com/digoal/blog/blob/master/201610/20161031_02.md">《PostgreSQL 使用 pgbench 測試 sysbench 相關case》</a>
<a href="https://github.com/digoal/blog/blob/master/201701/20170125_01.md">《資料庫界的華山論劍 tpc.org》</a>
<a href="https://www.postgresql.org/docs/10/static/pgbench.html">https://www.postgresql.org/docs/10/static/pgbench.html</a>