From 70dffe0fda5f3e6e816512cb034dcb002940dcc2 Mon Sep 17 00:00:00 2001 From: gentle_hu Date: Sat, 31 Jul 2021 14:52:05 +0800 Subject: [PATCH] fix expalin merge into and fastcheck test case --- src/common/backend/utils/adt/ruleutils.cpp | 5 ++ src/test/regress/expected/merge_1.out | 54 ++++++++++++++-------- src/test/regress/parallel_schedule0 | 2 +- src/test/regress/sql/merge_1.sql | 7 +++ 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/common/backend/utils/adt/ruleutils.cpp b/src/common/backend/utils/adt/ruleutils.cpp index f3a770ad9..8e742754d 100644 --- a/src/common/backend/utils/adt/ruleutils.cpp +++ b/src/common/backend/utils/adt/ruleutils.cpp @@ -4275,7 +4275,12 @@ static void set_deparse_planstate(deparse_namespace* dpns, PlanState* ps) } else dpns->inner_planstate = innerPlanState(ps); +#ifdef ENABLE_MULTIPLE_NODES if (IsA(ps, ModifyTableState)) +#else + if (IsA(ps, ModifyTableState) && ((ModifyTableState*)ps)->mt_upsert != NULL && + ((ModifyTableState*)ps)->mt_upsert->us_action != UPSERT_NONE) +#endif dpns->inner_tlist = ((ModifyTableState*)ps)->mt_upsert->us_excludedtlist; else if (dpns->inner_planstate != NULL) dpns->inner_tlist = dpns->inner_planstate->plan->targetlist; diff --git a/src/test/regress/expected/merge_1.out b/src/test/regress/expected/merge_1.out index 61b5725b5..02e66e9dc 100644 --- a/src/test/regress/expected/merge_1.out +++ b/src/test/regress/expected/merge_1.out @@ -51,6 +51,27 @@ INSERT INTO newproducts_row SELECT * FROM newproducts_base; ANALYZE products_row; ANALYZE newproducts_row; -- explain verbose +EXPLAIN (VERBOSE on, COSTS off) +MERGE INTO products_row p +USING newproducts_row np +ON p.product_id = np.product_id +WHEN MATCHED THEN + UPDATE SET product_name = np.product_name, category = np.category, total = np.total where np.product_id = 5; + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------- + Merge on mergeinto_1.products_row p + Update Cond: (p.product_id = 5) + -> Hash Join + Output: np.product_id, np.product_name, np.category, np.total, p.product_id, p.product_name, p.category, p.total, p.ctid, np.ctid + Hash Cond: (p.product_id = np.product_id) + -> Seq Scan on mergeinto_1.products_row p + Output: p.product_id, p.product_name, p.category, p.total, p.ctid + -> Hash + Output: np.product_id, np.product_name, np.category, np.total, np.ctid + -> Seq Scan on mergeinto_1.newproducts_row np + Output: np.product_id, np.product_name, np.category, np.total, np.ctid +(11 rows) + EXPLAIN (VERBOSE on, COSTS off) MERGE INTO products_row p USING newproducts_row np @@ -59,26 +80,19 @@ WHEN MATCHED THEN UPDATE SET product_name = np.product_name, category = np.category, total = np.total WHEN NOT MATCHED THEN INSERT VALUES (np.product_id, np.product_name, np.category, np.total); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Streaming (type: GATHER) - Node/s: All datanodes - -> Merge on mergeinto_1.products_row p - -> Streaming(type: REDISTRIBUTE) - Output: np.product_id, np.product_name, np.category, np.total, p.product_id, p.product_name, p.category, p.total, p.ctid, p.xc_node_id, np.ctid, (CASE WHEN (p.ctid IS NULL) THEN np.product_id ELSE p.product_id END) - Distribute Key: (CASE WHEN (p.ctid IS NULL) THEN np.product_id ELSE p.product_id END) - Spawn on: All datanodes - Consumer Nodes: All datanodes - -> Nested Loop Left Join - Output: np.product_id, np.product_name, np.category, np.total, p.product_id, p.product_name, p.category, p.total, p.ctid, p.xc_node_id, np.ctid, CASE WHEN (p.ctid IS NULL) THEN np.product_id ELSE p.product_id END - Join Filter: (p.product_id = np.product_id) - -> Seq Scan on mergeinto_1.newproducts_row np - Output: np.product_id, np.product_name, np.category, np.total, np.ctid - Distribute Key: np.product_id - -> Seq Scan on mergeinto_1.products_row p - Output: p.product_id, p.product_name, p.category, p.total, p.ctid, p.xc_node_id - Distribute Key: p.product_id -(17 rows) + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------- + Merge on mergeinto_1.products_row p + -> Hash Right Join + Output: np.product_id, np.product_name, np.category, np.total, p.product_id, p.product_name, p.category, p.total, p.ctid, np.ctid + Hash Cond: (p.product_id = np.product_id) + -> Seq Scan on mergeinto_1.products_row p + Output: p.product_id, p.product_name, p.category, p.total, p.ctid + -> Hash + Output: np.product_id, np.product_name, np.category, np.total, np.ctid + -> Seq Scan on mergeinto_1.newproducts_row np + Output: np.product_id, np.product_name, np.category, np.total, np.ctid +(10 rows) -- only MATCHED clause MERGE INTO products_row p diff --git a/src/test/regress/parallel_schedule0 b/src/test/regress/parallel_schedule0 index 66263b492..9a5eab897 100644 --- a/src/test/regress/parallel_schedule0 +++ b/src/test/regress/parallel_schedule0 @@ -155,7 +155,7 @@ test: single_node_sequence # run and check forbidden functions are still forbidden to use in single node test: single_node_forbidden -test: single_node_mergeinto +test: single_node_mergeinto merge_1 # Trigger tests test: single_node_triggers diff --git a/src/test/regress/sql/merge_1.sql b/src/test/regress/sql/merge_1.sql index b6e856c4c..51c8349fa 100644 --- a/src/test/regress/sql/merge_1.sql +++ b/src/test/regress/sql/merge_1.sql @@ -64,6 +64,13 @@ ANALYZE products_row; ANALYZE newproducts_row; -- explain verbose +EXPLAIN (VERBOSE on, COSTS off) +MERGE INTO products_row p +USING newproducts_row np +ON p.product_id = np.product_id +WHEN MATCHED THEN + UPDATE SET product_name = np.product_name, category = np.category, total = np.total where np.product_id = 5; + EXPLAIN (VERBOSE on, COSTS off) MERGE INTO products_row p USING newproducts_row np