Merge pull request #1600 from citusdata/fix_multi_row_returning

Add alias for target in multi-row INSERTs
pull/1607/head
Marco Slot 2017-08-23 11:00:27 +02:00 committed by GitHub
commit a67d10957f
5 changed files with 21 additions and 8 deletions

View File

@ -82,11 +82,15 @@ RebuildQueryStrings(Query *originalQuery, List *taskList)
UpdateRelationToShardNames((Node *) copiedSubquery, relationShardList);
}
else if (task->upsertQuery)
else if (task->upsertQuery || valuesRTE != NULL)
{
RangeTblEntry *rangeTableEntry = NULL;
/* setting an alias simplifies deparsing of UPSERTs */
/*
* Always an alias in UPSERTs and multi-row INSERTs to avoid
* deparsing issues (e.g. RETURNING might reference the original
* table name, which has been replaced by a shard name).
*/
rangeTableEntry = linitial(query->rtable);
if (rangeTableEntry->alias == NULL)
{

View File

@ -305,7 +305,7 @@ Custom Scan (Citus Router)
Tasks Shown: All
-> Task
Node: host=localhost port=57638 dbname=regression
-> Insert on lineitem_290000
-> Insert on lineitem_290000 citus_table_alias
-> Values Scan on "*VALUES*"
-- Test update
EXPLAIN (COSTS FALSE)

View File

@ -305,7 +305,7 @@ Custom Scan (Citus Router)
Tasks Shown: All
-> Task
Node: host=localhost port=57638 dbname=regression
-> Insert on lineitem_290000
-> Insert on lineitem_290000 citus_table_alias
-> Values Scan on "*VALUES*"
-- Test update
EXPLAIN (COSTS FALSE)

View File

@ -211,10 +211,18 @@ SELECT COUNT(*) FROM limit_orders WHERE id BETWEEN 12037 AND 12039;
3
(1 row)
-- even those with functions
-- even those with functions and returning
INSERT INTO limit_orders VALUES (22037, 'GOOG', 5634, now(), 'buy', 0.50),
(22038, 'GOOG', 5634, now(), 'buy', 2.50),
(22039, 'GOOG', 5634, now(), 'buy', 1.50);
(22039, 'GOOG', 5634, now(), 'buy', 1.50)
RETURNING id;
id
-------
22038
22039
22037
(3 rows)
SELECT COUNT(*) FROM limit_orders WHERE id BETWEEN 22037 AND 22039;
count
-------

View File

@ -153,10 +153,11 @@ INSERT INTO limit_orders VALUES (12037, 'GOOG', 5634, '2001-04-16 03:37:28', 'bu
SELECT COUNT(*) FROM limit_orders WHERE id BETWEEN 12037 AND 12039;
-- even those with functions
-- even those with functions and returning
INSERT INTO limit_orders VALUES (22037, 'GOOG', 5634, now(), 'buy', 0.50),
(22038, 'GOOG', 5634, now(), 'buy', 2.50),
(22039, 'GOOG', 5634, now(), 'buy', 1.50);
(22039, 'GOOG', 5634, now(), 'buy', 1.50)
RETURNING id;
SELECT COUNT(*) FROM limit_orders WHERE id BETWEEN 22037 AND 22039;