本文分享自华为云社区《GaussDB(DWS)性能调优:MERGE场景下语句不下推引起的性能瓶颈问题案例》,作者:O泡果奶~。

1、【问题描述】

语句执行时间过长,且该语句performance执行计划中SQL Diagnostic Information显示SQL语句不下推,理由为:Type of Record in dual that is not a real table can not be shipped

2、【原始语句】

merge into fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f T using
(SELECT 'Y' del_flag FROM DUAL) S on
( T.PERIOD_ID = 202308 AND NOT EXISTS
(SELECT 1 FROM FIN_DRT_ACT.RT_ACT_APD_NPD_RMK_TO_STO_V S WHERE T.UNIQUE_ID = S.UNIQUE_ID AND T.PERIOD_ID = S.PERIOD_ID ))
WHEN MATCHED THEN UPDATE SET T.del_flag=S.del_flag

3、【性能分析】

改写前SQL语句performance执行计划

 id |                                                   operation                                                   |   A-time   | A-rows | E-rows | E-distinct | Peak Memory | A-width | E-width | E-costs
----+---------------------------------------------------------------------------------------------------------------+------------+--------+--------+------------+-------------+---------+---------+---------
1 | -> Merge on fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f t | 806911.617 | 17948 | 17140 | | 74KB | | 498 | 501.74
2 | -> Nested Loop (3,4) | 3795.279 | 17948 | 17140 | | 66KB | | 498 | 501.74
3 | -> Result | 0.003 | 1 | 1 | | 24KB | | 0 | 0.01
4 | -> Hash Anti Join (5, 6) | 3741.930 | 17948 | 17140 | | 56KB | | 498 | 330.32
5 | -> Data Node Scan on rt_act_apd_npd_rmk_sto_his_dtl_f "_REMOTE_TABLE_QUERY_" | 3291.507 | 17948 | 17400 | | 24832KB | | 498 | 0.00
6 | -> Hash | 384.317 | 7 | 261 | | 320KB | | 554 | 54.23
7 | -> Hash Right Join (8, 14) | 384.287 | 7 | 261 | | 32KB | | 554 | 54.23
8 | -> Subquery Scan on t2 | 6.915 | 198 | 236 | | 32KB | | 18 | 26.41
9 | -> WindowAgg | 6.862 | 198 | 236 | | 64KB | | 18 | 23.46
10 | -> Sort | 6.730 | 198 | 236 | | 72KB | | 18 | 16.97
11 | -> Subquery Scan on t | 5.650 | 198 | 236 | | 64KB | | 18 | 7.08
12 | -> HashAggregate | 5.535 | 198 | 236 | | 104KB | | 28 | 4.72
13 | -> Data Node Scan on rt_act_mca_dc_user_privilege_dtl_f "_REMOTE_TABLE_QUERY_" | 5.378 | 198 | 236 | | 64KB | | 28 | 0.00
14 | -> Hash | 377.009 | 7 | 260 | | 312KB | | 2102 | 0.00
15 | -> Data Node Scan on apd_npd_rmk_to_sto_tmp "_REMOTE_TABLE_QUERY_" | 376.991 | 7 | 260 | | 64KB | | 2102 | 0.00 SQL Diagnostic Information
---------------------------------------------------------------------------
SQL is not plan-shipping
reason: Type of Record in dual that is not a real table can not be shipped Predicate Information (identified by plan id)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 --Merge on fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f t
Merge Updated: 17948
4 --Hash Anti Join (5, 6)
Hash Cond: (((t.unique_id)::text = ((t1.period_id)::text || (t1.unique_id)::text)) AND (t.period_id = (t1.period_id)::numeric))
7 --Hash Right Join (8, 14)
Hash Cond: ((t2.ssc_code)::text = (t1.ssc_code)::text)
Join Filter: (((t1.company_code)::text = (CASE WHEN ((t2.company_code)::text = 'ALL'::text) THEN t1.company_code ELSE t2.company_code END)::text) AND ((t1.account_code)::text = (CASE WHEN ((t2.account_number)::text = 'ALL'::text) THEN t1.account_code ELSE t2.account_number END)::text))
Rows Removed by Join Filter: 119
8 --Subquery Scan on t2
Filter: (t2.rownumber = 1) Memory Information (identified by plan id)
---------------------------------------------------------------------------------
1 --Merge on fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f t
Peak Memory: 74KB, Estimate Memory: 2048MB
2 --Nested Loop (3,4)
Peak Memory: 66KB, Estimate Memory: 2048MB
3 --Result
Peak Memory: 24KB, Estimate Memory: 2048MB
4 --Hash Anti Join (5, 6)
Peak Memory: 56KB, Estimate Memory: 2048MB
5 --Data Node Scan on rt_act_apd_npd_rmk_sto_his_dtl_f "_REMOTE_TABLE_QUERY_"
Peak Memory: 24832KB, Estimate Memory: 2048MB
6 --Hash
Peak Memory: 320KB, Width: 56
Buckets: 32768 Batches: 1 Memory Usage: 1kB
7 --Hash Right Join (8, 14)
Peak Memory: 32KB, Estimate Memory: 2048MB
8 --Subquery Scan on t2
Peak Memory: 32KB, Estimate Memory: 2048MB
9 --WindowAgg
Peak Memory: 64KB, Estimate Memory: 2048MB
10 --Sort
Peak Memory: 72KB, Estimate Memory: 2048MB
11 --Subquery Scan on t
Peak Memory: 64KB, Estimate Memory: 2048MB
12 --HashAggregate
Peak Memory: 104KB, Estimate Memory: 2048MB
13 --Data Node Scan on rt_act_mca_dc_user_privilege_dtl_f "_REMOTE_TABLE_QUERY_"
Peak Memory: 64KB, Estimate Memory: 2048MB
14 --Hash
Peak Memory: 312KB, Width: 76
Buckets: 32768 Batches: 1 Memory Usage: 1kB
15 --Data Node Scan on apd_npd_rmk_to_sto_tmp "_REMOTE_TABLE_QUERY_"
Peak Memory: 64KB, Estimate Memory: 2048MB Targetlist Information (identified by plan id)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 --Merge on fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f t
Node/s: All datanodes
Remote query: UPDATE ONLY fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f t SET seq_id = $47, batch_number = $48, approved_status = $49, reference_id = $50, enabled_flag = $51, operate_flag = $52, original_period = $53, carry_flag = $54, account_period_id = $55, period_id = $56, ssc_code = $57, ssc_cn_name = $58, ssc_en_name = $59, company_code = $60, source_name = $61, ic = $62, lc_dr_amt_je = $63, lc_cr_amt_je = $64, ptd_je = $65, lc_dr_tb = $66, lc_cr_tb = $67, ptd_tb = $68, dif_ptd = $69, account_code = $70, schedule_end_time = $71, remark = $72, status = $73, status_name = $74, exception_type = $75, exception_type_name = $76, approved_by = $77, approve_comment = $78, approve_date = $79, unique_id = $80, created_by = $81, creation_date = $82, last_updated_by = $83, last_update_date = $84, last_update_login = $85, error_message_cn = $86, error_message_en = $87, del_flag = $88 WHERE t.ctid = $44 AND t.xc_node_id = $45 AND t.tableoid = $46
2 --Nested Loop (3,4)
Output: 'Y'::text, t.seq_id, t.batch_number, t.approved_status, t.reference_id, t.enabled_flag, t.operate_flag, t.original_period, t.carry_flag, t.account_period_id, t.period_id, t.ssc_code, t.ssc_cn_name, t.ssc_en_name, t.company_code, t.source_name, t.ic, t.lc_dr_amt_je, t.lc_cr_amt_je, t.ptd_je, t.lc_dr_tb, t.lc_cr_tb, t.ptd_tb, t.dif_ptd, t.account_code, t.schedule_end_time, t.remark, t.status, t.status_name, t.exception_type, t.exception_type_name, t.approved_by, t.approve_comment, t.approve_date, t.unique_id, t.created_by, t.creation_date, t.last_updated_by, t.last_update_date, t.last_update_login, t.error_message_cn, t.error_message_en, t.del_flag, t.ctid, t.xc_node_id, t.tableoid, t.seq_id, t.batch_number, t.approved_status, t.reference_id, t.enabled_flag, t.operate_flag, t.original_period, t.carry_flag, t.account_period_id, t.period_id, t.ssc_code, t.ssc_cn_name, t.ssc_en_name, t.company_code, t.source_name, t.ic, t.lc_dr_amt_je, t.lc_cr_amt_je, t.ptd_je, t.lc_dr_tb, t.lc_cr_tb, t.ptd_tb, t.dif_ptd, t.account_code, t.schedule_end_time, t.remark, t.status, t.status_name, t.exception_type, t.exception_type_name, t.approved_by, t.approve_comment, t.approve_date, t.unique_id, t.created_by, t.creation_date, t.last_updated_by, t.last_update_date, t.last_update_login, t.error_message_cn, t.error_message_en, 'Y'::character varying(1)
4 --Hash Anti Join (5, 6)
Output: t.seq_id, t.batch_number, t.approved_status, t.reference_id, t.enabled_flag, t.operate_flag, t.original_period, t.carry_flag, t.account_period_id, t.period_id, t.ssc_code, t.ssc_cn_name, t.ssc_en_name, t.company_code, t.source_name, t.ic, t.lc_dr_amt_je, t.lc_cr_amt_je, t.ptd_je, t.lc_dr_tb, t.lc_cr_tb, t.ptd_tb, t.dif_ptd, t.account_code, t.schedule_end_time, t.remark, t.status, t.status_name, t.exception_type, t.exception_type_name, t.approved_by, t.approve_comment, t.approve_date, t.unique_id, t.created_by, t.creation_date, t.last_updated_by, t.last_update_date, t.last_update_login, t.error_message_cn, t.error_message_en, t.del_flag, t.ctid, t.xc_node_id, t.tableoid
5 --Data Node Scan on rt_act_apd_npd_rmk_sto_his_dtl_f "_REMOTE_TABLE_QUERY_"
Output: t.seq_id, t.batch_number, t.approved_status, t.reference_id, t.enabled_flag, t.operate_flag, t.original_period, t.carry_flag, t.account_period_id, t.period_id, t.ssc_code, t.ssc_cn_name, t.ssc_en_name, t.company_code, t.source_name, t.ic, t.lc_dr_amt_je, t.lc_cr_amt_je, t.ptd_je, t.lc_dr_tb, t.lc_cr_tb, t.ptd_tb, t.dif_ptd, t.account_code, t.schedule_end_time, t.remark, t.status, t.status_name, t.exception_type, t.exception_type_name, t.approved_by, t.approve_comment, t.approve_date, t.unique_id, t.created_by, t.creation_date, t.last_updated_by, t.last_update_date, t.last_update_login, t.error_message_cn, t.error_message_en, t.del_flag, t.ctid, t.xc_node_id, t.tableoid
Node/s: All datanodes
Remote query: SELECT seq_id, batch_number, approved_status, reference_id, enabled_flag, operate_flag, original_period, carry_flag, account_period_id, period_id, ssc_code, ssc_cn_name, ssc_en_name, company_code, source_name, ic, lc_dr_amt_je, lc_cr_amt_je, ptd_je, lc_dr_tb, lc_cr_tb, ptd_tb, dif_ptd, account_code, schedule_end_time, remark, status, status_name, exception_type, exception_type_name, approved_by, approve_comment, approve_date, unique_id, created_by, creation_date, last_updated_by, last_update_date, last_update_login, error_message_cn, error_message_en, del_flag, ctid, xc_node_id, tableoid FROM ONLY fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f t WHERE period_id = 202308::numeric
6 --Hash
Output: t1.period_id, t1.unique_id
7 --Hash Right Join (8, 14)
Output: t1.period_id, t1.unique_id
8 --Subquery Scan on t2
Output: t2.ssc_code, t2.company_code, t2.account_number, t2.level_key, t2.rownumber
9 --WindowAgg
Output: t.ssc_code, t.company_code, t.account_number, (CASE WHEN (((t.company_code)::text = 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 0 WHEN (((t.company_code)::text <> 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 1 ELSE 2 END), dense_rank() OVER (PARTITION BY t.ssc_code ORDER BY (CASE WHEN (((t.company_code)::text = 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 0 WHEN (((t.company_code)::text <> 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 1 ELSE 2 END) USING = NULLS LAST)
10 --Sort
Output: t.ssc_code, (CASE WHEN (((t.company_code)::text = 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 0 WHEN (((t.company_code)::text <> 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 1 ELSE 2 END), t.company_code, t.account_number
Sort Key: t.ssc_code, (CASE WHEN (((t.company_code)::text = 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 0 WHEN (((t.company_code)::text <> 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 1 ELSE 2 END)
11 --Subquery Scan on t
Output: t.ssc_code, CASE WHEN (((t.company_code)::text = 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 0 WHEN (((t.company_code)::text <> 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 1 ELSE 2 END, t.company_code, t.account_number
12 --HashAggregate
Output: t1.ssc_code, t1.company_code, t1.account_number, t1.user_id
Group By Key: t1.ssc_code, t1.company_code, t1.account_number, t1.user_id
13 --Data Node Scan on rt_act_mca_dc_user_privilege_dtl_f "_REMOTE_TABLE_QUERY_"
Output: t1.ssc_code, t1.company_code, t1.account_number, t1.user_id
Node/s: All datanodes
Remote query: SELECT ssc_code, company_code, account_number, user_id FROM ONLY fin_drt_act.rt_act_mca_dc_user_privilege_dtl_f t1 WHERE flow_type::text = 'EC_GL'::text AND chek_type::text = 'EC_GL_STO'::text AND begin_date <= pg_systimestamp()::timestamp(0) without time zone AND end_date >= pg_systimestamp()::timestamp(0) without time zone
14 --Hash
Output: t1.ssc_code, t1.company_code, t1.account_code, t1.period_id, t1.unique_id
15 --Data Node Scan on apd_npd_rmk_to_sto_tmp "_REMOTE_TABLE_QUERY_"
Output: t1.ssc_code, t1.company_code, t1.account_code, t1.period_id, t1.unique_id
Node/s: All datanodes
Remote query: SELECT ssc_code, company_code, account_code, period_id, unique_id FROM ONLY fin_drt_act.apd_npd_rmk_to_sto_tmp t1 WHERE true Datanode Information (identified by plan id)
-----------------------------------------------------------------------------------------------
1 --Merge on fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f t
(actual time=806911.616..806911.617 rows=17948 loops=1)
(Buffers: shared hit=6)
(CPU: ex c/r=116340958, ex row=17948, ex cyc=2088087526316, inc cyc=2097953048602)
2 --Nested Loop (3,4)
(actual time=561.052..3795.279 rows=17948 loops=1) (projection time=23.340)
(CPU: ex c/r=7752, ex row=17949, ex cyc=139143070, inc cyc=9865522286)
3 --Result
(actual time=0.001..0.003 rows=1 loops=1) (projection time=0.001)
(CPU: ex c/r=4680, ex row=1, ex cyc=4680, inc cyc=4680)
4 --Hash Anti Join (5, 6)
(actual time=561.044..3741.930 rows=17948 loops=1) (projection time=7.143)
(Buffers: shared hit=6)
(CPU: ex c/r=9584, ex row=17955, ex cyc=172088156, inc cyc=9726374536)
5 --Data Node Scan on rt_act_apd_npd_rmk_sto_his_dtl_f "_REMOTE_TABLE_QUERY_"
(actual time=176.472..3291.507 rows=17948 loops=1)
(Buffers: 0)
(CPU: ex c/r=476658, ex row=17948, ex cyc=8555072428, inc cyc=8555072428)
6 --Hash
(actual time=384.317..384.317 rows=7 loops=1)
(Buffers: shared hit=6)
(CPU: ex c/r=10954, ex row=7, ex cyc=76680, inc cyc=999213952)
7 --Hash Right Join (8, 14)
(actual time=384.028..384.287 rows=7 loops=1) (filter time=0.043 projection time=0.000)
(Buffers: shared hit=6)
(CPU: ex c/r=4613, ex row=205, ex cyc=945852, inc cyc=999137272)
8 --Subquery Scan on t2
(actual time=6.751..6.915 rows=198 loops=1) (filter time=0.018)
(CPU: ex c/r=682, ex row=198, ex cyc=135038, inc cyc=17975308)
9 --WindowAgg
(actual time=6.741..6.862 rows=198 loops=1) (projection time=0.016)
(Buffers: shared hit=6)
(CPU: ex c/r=1848, ex row=198, ex cyc=366028, inc cyc=17840270)
10 --Sort
(actual time=6.716..6.730 rows=198 loops=1)
(Buffers: shared hit=6)
(CPU: ex c/r=14173, ex row=198, ex cyc=2806302, inc cyc=17474242)
11 --Subquery Scan on t
(actual time=5.524..5.650 rows=198 loops=1) (projection time=0.067)
(CPU: ex c/r=1406, ex row=198, ex cyc=278492, inc cyc=14667940)
12 --HashAggregate
(actual time=5.490..5.535 rows=198 loops=1) (projection time=0.003)
(Buffers: 0)
(CPU: ex c/r=2111, ex row=198, ex cyc=418106, inc cyc=14389448)
13 --Data Node Scan on rt_act_mca_dc_user_privilege_dtl_f "_REMOTE_TABLE_QUERY_"
(actual time=2.249..5.378 rows=198 loops=1)
(Buffers: 0)
(CPU: ex c/r=70562, ex row=198, ex cyc=13971342, inc cyc=13971342)
14 --Hash
(actual time=377.009..377.009 rows=7 loops=1)
(Buffers: 0)
(CPU: ex c/r=8018, ex row=7, ex cyc=56128, inc cyc=980216112)
15 --Data Node Scan on apd_npd_rmk_to_sto_tmp "_REMOTE_TABLE_QUERY_"
(actual time=128.393..376.991 rows=7 loops=1)
(Buffers: 0)
(CPU: ex c/r=140022854, ex row=7, ex cyc=980159984, inc cyc=980159984) ====== Query Summary =====
-------------------------------------------------------------
Remote query poll time: 169.602 ms, Deserialze time: 7.760 ms
Remote query poll time: 4.858 ms, Deserialze time: 0.006 ms
Remote query poll time: 319.716 ms, Deserialze time: 0.000 ms
Enqueue time: 0.034 ms
Coordinator executor start time: 0.551 ms
Coordinator executor run time: 806912.768 ms
Coordinator executor end time: 17.822 ms
Parser runtime: 0.000 ms
Planner runtime: 4.840 ms
Query Id: 83598068858005619
Unique SQL Id: 4289851310
Total runtime: 806936.261 ms

业务使用时,会使用MERGE INTO语句实现类似UPSERT的功能。这种场景下MERGE INTO语句的USING部分的数据为VALUES子句,USING部分的书写方式可能导致MERGE INTO语句的执行不下推。
本文SQL语句中,可以看出不下推原因是dual表且VALUES子句中并没有使用到该表,因此对USING子句的SQL语句进行改写,以便整个SQL语句可以下推。
改写语句

merge into fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f T using
(SELECT 'Y' del_flag) S on
( T.PERIOD_ID = 202308 AND NOT EXISTS
(SELECT 1 FROM FIN_DRT_ACT.RT_ACT_APD_NPD_RMK_TO_STO_V S WHERE T.UNIQUE_ID = S.UNIQUE_ID AND T.PERIOD_ID = S.PERIOD_ID ))
WHEN MATCHED THEN UPDATE SET T.del_flag=S.del_flag

改写后语句verbose执行计划

 id |                                                   operation                                                    | E-rows | E-distinct | E-memory | E-width | E-costs
----+----------------------------------------------------------------------------------------------------------------+--------+------------+----------+---------+---------
1 | -> Row Adapter | 1 | | | 572 | 2838.74
2 | -> Vector Streaming (type: GATHER) | 1 | | | 572 | 2838.74
3 | -> Vector Merge on fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f t | 17592 | | 48MB | 572 | 2834.97
4 | -> Vector Hash Anti Join (5, 9) | 17592 | | 16MB | 572 | 2834.97
5 | -> Vector Nest Loop (6,8) | 17852 | 686 | 1MB | 532 | 1873.40
6 | -> Vector Adapter | 26 | | 1MB | 0 | 0.01
7 | -> Result | 26 | | 1MB | 0 | 0.01
8 | -> CStore Scan on fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f t | 17852 | | 1MB | 500 | 1866.51
9 | -> Vector Streaming(type: BROADCAST) | 6838 | 52 | 2MB | 594 | 947.28
10 | -> Vector Hash Right Join (11, 20) | 263 | | 16MB | 594 | 706.57
11 | -> Vector Streaming(type: BROADCAST) | 6162 | 47 | 2MB | 30 | 674.47
12 | -> Vector Subquery Scan on t2 | 237 | | 1MB | 30 | 631.14
13 | -> Vector WindowAgg | 237 | | 16MB | 18 | 631.03
14 | -> Vector Sort | 237 | | 16MB | 18 | 630.56
15 | -> Vector Streaming(type: REDISTRIBUTE) | 234 | | 2MB | 18 | 629.85
16 | -> Vector Subquery Scan on t | 234 | | 1MB | 18 | 629.51
17 | -> Vector Sonic Hash Aggregate | 234 | | 16MB | 28 | 629.42
18 | -> Vector Streaming(type: REDISTRIBUTE) | 236 | | 2MB | 28 | 629.24
19 | -> CStore Scan on fin_drt_act.rt_act_mca_dc_user_privilege_dtl_f t1 | 236 | | 1MB | 28 | 628.94
20 | -> Vector Partition Iterator | 260 | 30 | 1MB | 2112 | 30.03
21 | -> Partitioned CStore Scan on fin_drt_act.apd_npd_rmk_to_sto_tmp t1 | 260 | | 1MB | 2112 | 30.03 Predicate Information (identified by plan id)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4 --Vector Hash Anti Join (5, 9)
Hash Cond: (((t.unique_id)::text = ((t1.period_id)::text || (t1.unique_id)::text)) AND (t.period_id = (t1.period_id)::numeric))
8 --CStore Scan on fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f t
Filter: (t.period_id = 202308::numeric)
Pushdown Predicate Filter: (t.period_id = 202308::numeric)
10 --Vector Hash Right Join (11, 20)
Hash Cond: ((t2.ssc_code)::text = (t1.ssc_code)::text)
Join Filter: (((t1.company_code)::text = (CASE WHEN ((t2.company_code)::text = 'ALL'::text) THEN t1.company_code ELSE t2.company_code END)::text) AND ((t1.account_code)::text = (CASE WHEN ((t2.account_number)::text = 'ALL'::text) THEN t1.account_code ELSE t2.account_number END)::text))
12 --Vector Subquery Scan on t2
Filter: (t2.rownumber = 1)
17 --Vector Sonic Hash Aggregate
Skew Agg Optimized by Statistic
19 --CStore Scan on fin_drt_act.rt_act_mca_dc_user_privilege_dtl_f t1
Filter: (((t1.flow_type)::text = 'EC_GL'::text) AND ((t1.chek_type)::text = 'EC_GL_STO'::text) AND (t1.begin_date <= (pg_systimestamp())::timestamp(0) without time zone) AND (t1.end_date >= (pg_systimestamp())::timestamp(0) without time zone))
Pushdown Predicate Filter: (((t1.flow_type)::text = 'EC_GL'::text) AND ((t1.chek_type)::text = 'EC_GL_STO'::text) AND (t1.begin_date <= (pg_systimestamp())::timestamp(0) without time zone) AND (t1.end_date >= (pg_systimestamp())::timestamp(0) without time zone))
20 --Vector Partition Iterator
Iterations: 120
21 --Partitioned CStore Scan on fin_drt_act.apd_npd_rmk_to_sto_tmp t1
Partitions Selected by Static Prune: 1..120 Targetlist Information (identified by plan id)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2 --Vector Streaming (type: GATHER)
Node/s: All datanodes
4 --Vector Hash Anti Join (5, 9)
Output: ('Y'::text), t.seq_id, t.batch_number, t.approved_status, t.reference_id, t.enabled_flag, t.operate_flag, t.original_period, t.carry_flag, t.account_period_id, t.period_id, t.ssc_code, t.ssc_cn_name, t.ssc_en_name, t.company_code, t.source_name, t.ic, t.lc_dr_amt_je, t.lc_cr_amt_je, t.ptd_je, t.lc_dr_tb, t.lc_cr_tb, t.ptd_tb, t.dif_ptd, t.account_code, t.schedule_end_time, t.remark, t.status, t.status_name, t.exception_type, t.exception_type_name, t.approved_by, t.approve_comment, t.approve_date, t.unique_id, t.created_by, t.creation_date, t.last_updated_by, t.last_update_date, t.last_update_login, t.error_message_cn, t.error_message_en, t.del_flag, t.ctid, t.xc_node_id, t.tableoid, ('Y'::text), t1.ctid, t1.tableoid, t2.ssc_code, t2.company_code, t2.account_number, t2.level_key, t2.rownumber
5 --Vector Nest Loop (6,8)
Output: ('Y'::text), t.seq_id, t.batch_number, t.approved_status, t.reference_id, t.enabled_flag, t.operate_flag, t.original_period, t.carry_flag, t.account_period_id, t.period_id, t.ssc_code, t.ssc_cn_name, t.ssc_en_name, t.company_code, t.source_name, t.ic, t.lc_dr_amt_je, t.lc_cr_amt_je, t.ptd_je, t.lc_dr_tb, t.lc_cr_tb, t.ptd_tb, t.dif_ptd, t.account_code, t.schedule_end_time, t.remark, t.status, t.status_name, t.exception_type, t.exception_type_name, t.approved_by, t.approve_comment, t.approve_date, t.unique_id, t.created_by, t.creation_date, t.last_updated_by, t.last_update_date, t.last_update_login, t.error_message_cn, t.error_message_en, t.del_flag, t.ctid, t.xc_node_id, t.tableoid
6 --Vector Adapter
Output: 'Y'::text
7 --Result
Output: 'Y'::text
8 --CStore Scan on fin_drt_act.rt_act_apd_npd_rmk_sto_his_dtl_f t
Output: t.seq_id, t.batch_number, t.approved_status, t.reference_id, t.enabled_flag, t.operate_flag, t.original_period, t.carry_flag, t.account_period_id, t.period_id, t.ssc_code, t.ssc_cn_name, t.ssc_en_name, t.company_code, t.source_name, t.ic, t.lc_dr_amt_je, t.lc_cr_amt_je, t.ptd_je, t.lc_dr_tb, t.lc_cr_tb, t.ptd_tb, t.dif_ptd, t.account_code, t.schedule_end_time, t.remark, t.status, t.status_name, t.exception_type, t.exception_type_name, t.approved_by, t.approve_comment, t.approve_date, t.unique_id, t.created_by, t.creation_date, t.last_updated_by, t.last_update_date, t.last_update_login, t.error_message_cn, t.error_message_en, t.del_flag, t.ctid, t.xc_node_id, t.tableoid
Distribute Key: t.seq_id
9 --Vector Streaming(type: BROADCAST)
Output: t1.ctid, t1.tableoid, t1.period_id, t1.unique_id, t2.ssc_code, t2.company_code, t2.account_number, t2.level_key, t2.rownumber
Spawn on: All datanodes
Consumer Nodes: All datanodes
10 --Vector Hash Right Join (11, 20)
Output: t1.ctid, t1.tableoid, t1.period_id, t1.unique_id, t2.ssc_code, t2.company_code, t2.account_number, t2.level_key, t2.rownumber
11 --Vector Streaming(type: BROADCAST)
Output: t2.ssc_code, t2.company_code, t2.account_number, t2.level_key, t2.rownumber
Spawn on: All datanodes
Consumer Nodes: All datanodes
12 --Vector Subquery Scan on t2
Output: t2.ssc_code, t2.company_code, t2.account_number, t2.level_key, t2.rownumber
13 --Vector WindowAgg
Output: t.ssc_code, t.company_code, t.account_number, (CASE WHEN (((t.company_code)::text = 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 0 WHEN (((t.company_code)::text <> 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 1 ELSE 2 END), dense_rank() OVER (PARTITION BY t.ssc_code ORDER BY (CASE WHEN (((t.company_code)::text = 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 0 WHEN (((t.company_code)::text <> 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 1 ELSE 2 END) USING = NULLS LAST)
14 --Vector Sort
Output: t.ssc_code, (CASE WHEN (((t.company_code)::text = 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 0 WHEN (((t.company_code)::text <> 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 1 ELSE 2 END), t.company_code, t.account_number
Sort Key: t.ssc_code, (CASE WHEN (((t.company_code)::text = 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 0 WHEN (((t.company_code)::text <> 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 1 ELSE 2 END)
15 --Vector Streaming(type: REDISTRIBUTE)
Output: t.ssc_code, (CASE WHEN (((t.company_code)::text = 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 0 WHEN (((t.company_code)::text <> 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 1 ELSE 2 END), t.company_code, t.account_number
Distribute Key: t.ssc_code
Spawn on: All datanodes
Consumer Nodes: All datanodes
16 --Vector Subquery Scan on t
Output: t.ssc_code, CASE WHEN (((t.company_code)::text = 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 0 WHEN (((t.company_code)::text <> 'ALL'::text) AND ((t.account_number)::text = 'ALL'::text)) THEN 1 ELSE 2 END, t.company_code, t.account_number
17 --Vector Sonic Hash Aggregate
Output: t1.ssc_code, t1.company_code, t1.account_number, t1.user_id
Group By Key: t1.ssc_code, t1.company_code, t1.account_number, t1.user_id
18 --Vector Streaming(type: REDISTRIBUTE)
Output: t1.ssc_code, t1.company_code, t1.account_number, t1.user_id
Distribute Key: t1.account_number
Spawn on: All datanodes
Consumer Nodes: All datanodes
19 --CStore Scan on fin_drt_act.rt_act_mca_dc_user_privilege_dtl_f t1
Output: t1.ssc_code, t1.company_code, t1.account_number, t1.user_id
Distribute Key: t1.id
20 --Vector Partition Iterator
Output: t1.ctid, t1.tableoid, t1.ssc_code, t1.company_code, t1.account_code, t1.period_id, t1.unique_id
21 --Partitioned CStore Scan on fin_drt_act.apd_npd_rmk_to_sto_tmp t1
Output: t1.ctid, t1.tableoid, t1.ssc_code, t1.company_code, t1.account_code, t1.period_id, t1.unique_id
Distribute Key: t1.row_number ====== Query Summary =====
-------------------------------
System available mem: 2097152KB
Query Max mem: 2097152KB
Query estimated mem: 131072KB
Parser runtime: 0.102 ms
Planner runtime: 4.602 ms
Unique SQL Id: 1168204269

可以看出,SQL语句能够下推,且经过业务验证,语句执行时间下降为10s左右。

点击关注,第一时间了解华为云新鲜技术~

GaussDB(DWS)案例丨MERGE场景下语句不下推引起的性能瓶颈问题的更多相关文章

  1. GaussDB(DWS)运维:导致SQL执行不下推的改写方案

    摘要:本文就针对因USING子句的书写方式可能导致MERGE INTO语句的执行不下推的场景,对USING子句的SQL语句进行改写一遍,整个SQL语句可以下推. 本文分享自华为云社区<Gauss ...

  2. GaussDB(DWS)应用实践丨负载管理与作业排队处理方法

    摘要:本文用来总结一些GaussDB(DWS)在实际应用过程中,可能出现的各种作业排队的情况,以及出现排队时,我们应该怎么去判断是否正常,调整一些参数,让资源分配与负载管理更符合当前的业务:或者在作业 ...

  3. GaussDB(DWS)现网案例:collation报错

    摘要:用户创建hash分布表,使用pbe方式执行使用分布列作为查询条件的语句时报错 本文分享自华为云社区<GaussDB(DWS)现网案例之collation报错>,作者: 你是猴子请来的 ...

  4. 从数据仓库双集群系统模式探讨,看GaussDB(DWS)的容灾设计

    摘要:本文主要是探讨OLAP关系型数据库框架的数据仓库平台如何设计双集群系统,即增强系统高可用的保障水准,然后讨论一下GaussDB(DWS)的容灾应该如何设计. 当前社会.企业运行当中,大数据分析. ...

  5. 十八般武艺玩转GaussDB(DWS)性能调优:路径干预

    摘要:路径生成是表关联方式确定的主要阶段,本文介绍了几个影响路径生成的要素:cost_param, scan方式,join方式,stream方式,并从原理上分析如何干预路径的生成. 一.cost模型选 ...

  6. 一文详解GaussDB(DWS) 的并发管控和内存管控

    摘要:DWS的负载管理分为两层,第一层为cn的全局并发控制,第二层为资源池级别的并发控制. 本文分享自华为云社区<GaussDB(DWS) 并发管控&内存管控>,作者: fight ...

  7. GaussDB(DWS)应用实战:对被视图引用的表进行DDL操作

    摘要:GaussDB(DWS)是从Postgres演进过来的,像Postgres一样,如果表被视图引用的话,特定场景下,部分DDL操作是不能直接执行的. 背景说明 GaussDB(DWS)是从Post ...

  8. 详解GaussDB(DWS) explain分布式执行计划

    摘要:本文主要介绍如何详细解读GaussDB(DWS)产生的分布式执行计划,从计划中发现性能调优点. 前言 执行计划(又称解释计划)是数据库执行SQL语句的具体步骤,例如通过索引还是全表扫描访问表中的 ...

  9. 十八般武艺玩转GaussDB(DWS)性能调优(三):好味道表定义

    摘要:表结构设计是数据库建模的一个关键环节,表定义好坏直接决定了集群的有效容量以及业务查询性能,本文从产品架构.功能实现以及业务特征的角度阐述在GaussDB(DWS)的中表定义时需要关注的一些关键因 ...

  10. 十八般武艺玩转GaussDB(DWS)性能调优:SQL改写

    摘要:本文将系统介绍在GaussDB(DWS)系统中影响性能的坏味道SQL及SQL模式,帮助大家能够从原理层面尽快识别这些坏味道SQL,在调优过程中及时发现问题,进行整改. 数据库的应用中,充斥着坏味 ...

随机推荐

  1. Java 魔法值处理的四种方法

    Java 魔法值处理方案 魔法值的定义 方法一 静态常量(不推荐) 方法二 接口中定义 方法三 定义在实体类 方法四 使用枚举类 enum 总结 魔法值的定义 魔法值是Java中突兀出现在代码中的常量 ...

  2. We Need More Bosses 题解

    We Need More Bosses 题目大意 给定一张图,找到两个点,使得这两个点之间的所有路径必须经过的边最多. 思路分析 我们先来思考一下如果已知两个点,怎么求两个点之间必须经过的边的数量. ...

  3. Full Tank 题解

    Full Tank 题目大意 给定一张 \(n\) 个点,\(m\) 条边的连通无向图,在每个点有一个加油站,油价为该点的点权,每条边的油耗为该边的边权.现给出若干询问,问一辆油箱容量为 \(c\) ...

  4. Hello-FPGA CoaXPress 2.0 FPGA HOST IP Core PCIe Demo User Manual

    目录 1 说明 4 2 设备连接 7 3 VIVADO FPGA工程 8 4 调试说明 9 图 1‑1 资料目录 4 图 1‑2 VIVADO工程目录结构 5 图 1‑3 VS软件工程目录 5 图 1 ...

  5. InnoDB 存储引擎之 Buffer Pool

    Mysql 5.7 InnoDB 存储引擎整体逻辑架构图 一.Buffer Pool 概述 InnoDB 作为一个存储引擎,为了降低磁盘 IO,提升读写性能,必然有相应的缓冲池机制,这个缓冲池就是 B ...

  6. 为zabbix穿上一件漂亮的外衣

    zabbix+Grafana 7.0  zabbix的环境已部署好的情况下,zabbix部分-- 略 Grafana简介: 1.Grafana自身并存储数据,数据从其它地方获取.需要配置数据源 2.G ...

  7. codeforces div1A

    A. Circular Local MiniMax 题目翻译:给我们一个数组(循环的也就是1和n是相邻的),我们可以对数组进行任意调序,对于每个数b[i]要求满足b[i] < b[i - 1] ...

  8. 贪心算法:7-6 Swan学院社团招新

    Swan学院社团招新,招新宣讲会分散在不同时间段,大一新生小花花想知道自己最多能完整的参加多少个招新宣讲会(参加一个招新宣讲会的时候不能中断或离开). [问题说明]这个问题是对几个相互竞争的招新宣讲会 ...

  9. AdaBoost算法解密:从基础到应用的全面解析

    本文全面而深入地探讨了AdaBoost算法,从其基础概念和原理到Python实战应用.文章不仅详细解析了AdaBoost的优缺点,还通过实例展示了如何在Python中实现该算法. 关注TechLead ...

  10. 自定义springboot-starter 动态数据源

    自定义springboot-starter 动态数据源 如果使用的是spring或springboot框架,spring提供了一个实现动态数据源的一个抽象类AbstractRoutingDataSou ...