Skip to content

Commit

Permalink
Support RETURNING for modification commands.
Browse files Browse the repository at this point in the history
Fixes: #242
  • Loading branch information
anarazel committed Jun 3, 2016
1 parent 67820f5 commit 5a0c4cd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 5 additions & 10 deletions src/backend/distributed/planner/multi_router_planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,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)
{
Expand Down Expand Up @@ -289,6 +279,11 @@ ErrorIfModifyQueryNotSupported(Query *queryTree)
{
hasNonConstQualExprs = true;
}

if (contain_mutable_functions((Node *) queryTree->returningList))
{
hasNonConstTargetEntryExprs = true;
}
}

#if (PG_VERSION_NUM >= 90500)
Expand Down
13 changes: 0 additions & 13 deletions src/test/regress/expected/multi_modifications.out
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,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;
Expand Down Expand Up @@ -239,10 +234,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;
Expand Down Expand Up @@ -325,10 +316,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';
Expand Down
6 changes: 2 additions & 4 deletions src/test/regress/expected/multi_shard_modify.out
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,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
Expand Down Expand Up @@ -204,8 +203,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
Expand Down
10 changes: 0 additions & 10 deletions src/test/regress/sql/multi_modifications.sql
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,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;
Expand Down Expand Up @@ -171,9 +167,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;
Expand Down Expand Up @@ -238,9 +231,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';
Expand Down

0 comments on commit 5a0c4cd

Please sign in to comment.