PostgreSQL10.0preview效能增強-分割槽表效能增強(plan階段加速)
標籤
PostgreSQL , 10.0 , 分割槽表 , 子表 , 元資訊搜尋效能增強
背景
PostgreSQL 10.0 增強了分割槽表的子表搜尋效能,對於涉及分割槽表包含子表特別多的QUERY,可以提升效能。
效能分析
get_tabstat_entry, find_all_inheritors成為主要瓶頸。
Hello.
I decided to figure out whether current implementation of declarative
partitioning has any bottlenecks when there is a lot of partitions. Here
is what I did [1].
-- init schema
iming on
CREATE TABLE part_test (pk int not null, k int, v varchar(128)) PARTITION BY RANGE(pk);
do $$
declare
i integer;
begin
for i in 1 .. 10000
loop
raise notice `i = %`, i;
execute (`CREATE TABLE part_test_` || i ||
` PARTITION OF part_test FOR VALUES FROM (` ||
(1 + (i-1)*1000) || `) to (` || ( (i * 1000) + 1) || `);`
);
end loop;
end $$;
-- fill tables with some data
do $$
declare
i integer;
begin
for i in 1 .. 100*1000
loop
raise notice `i = %`, i;
execute (`insert into part_test values ( ceil(random()*(10000-1)*1000), ceil(random()*10000*1000), ```` || ceil(random()*10000*1000) );`);
end loop;
end $$;
Then:
# 2580 is some pk that exists
echo `select * from part_test where pk = 2580;` > t.sql
pgbench -j 7 -c 7 -f t.sql -P 1 -T 300 eax
`perf top` showed to bottlenecks [2]. A stacktrace for the first one
looks like this [3]:
0x00000000007a42e2 in get_tabstat_entry (rel_id=25696, isshared=0 ` 00`) at pgstat.c:1689
1689 if (entry->t_id == rel_id)
#0 0x00000000007a42e2 in get_tabstat_entry (rel_id=25696, isshared=0 ` 00`) at pgstat.c:1689
#1 0x00000000007a4275 in pgstat_initstats (rel=0x7f4af3fd41f8) at pgstat.c:1666
#2 0x00000000004c7090 in relation_open (relationId=25696, lockmode=0) at heapam.c:1137
#3 0x00000000004c72c9 in heap_open (relationId=25696, lockmode=0) at heapam.c:1291
(skipped)
And here is a stacktrace for the second bottleneck [4]:
0x0000000000584fb1 in find_all_inheritors (parentrelId=16393, lockmode=1, numparents=0x0) at pg_inherits.c:199
199 forboth(lo, rels_list, li, rel_numparents)
#0 0x0000000000584fb1 in find_all_inheritors (parentrelId=16393, lockmode=1, numparents=0x0) at pg_inherits.c:199
#1 0x000000000077fc9f in expand_inherited_rtentry (root=0x1badcb8, rte=0x1b630b8, rti=1) at prepunion.c:1408
#2 0x000000000077fb67 in expand_inherited_tables (root=0x1badcb8) at prepunion.c:1335
#3 0x0000000000767526 in subquery_planner (glob=0x1b63cc0, parse=0x1b62fa0, parent_root=0x0, hasRecursion=0 ` 00`, tuple_fraction=0) at planner.c:568
(skipped)
The first one could be easily fixed by introducing a hash table
(rel_id -> pgStatList entry). Perhaps hash table should be used only
after some threshold. Unless there are any objections I will send a
corresponding patch shortly.
I didn`t explored the second bottleneck closely yet but at first glance
it doesn`t look much more complicated.
Please don`t hesitate to share your thoughts regarding this matter.
[1] http://afiskon.ru/s/e3/5f47af9102_benchmark.txt
[2] http://afiskon.ru/s/00/2008c4ae66_temp.png
[3] http://afiskon.ru/s/23/650f0afc89_stack.txt
[4] http://afiskon.ru/s/03/a7e685a4db_stack2.txt
--
Best regards,
Aleksander Alekseev
這個patch的討論,詳見郵件組,本文末尾URL。
PostgreSQL社群的作風非常嚴謹,一個patch可能在郵件組中討論幾個月甚至幾年,根據大家的意見反覆的修正,patch合併到master已經非常成熟,所以PostgreSQL的穩定性也是遠近聞名的。
參考
https://commitfest.postgresql.org/13/1058/
相關文章
- PostgreSQL10.0preview效能增強-hashindexmetapagecache、高併發增強SQLViewIndex
- 震精-PostgreSQL10.0preview效能增強-WARM提升一倍效能SQLView
- PostgreSQL10.0preview效能增強-間接索引(secondaryindex)SQLView索引Index
- PostgreSQL10.0preview效能增強-支援64bitatomicSQLView
- PostgreSQL11preview-分割槽表增強彙總SQLView
- PostgreSQL10.0preview效能增強-OLAP提速框架,FasterExpressionEvaluationFramework(含JIT)SQLView框架ASTExpressFramework
- Oracle利用Windows的高階特性增強效能OracleWindows
- Oracle11新特性——分割槽功能增強Oracle
- PostgreSQL10.0preview效能增強-pg_xactalign(cacheline對齊)SQLView
- MySQL 8 複製效能的增強MySql
- Oracle11新特性——分割槽功能增強(五)Oracle
- Oracle11新特性——分割槽功能增強(四)Oracle
- Oracle11新特性——分割槽功能增強(三)Oracle
- Oracle11新特性——分割槽功能增強(二)Oracle
- Oracle11新特性——分割槽功能增強(一)Oracle
- PostgreSQL10.0preview功能增強-OLAP增強向量聚集索引(列儲存擴充套件)SQLView索引套件
- PostgreSQL10.0preview功能增強-國際化功能增強,支援ICU(InternationalComponentsforUnicode)SQLViewUnicode
- OpenCL 增強單work-item kernel效能策略
- PostgreSQL10.0preview效能增強-(多維分析)更快,更省記憶體hashedaggregationwithgroupingsetsSQLView記憶體Gse
- PostgreSQL10.0preview功能增強-增加ProcArrayGroupUpdate等待事件SQLView事件
- 用歸納偏置來增強你的模型效能模型
- 微軟Xbox One更新 控制皮膚效能增強微軟
- Java高階特性增強-鎖Java
- PostgreSQL10.0preview功能增強-觸發器函式內建中間表SQLView觸發器函式
- 深圳市恆訊科技分析如何增強mySQL效能?MySql
- PostgreSQL10.0preview效能增強-hash,nestloopjoin優化(聰明的優化器是這樣的)SQLViewOOP優化
- JOB、分割槽表、效能優化方面優化
- PostgreSQL10.0preview功能增強-CLOGoldestXID跟蹤SQLViewGo
- 影像語義分割資料增強——imgaug(二)
- JMeter做效能測試(1)-效能壓測指令碼的生成以及完善和增強JMeter指令碼
- 強化階段
- PostgreSQL10.0preview功能增強-JSON內容全文檢索SQLViewJSON
- PostgreSQL10.0preview功能增強-後臺執行(pg_background)SQLView
- 【譯】Visual Studio 2022 - 17.10 效能增強
- Oracle12c中效能最佳化&功能增強新特性之全域性索引DROP和TRUNCATE 分割槽的非同步維護Oracle索引非同步
- 集合框架-增強for框架
- 增強字串 (轉)字串
- PostgreSQL10.0preview功能增強-自由定義統計資訊維度SQLView