Skip to content

Commit

Permalink
Fix issue with some zero-shard modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoslot committed Dec 12, 2019
1 parent 2c040d2 commit e7a8db5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/backend/distributed/planner/multi_physical_planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -5122,6 +5122,11 @@ ReorderAndAssignTaskList(List *taskList, List * (*reorderFunction)(Task *, List
ListCell *placementListCell = NULL;
uint32 unAssignedTaskCount = 0;

if (taskList == NIL)
{
return NIL;
}

/*
* We first sort tasks by their anchor shard id. We then sort placements for
* each anchor shard by the placement's insertion time. Note that we sort
Expand Down
6 changes: 5 additions & 1 deletion src/backend/distributed/planner/multi_router_planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,11 @@ RouterJob(Query *originalQuery, PlannerRestrictionContext *plannerRestrictionCon
MODIFY_TASK,
requiresMasterEvaluation);
}
else if (shardId == INVALID_SHARD_ID)
{
/* modification that prunes to 0 shards */
job->taskList = NIL;
}
else
{
job->taskList = SingleShardModifyTaskList(originalQuery, job->jobId,
Expand Down Expand Up @@ -2068,7 +2073,6 @@ PlanRouterQuery(Query *originalQuery,
}

Assert(UpdateOrDeleteQuery(originalQuery));

planningError = ModifyQuerySupported(originalQuery, originalQuery,
isMultiShardQuery,
plannerRestrictionContext);
Expand Down
7 changes: 7 additions & 0 deletions src/test/regress/expected/multi_modifications.out
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,13 @@ INSERT INTO raw_table VALUES (2, 400);
INSERT INTO raw_table VALUES (2, 500);
INSERT INTO summary_table VALUES (1);
INSERT INTO summary_table VALUES (2);
-- test noop deletes and updates
DELETE FROM summary_table WHERE false;
DELETE FROM summary_table WHERE null;
DELETE FROM summary_table WHERE null > jsonb_build_array();
UPDATE summary_table SET uniques = 0 WHERE false;
UPDATE summary_table SET uniques = 0 WHERE null;
UPDATE summary_table SET uniques = 0 WHERE null > jsonb_build_array();
SELECT * FROM summary_table ORDER BY id;
id | min_value | average_value | count | uniques
----+-----------+---------------+-------+---------
Expand Down
9 changes: 9 additions & 0 deletions src/test/regress/sql/multi_modifications.sql
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,15 @@ INSERT INTO raw_table VALUES (2, 500);
INSERT INTO summary_table VALUES (1);
INSERT INTO summary_table VALUES (2);

-- test noop deletes and updates
DELETE FROM summary_table WHERE false;
DELETE FROM summary_table WHERE null;
DELETE FROM summary_table WHERE null > jsonb_build_array();

UPDATE summary_table SET uniques = 0 WHERE false;
UPDATE summary_table SET uniques = 0 WHERE null;
UPDATE summary_table SET uniques = 0 WHERE null > jsonb_build_array();

SELECT * FROM summary_table ORDER BY id;

UPDATE summary_table SET average_value = average_query.average FROM (
Expand Down

0 comments on commit e7a8db5

Please sign in to comment.