openGauss學(xué)習(xí)筆記-225 openGauss性能調(diào)優(yōu)-系統(tǒng)調(diào)優(yōu)-配置向量化執(zhí)行引擎
openGauss學(xué)習(xí)筆記-225 openGauss性能調(diào)優(yōu)-系統(tǒng)調(diào)優(yōu)-配置向量化執(zhí)行引擎
openGauss數(shù)據(jù)庫支持行執(zhí)行引擎和向量化執(zhí)行引擎,分別對(duì)應(yīng)行存表和列存表。
一次一個(gè)batch,讀取更多數(shù)據(jù),節(jié)省IO。
batch中記錄較多,CPU cache命中率提升。
Pipeline模式執(zhí)行,函數(shù)調(diào)用次數(shù)少。
一次處理一批數(shù)據(jù),效率高。
openGauss數(shù)據(jù)庫所以對(duì)于分析類的復(fù)雜查詢能夠獲得更好的查詢性能。但列存表在數(shù)據(jù)插入和數(shù)據(jù)更新上表現(xiàn)不佳,對(duì)于存在數(shù)據(jù)頻繁插入和更新的業(yè)務(wù)無法使用列存表。
為了提升行存表在分析類的復(fù)雜查詢上的查詢性能,openGauss數(shù)據(jù)庫提供行存表使用向量化執(zhí)行引擎的能力。通過設(shè)置GUC參數(shù)try_vector_engine_strategy,可以將包含行存表的查詢語句轉(zhuǎn)換為向量化執(zhí)行計(jì)劃執(zhí)行。
行存表轉(zhuǎn)換為向量化執(zhí)行引擎執(zhí)行不是對(duì)所有的查詢場(chǎng)景都適用。參考向量化引擎的優(yōu)勢(shì),如果查詢語句中包含表達(dá)式計(jì)算、多表join、聚集等操作時(shí),通過轉(zhuǎn)換為向量化執(zhí)行能夠獲得性能提升。從原理上分析,行存表轉(zhuǎn)換為向量化執(zhí)行,會(huì)產(chǎn)生轉(zhuǎn)換的開銷,導(dǎo)致性能下降。而上述操作的表達(dá)式計(jì)算、join操作、聚集操作轉(zhuǎn)換為向量化執(zhí)行之后,能夠獲得獲得性能提升。所以查詢轉(zhuǎn)換為向量化執(zhí)行后,性能是否提升,取決于查詢轉(zhuǎn)換為向量化之后獲得的性能提升能否高于轉(zhuǎn)換產(chǎn)生的性能開銷。
以TPCH Q1為例,使用行執(zhí)行引擎時(shí),掃描算子的執(zhí)行時(shí)間為405210ms,聚集操作的執(zhí)行時(shí)間為2618964ms;而轉(zhuǎn)換為向量化執(zhí)行引擎后,掃描算子(SeqScan + VectorAdapter)的執(zhí)行時(shí)間為470840ms,聚集操作的執(zhí)行時(shí)間為212384ms,所以查詢能夠獲得性能提升。
TPCH Q1 行執(zhí)行引擎執(zhí)行計(jì)劃:
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=43539570.49..43539570.50 rows=6 width=260) (actual time=3024174.439..3024174.439 rows=4 loops=1)
Sort Key: l_returnflag, l_linestatus
Sort Method: quicksort Memory: 25kB
-> HashAggregate (cost=43539570.30..43539570.41 rows=6 width=260) (actual time=3024174.396..3024174.403 rows=4 loops=1)
Group By Key: l_returnflag, l_linestatus
-> Seq Scan on lineitem (cost=0.00..19904554.46 rows=590875396 width=28) (actual time=0.016..405210.038 rows=596140342 loops=1)
Filter: (l_shipdate <= '1998-10-01 00:00:00'::timestamp without time zone)
Rows Removed by Filter: 3897560
Total runtime: 3024174.578 ms
(9 rows)
TPCH Q1 向量化執(zhí)行引擎執(zhí)行計(jì)劃:
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Row Adapter (cost=43825808.18..43825808.18 rows=6 width=298) (actual time=683224.925..683224.927 rows=4 loops=1)
-> Vector Sort (cost=43825808.16..43825808.18 rows=6 width=298) (actual time=683224.919..683224.919 rows=4 loops=1)
Sort Key: l_returnflag, l_linestatus
Sort Method: quicksort Memory: 3kB
-> Vector Sonic Hash Aggregate (cost=43825807.98..43825808.08 rows=6 width=298) (actual time=683224.837..683224.837 rows=4 loops=1)
Group By Key: l_returnflag, l_linestatus
-> Vector Adapter(type: BATCH MODE) (cost=19966853.54..19966853.54 rows=596473861 width=66) (actual time=0.982..470840.274 rows=596140342 loops=1)
Filter: (l_shipdate <= '1998-10-01 00:00:00'::timestamp without time zone)
Rows Removed by Filter: 3897560
-> Seq Scan on lineitem (cost=0.00..19966853.54 rows=596473861 width=66) (actual time=0.364..199301.737 rows=600037902 loops=1)
Total runtime: 683225.564 ms
(11 rows)
?? 點(diǎn)贊,你的認(rèn)可是我創(chuàng)作的動(dòng)力!
?? 收藏,你的青睞是我努力的方向!
?? 評(píng)論,你的意見是我進(jìn)步的財(cái)富!
