根據需要設置關聯發生的節點
更新時間 2025-02-05 09:36:58
最近更新時間: 2025-02-05 09:36:58
分享文章
多表關聯的邏輯默認是在DN節點執行,在發生重分布后,可能會因為重分布原因性能明顯下降。您可以選擇將關聯邏輯上拉到CN節點執行,避免DN之間的重分布。
多表關聯的邏輯默認是在DN節點執行,在發生重分布后,可能會因為重分布原因性能明顯下降。
針對此問題,TeleDB支持通過參數prefer_olap設置,可以選擇將關聯邏輯上拉到CN節點執行,避免DN之間的重分布。參數prefer_olap默認為on,表示關聯下推到DN執行,off則表示關聯上拉到DN執行。
這里需要注意,設置關聯上拉CN節點執行,需要提前做好評估,如果上拉數據量過大,大量并發SQL發起上拉數據到CN動作,會導致CN節點負載過高,甚至OOM。
通常可以在TP類業務中可以針對SQL會話級設置上拉,性能會有所提升,同時CN節點應配置較大的資源,避免OOM發生。
例如,下面的SQL,teledb_1關聯沒有用到分布鍵,發生了重分布。
teledb=# explain select teledb_1.* from teledb_1,teledb_2 where teledb_1.f1=teledb_2.f1 ;
QUERY PLAN
------------------------------------------------------------------------------------------------
Remote Subquery Scan on all (dn001,dn002) (cost=29.80..186.32 rows=3872 width=40)
-> Hash Join (cost=29.80..186.32 rows=3872 width=40)
Hash Cond: (teledb_1.f1 = teledb_2.f1)
-> Remote Subquery Scan on all (dn001,dn002) (cost=100.00..158.40 rows=880 width=40)
Distribute results by S: f1
-> Seq Scan on teledb_1 (cost=0.00..18.80 rows=880 width=40)
-> Hash (cost=18.80..18.80 rows=880 width=4)
-> Seq Scan on teledb_2 (cost=0.00..18.80 rows=880 width=4)
(8 rows)
設置prefer_olap=off后,關聯上拉到CN上執行,重分布消失。
執行計劃如下:
teledb=# set prefer_olap to off;
SET
teledb=# explain select teledb_1.* from teledb_1,teledb_2 where teledb_1.f1=teledb_2.f1 ;
QUERY PLAN
-----------------------------------------------------------------------------------------------
Hash Join (cost=29.80..186.32 rows=3872 width=40)
Hash Cond: (teledb_1.f1 = teledb_2.f1)
-> Remote Subquery Scan on all (dn001,dn002) (cost=100.00..158.40 rows=880 width=40)
-> Seq Scan on teledb_1 (cost=0.00..18.80 rows=880 width=40)
-> Hash (cost=126.72..126.72 rows=880 width=4)
-> Remote Subquery Scan on all (dn001,dn002) (cost=100.00..126.72 rows=880 width=4)
-> Seq Scan on teledb_2 (cost=0.00..18.80 rows=880 width=4)
(7 rows)