From cccba66f24a59ff05971d1ea5c5bb328a8accf17 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Wed, 22 Jun 2016 14:36:36 -0700 Subject: [PATCH] Support RETURNING for modification commands. Fixes: #242 --- .../master/master_modify_multiple_shards.c | 8 ++++++++ .../distributed/planner/multi_router_planner.c | 15 +++++---------- src/test/regress/expected/multi_modifications.out | 13 ------------- src/test/regress/expected/multi_shard_modify.out | 6 ++---- src/test/regress/sql/multi_modifications.sql | 10 ---------- 5 files changed, 15 insertions(+), 37 deletions(-) diff --git a/src/backend/distributed/master/master_modify_multiple_shards.c b/src/backend/distributed/master/master_modify_multiple_shards.c index 0ca5afc52..48d82e66e 100644 --- a/src/backend/distributed/master/master_modify_multiple_shards.c +++ b/src/backend/distributed/master/master_modify_multiple_shards.c @@ -116,6 +116,14 @@ master_modify_multiple_shards(PG_FUNCTION_ARGS) ErrorIfModifyQueryNotSupported(modifyQuery); + /* reject queries with a returning list */ + if (list_length(modifyQuery->returningList) > 0) + { + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("master_modify_multiple_shards() does not support RETURNING"))); + } + shardIntervalList = LoadShardIntervalList(relationId); restrictClauseList = WhereClauseList(modifyQuery->jointree); diff --git a/src/backend/distributed/planner/multi_router_planner.c b/src/backend/distributed/planner/multi_router_planner.c index cf12fefa0..5f76b3194 100644 --- a/src/backend/distributed/planner/multi_router_planner.c +++ b/src/backend/distributed/planner/multi_router_planner.c @@ -255,16 +255,6 @@ ErrorIfModifyQueryNotSupported(Query *queryTree) "supported."))); } - /* reject queries with a returning list */ - if (list_length(queryTree->returningList) > 0) - { - ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot perform distributed planning for the given" - " modification"), - errdetail("RETURNING clauses are not supported in distributed " - "modifications."))); - } - if (commandType == CMD_INSERT || commandType == CMD_UPDATE || commandType == CMD_DELETE) { @@ -298,6 +288,11 @@ ErrorIfModifyQueryNotSupported(Query *queryTree) { hasNonConstQualExprs = true; } + + if (contain_mutable_functions((Node *) queryTree->returningList)) + { + hasNonConstTargetEntryExprs = true; + } } #if (PG_VERSION_NUM >= 90500) diff --git a/src/test/regress/expected/multi_modifications.out b/src/test/regress/expected/multi_modifications.out index 970d4ff45..c61b225de 100644 --- a/src/test/regress/expected/multi_modifications.out +++ b/src/test/regress/expected/multi_modifications.out @@ -195,11 +195,6 @@ DETAIL: Multi-row INSERTs to distributed tables are not supported. INSERT INTO limit_orders SELECT * FROM limit_orders; ERROR: cannot perform distributed planning for the given modifications DETAIL: Subqueries are not supported in distributed modifications. --- commands with a RETURNING clause are unsupported -INSERT INTO limit_orders VALUES (7285, 'AMZN', 3278, '2016-01-05 02:07:36', 'sell', 0.00) - RETURNING *; -ERROR: cannot perform distributed planning for the given modification -DETAIL: RETURNING clauses are not supported in distributed modifications. -- commands containing a CTE are unsupported WITH deleted_orders AS (DELETE FROM limit_orders RETURNING *) INSERT INTO limit_orders DEFAULT VALUES; @@ -244,10 +239,6 @@ DELETE FROM limit_orders USING bidders WHERE limit_orders.id = 246 AND limit_orders.bidder_id = bidders.id AND bidders.name = 'Bernie Madoff'; ERROR: cannot plan queries that include both regular and partitioned relations --- commands with a RETURNING clause are unsupported -DELETE FROM limit_orders WHERE id = 246 RETURNING *; -ERROR: cannot perform distributed planning for the given modification -DETAIL: RETURNING clauses are not supported in distributed modifications. -- commands containing a CTE are unsupported WITH deleted_orders AS (INSERT INTO limit_orders DEFAULT VALUES RETURNING *) DELETE FROM limit_orders; @@ -363,10 +354,6 @@ UPDATE limit_orders SET limit_price = 0.00 FROM bidders limit_orders.bidder_id = bidders.id AND bidders.name = 'Bernie Madoff'; ERROR: cannot plan queries that include both regular and partitioned relations --- commands with a RETURNING clause are unsupported -UPDATE limit_orders SET symbol = 'GM' WHERE id = 246 RETURNING *; -ERROR: cannot perform distributed planning for the given modification -DETAIL: RETURNING clauses are not supported in distributed modifications. -- commands containing a CTE are unsupported WITH deleted_orders AS (INSERT INTO limit_orders DEFAULT VALUES RETURNING *) UPDATE limit_orders SET symbol = 'GM'; diff --git a/src/test/regress/expected/multi_shard_modify.out b/src/test/regress/expected/multi_shard_modify.out index 59a815659..0d4e389d6 100644 --- a/src/test/regress/expected/multi_shard_modify.out +++ b/src/test/regress/expected/multi_shard_modify.out @@ -62,8 +62,7 @@ ERROR: cannot perform distributed planning for the given modification DETAIL: Joins are not supported in distributed modifications. -- commands with a RETURNING clause are unsupported SELECT master_modify_multiple_shards('DELETE FROM multi_shard_modify_test WHERE t_key = 3 RETURNING *'); -ERROR: cannot perform distributed planning for the given modification -DETAIL: RETURNING clauses are not supported in distributed modifications. +ERROR: master_modify_multiple_shards() does not support RETURNING -- commands containing a CTE are unsupported SELECT master_modify_multiple_shards('WITH deleted_stuff AS (INSERT INTO multi_shard_modify_test DEFAULT VALUES RETURNING *) DELETE FROM multi_shard_modify_test'); ERROR: cannot perform distributed planning for the given modification @@ -205,8 +204,7 @@ ERROR: cannot perform distributed planning for the given modification DETAIL: Joins are not supported in distributed modifications. -- commands with a RETURNING clause are unsupported SELECT master_modify_multiple_shards('UPDATE multi_shard_modify_test SET t_name=''FAIL'' WHERE t_key=4 RETURNING *'); -ERROR: cannot perform distributed planning for the given modification -DETAIL: RETURNING clauses are not supported in distributed modifications. +ERROR: master_modify_multiple_shards() does not support RETURNING -- commands containing a CTE are unsupported SELECT master_modify_multiple_shards('WITH t AS (INSERT INTO multi_shard_modify_test DEFAULT VALUES RETURNING *) UPDATE multi_shard_modify_test SET t_name = ''FAIL'' '); ERROR: cannot perform distributed planning for the given modification diff --git a/src/test/regress/sql/multi_modifications.sql b/src/test/regress/sql/multi_modifications.sql index f85623cc1..935a9228a 100644 --- a/src/test/regress/sql/multi_modifications.sql +++ b/src/test/regress/sql/multi_modifications.sql @@ -143,10 +143,6 @@ INSERT INTO limit_orders VALUES (DEFAULT), (DEFAULT); -- INSERT ... SELECT ... FROM commands are unsupported INSERT INTO limit_orders SELECT * FROM limit_orders; --- commands with a RETURNING clause are unsupported -INSERT INTO limit_orders VALUES (7285, 'AMZN', 3278, '2016-01-05 02:07:36', 'sell', 0.00) - RETURNING *; - -- commands containing a CTE are unsupported WITH deleted_orders AS (DELETE FROM limit_orders RETURNING *) INSERT INTO limit_orders DEFAULT VALUES; @@ -174,9 +170,6 @@ DELETE FROM limit_orders USING bidders WHERE limit_orders.id = 246 AND limit_orders.bidder_id = bidders.id AND bidders.name = 'Bernie Madoff'; --- commands with a RETURNING clause are unsupported -DELETE FROM limit_orders WHERE id = 246 RETURNING *; - -- commands containing a CTE are unsupported WITH deleted_orders AS (INSERT INTO limit_orders DEFAULT VALUES RETURNING *) DELETE FROM limit_orders; @@ -275,9 +268,6 @@ UPDATE limit_orders SET limit_price = 0.00 FROM bidders limit_orders.bidder_id = bidders.id AND bidders.name = 'Bernie Madoff'; --- commands with a RETURNING clause are unsupported -UPDATE limit_orders SET symbol = 'GM' WHERE id = 246 RETURNING *; - -- commands containing a CTE are unsupported WITH deleted_orders AS (INSERT INTO limit_orders DEFAULT VALUES RETURNING *) UPDATE limit_orders SET symbol = 'GM';