fix expalin merge into and fastcheck test case

This commit is contained in:
gentle_hu
2021-07-31 14:52:05 +08:00
parent 35fff99804
commit 70dffe0fda
4 changed files with 47 additions and 21 deletions

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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