mirror of https://github.com/citusdata/citus.git
Initial changes
parent
3c467e6e02
commit
cd76b7649c
|
@ -857,8 +857,11 @@ ConvertRelationRTEIntoSubquery(Query *mergeQuery, RangeTblEntry *sourceRte,
|
|||
/* set the FROM expression to the subquery */
|
||||
newRangeTableRef->rtindex = SINGLE_RTE_INDEX;
|
||||
sourceResultsQuery->jointree = makeFromExpr(list_make1(newRangeTableRef), NULL);
|
||||
|
||||
bool isMergeQuery = true;
|
||||
sourceResultsQuery->targetList =
|
||||
CreateAllTargetListForRelation(sourceRte->relid, requiredAttributes);
|
||||
CreateAllTargetListForRelation(sourceRte->relid, requiredAttributes,
|
||||
isMergeQuery);
|
||||
List *restrictionList =
|
||||
GetRestrictInfoListForRelation(sourceRte, plannerRestrictionContext);
|
||||
List *copyRestrictionList = copyObject(restrictionList);
|
||||
|
|
|
@ -325,13 +325,14 @@ WrapRteRelationIntoSubquery(RangeTblEntry *rteRelation,
|
|||
* as a NULL column.
|
||||
*/
|
||||
List *
|
||||
CreateAllTargetListForRelation(Oid relationId, List *requiredAttributes)
|
||||
CreateAllTargetListForRelation(Oid relationId, List *requiredAttributes, bool
|
||||
isMergeQuery)
|
||||
{
|
||||
Relation relation = relation_open(relationId, AccessShareLock);
|
||||
int numberOfAttributes = RelationGetNumberOfAttributes(relation);
|
||||
|
||||
List *targetList = NIL;
|
||||
int varAttrNo = 1;
|
||||
int colAppendIdx = 1;
|
||||
|
||||
for (int attrNum = 1; attrNum <= numberOfAttributes; attrNum++)
|
||||
{
|
||||
|
@ -361,8 +362,9 @@ CreateAllTargetListForRelation(Oid relationId, List *requiredAttributes)
|
|||
}
|
||||
else
|
||||
{
|
||||
int varAttNum = isMergeQuery ? attrNum : colAppendIdx++;
|
||||
TargetEntry *targetEntry =
|
||||
CreateTargetEntryForColumn(attributeTuple, SINGLE_RTE_INDEX, varAttrNo++,
|
||||
CreateTargetEntryForColumn(attributeTuple, SINGLE_RTE_INDEX, varAttNum,
|
||||
resNo);
|
||||
targetList = lappend(targetList, targetEntry);
|
||||
}
|
||||
|
|
|
@ -1767,8 +1767,11 @@ ReplaceRTERelationWithRteSubquery(RangeTblEntry *rangeTableEntry,
|
|||
{
|
||||
Query *subquery = WrapRteRelationIntoSubquery(rangeTableEntry, requiredAttrNumbers,
|
||||
perminfo);
|
||||
|
||||
bool isMergeQuery = false;
|
||||
List *outerQueryTargetList = CreateAllTargetListForRelation(rangeTableEntry->relid,
|
||||
requiredAttrNumbers);
|
||||
requiredAttrNumbers,
|
||||
isMergeQuery);
|
||||
|
||||
List *restrictionList =
|
||||
GetRestrictInfoListForRelation(rangeTableEntry,
|
||||
|
@ -2109,7 +2112,6 @@ TransformFunctionRTE(RangeTblEntry *rangeTblEntry)
|
|||
subquery->targetList = lappend(subquery->targetList, targetEntry);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If tupleDesc is NULL we have 2 different cases:
|
||||
*
|
||||
|
@ -2159,7 +2161,6 @@ TransformFunctionRTE(RangeTblEntry *rangeTblEntry)
|
|||
columnType = list_nth_oid(rangeTblFunction->funccoltypes,
|
||||
targetColumnIndex);
|
||||
}
|
||||
|
||||
/* use the types in the function definition otherwise */
|
||||
else
|
||||
{
|
||||
|
|
|
@ -38,6 +38,7 @@ extern bool SubqueryColocated(Query *subquery, ColocatedJoinChecker *context);
|
|||
extern Query * WrapRteRelationIntoSubquery(RangeTblEntry *rteRelation,
|
||||
List *requiredAttributes,
|
||||
RTEPermissionInfo *perminfo);
|
||||
extern List * CreateAllTargetListForRelation(Oid relationId, List *requiredAttributes);
|
||||
extern List * CreateAllTargetListForRelation(Oid relationId, List *requiredAttributes,
|
||||
bool isMergeQuery);
|
||||
|
||||
#endif /* QUERY_COLOCATION_CHECKER_H */
|
||||
|
|
|
@ -312,6 +312,63 @@ WHEN MATCHED THEN DO NOTHING;
|
|||
DROP TABLE IF EXISTS source;
|
||||
DROP TABLE IF EXISTS target;
|
||||
|
||||
|
||||
-- Bug Fix Test as part of this PR
|
||||
-- Test 1
|
||||
CREATE TABLE source (
|
||||
id int,
|
||||
age int,
|
||||
salary int
|
||||
);
|
||||
|
||||
CREATE TABLE target (
|
||||
id int,
|
||||
age int,
|
||||
salary int
|
||||
);
|
||||
|
||||
SELECT create_distributed_table('source', 'id', colocate_with=>'none');
|
||||
SELECT create_distributed_table('target', 'id', colocate_with=>'none');
|
||||
|
||||
INSERT INTO source (id, age, salary) VALUES (1,30, 100000);
|
||||
|
||||
MERGE INTO ONLY target USING source ON (source.id = target.id)
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (id, salary) VALUES (source.id, source.salary);
|
||||
|
||||
SELECT * FROM TARGET;
|
||||
DROP TABLE IF EXISTS source;
|
||||
DROP TABLE IF EXISTS target;
|
||||
|
||||
|
||||
-- Test 2
|
||||
CREATE TABLE source (
|
||||
id int,
|
||||
age int,
|
||||
salary int
|
||||
);
|
||||
|
||||
CREATE TABLE target (
|
||||
id int,
|
||||
age int,
|
||||
salary int
|
||||
);
|
||||
|
||||
SELECT create_distributed_table('source', 'id', colocate_with=>'none');
|
||||
SELECT create_distributed_table('target', 'id', colocate_with=>'none');
|
||||
|
||||
INSERT INTO source (id, age, salary) VALUES (1,30, 100000);
|
||||
|
||||
MERGE INTO ONLY target USING source ON (source.id = target.id)
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT (salary, id) VALUES (source.salary, source.id);
|
||||
|
||||
SELECT * FROM TARGET;
|
||||
DROP TABLE IF EXISTS source;
|
||||
DROP TABLE IF EXISTS target;
|
||||
|
||||
|
||||
|
||||
DROP SCHEMA IF EXISTS merge_vcore_schema CASCADE;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue