mirror of https://github.com/citusdata/citus.git
Merge pull request #1749 from citusdata/fix_reference_table_insert_into_select
Don't try to add restrictions for reference tables in insert into selectpull/1744/head
commit
d7171838d7
|
@ -66,6 +66,7 @@ RebuildQueryStrings(Query *originalQuery, List *taskList)
|
|||
Query *copiedSubquery = NULL;
|
||||
List *relationShardList = task->relationShardList;
|
||||
ShardInterval *shardInterval = LoadShardInterval(task->anchorShardId);
|
||||
char partitionMethod = 0;
|
||||
|
||||
query = copyObject(originalQuery);
|
||||
|
||||
|
@ -73,7 +74,13 @@ RebuildQueryStrings(Query *originalQuery, List *taskList)
|
|||
copiedSubqueryRte = ExtractSelectRangeTableEntry(query);
|
||||
copiedSubquery = copiedSubqueryRte->subquery;
|
||||
|
||||
AddShardIntervalRestrictionToSelect(copiedSubquery, shardInterval);
|
||||
/* there are no restrictions to add for reference tables */
|
||||
partitionMethod = PartitionMethod(shardInterval->relationId);
|
||||
if (partitionMethod != DISTRIBUTE_BY_NONE)
|
||||
{
|
||||
AddShardIntervalRestrictionToSelect(copiedSubquery, shardInterval);
|
||||
}
|
||||
|
||||
ReorderInsertSelectTargetLists(query, copiedInsertRte, copiedSubqueryRte);
|
||||
|
||||
/* setting an alias simplifies deparsing of RETURNING */
|
||||
|
|
|
@ -2392,6 +2392,39 @@ SELECT * FROM ref_table ORDER BY user_id, value_1;
|
|||
(5 rows)
|
||||
|
||||
DROP TABLE ref_table;
|
||||
-- Select from reference table into reference table
|
||||
CREATE TABLE ref1 (d timestamptz);
|
||||
SELECT create_reference_table('ref1');
|
||||
create_reference_table
|
||||
------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE TABLE ref2 (d date);
|
||||
SELECT create_reference_table('ref2');
|
||||
create_reference_table
|
||||
------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
INSERT INTO ref2 VALUES ('2017-10-31');
|
||||
INSERT INTO ref1 SELECT * FROM ref2;
|
||||
SELECT count(*) from ref1;
|
||||
count
|
||||
-------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
-- also test with now()
|
||||
INSERT INTO ref1 SELECT now() FROM ref2;
|
||||
SELECT count(*) from ref1;
|
||||
count
|
||||
-------
|
||||
2
|
||||
(1 row)
|
||||
|
||||
DROP TABLE ref1;
|
||||
DROP TABLE ref2;
|
||||
-- Select into an append-partitioned table is not supported
|
||||
CREATE TABLE insert_append_table (user_id int, value_4 bigint);
|
||||
SELECT create_distributed_table('insert_append_table', 'user_id', 'append');
|
||||
|
|
|
@ -1885,6 +1885,25 @@ SELECT * FROM ref_table ORDER BY user_id, value_1;
|
|||
|
||||
DROP TABLE ref_table;
|
||||
|
||||
-- Select from reference table into reference table
|
||||
CREATE TABLE ref1 (d timestamptz);
|
||||
SELECT create_reference_table('ref1');
|
||||
|
||||
CREATE TABLE ref2 (d date);
|
||||
SELECT create_reference_table('ref2');
|
||||
INSERT INTO ref2 VALUES ('2017-10-31');
|
||||
|
||||
INSERT INTO ref1 SELECT * FROM ref2;
|
||||
SELECT count(*) from ref1;
|
||||
|
||||
-- also test with now()
|
||||
INSERT INTO ref1 SELECT now() FROM ref2;
|
||||
SELECT count(*) from ref1;
|
||||
|
||||
|
||||
DROP TABLE ref1;
|
||||
DROP TABLE ref2;
|
||||
|
||||
-- Select into an append-partitioned table is not supported
|
||||
CREATE TABLE insert_append_table (user_id int, value_4 bigint);
|
||||
SELECT create_distributed_table('insert_append_table', 'user_id', 'append');
|
||||
|
|
Loading…
Reference in New Issue