Merge branch 'main' into fix-upgrade-typo

pull/7686/head
eaydingol 2024-09-16 16:32:34 +03:00 committed by GitHub
commit d410d5c90a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 194 additions and 4 deletions

View File

@ -858,7 +858,7 @@ ConvertRelationRTEIntoSubquery(Query *mergeQuery, RangeTblEntry *sourceRte,
newRangeTableRef->rtindex = SINGLE_RTE_INDEX; newRangeTableRef->rtindex = SINGLE_RTE_INDEX;
sourceResultsQuery->jointree = makeFromExpr(list_make1(newRangeTableRef), NULL); sourceResultsQuery->jointree = makeFromExpr(list_make1(newRangeTableRef), NULL);
sourceResultsQuery->targetList = sourceResultsQuery->targetList =
CreateAllTargetListForRelation(sourceRte->relid, requiredAttributes); CreateFilteredTargetListForRelation(sourceRte->relid, requiredAttributes);
List *restrictionList = List *restrictionList =
GetRestrictInfoListForRelation(sourceRte, plannerRestrictionContext); GetRestrictInfoListForRelation(sourceRte, plannerRestrictionContext);
List *copyRestrictionList = copyObject(restrictionList); List *copyRestrictionList = copyObject(restrictionList);

View File

@ -45,8 +45,6 @@
static RangeTblEntry * AnchorRte(Query *subquery); static RangeTblEntry * AnchorRte(Query *subquery);
static List * UnionRelationRestrictionLists(List *firstRelationList, static List * UnionRelationRestrictionLists(List *firstRelationList,
List *secondRelationList); List *secondRelationList);
static List * CreateFilteredTargetListForRelation(Oid relationId,
List *requiredAttributes);
static List * CreateDummyTargetList(Oid relationId, List *requiredAttributes); static List * CreateDummyTargetList(Oid relationId, List *requiredAttributes);
static TargetEntry * CreateTargetEntryForColumn(Form_pg_attribute attributeTuple, Index static TargetEntry * CreateTargetEntryForColumn(Form_pg_attribute attributeTuple, Index
rteIndex, rteIndex,
@ -378,7 +376,7 @@ CreateAllTargetListForRelation(Oid relationId, List *requiredAttributes)
* only the required columns of the given relation. If there is not required * only the required columns of the given relation. If there is not required
* columns then a dummy NULL column is put as the only entry. * columns then a dummy NULL column is put as the only entry.
*/ */
static List * List *
CreateFilteredTargetListForRelation(Oid relationId, List *requiredAttributes) CreateFilteredTargetListForRelation(Oid relationId, List *requiredAttributes)
{ {
Relation relation = relation_open(relationId, AccessShareLock); Relation relation = relation_open(relationId, AccessShareLock);

View File

@ -39,5 +39,7 @@ extern Query * WrapRteRelationIntoSubquery(RangeTblEntry *rteRelation,
List *requiredAttributes, List *requiredAttributes,
RTEPermissionInfo *perminfo); RTEPermissionInfo *perminfo);
extern List * CreateAllTargetListForRelation(Oid relationId, List *requiredAttributes); extern List * CreateAllTargetListForRelation(Oid relationId, List *requiredAttributes);
extern List * CreateFilteredTargetListForRelation(Oid relationId,
List *requiredAttributes);
#endif /* QUERY_COLOCATION_CHECKER_H */ #endif /* QUERY_COLOCATION_CHECKER_H */

View File

@ -476,6 +476,112 @@ WHEN MATCHED THEN DO NOTHING;
Filter: ('2'::bigint = id) Filter: ('2'::bigint = id)
(11 rows) (11 rows)
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');
create_distributed_table
---------------------------------------------------------------------
(1 row)
SELECT create_distributed_table('target', 'id', colocate_with=>'none');
create_distributed_table
---------------------------------------------------------------------
(1 row)
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;
id | age | salary
---------------------------------------------------------------------
1 | | 100000
(1 row)
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');
create_distributed_table
---------------------------------------------------------------------
(1 row)
SELECT create_distributed_table('target', 'id', colocate_with=>'none');
create_distributed_table
---------------------------------------------------------------------
(1 row)
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;
id | age | salary
---------------------------------------------------------------------
1 | | 100000
(1 row)
DROP TABLE IF EXISTS source;
DROP TABLE IF EXISTS target;
-- Test 3
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');
create_distributed_table
---------------------------------------------------------------------
(1 row)
SELECT create_distributed_table('target', 'id', colocate_with=>'none');
create_distributed_table
---------------------------------------------------------------------
(1 row)
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, age) VALUES (source.age, source.id, source.salary);
SELECT * FROM TARGET;
id | age | salary
---------------------------------------------------------------------
1 | 100000 | 30
(1 row)
DROP TABLE IF EXISTS source; DROP TABLE IF EXISTS source;
DROP TABLE IF EXISTS target; DROP TABLE IF EXISTS target;
DROP SCHEMA IF EXISTS merge_vcore_schema CASCADE; DROP SCHEMA IF EXISTS merge_vcore_schema CASCADE;

View File

@ -312,6 +312,90 @@ WHEN MATCHED THEN DO NOTHING;
DROP TABLE IF EXISTS source; DROP TABLE IF EXISTS source;
DROP TABLE IF EXISTS target; 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;
-- Test 3
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, age) VALUES (source.age, source.id, source.salary);
SELECT * FROM TARGET;
DROP TABLE IF EXISTS source;
DROP TABLE IF EXISTS target;
DROP SCHEMA IF EXISTS merge_vcore_schema CASCADE; DROP SCHEMA IF EXISTS merge_vcore_schema CASCADE;