Skip to content

Commit

Permalink
[BACKPORT 2.6][YSQL] [#9572] Correctly determine is_yb_relation for r…
Browse files Browse the repository at this point in the history
…ow-marked relations when preparing target list

Summary:
Presently, when iterating through the row-marked relations to add the necessary columns to the target list, we determined whether to get the YB TID or the CTID based on the target relation. However, this check should be done using the row-marked relation instead.
The previous version of the code fails to work when the target relation is a YB relation and the row-marked relation is a temporary relation.
(Eg: `UPDATE test1 SET z = 2 FROM test2 WHERE test1.x = test2.x;` where test2 is a temporary relation and test1 is a YB relation)

Original Commit: [[ f148418 | f148418 ]]

Original Differential Revision: https://phabricator.dev.yugabyte.com/D12994

Test Plan:
Jenkins: rebase: 2.6

Run `TestPgRegressFeature` to execute `yb_feature_temp`

Reviewers: mihnea, amartsinchyk

Reviewed By: amartsinchyk

Differential Revision: https://phabricator.dev.yugabyte.com/D13108
  • Loading branch information
Fizaa Luthra authored and Fizaa Luthra committed Sep 21, 2021
1 parent 2220e08 commit e11283e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/postgres/src/backend/optimizer/prep/preptlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,7 @@ preprocess_targetlist(PlannerInfo *root)

if (rc->allMarkTypes & ~(1 << ROW_MARK_COPY))
{
bool is_yb_relation = false;
if (!target_relation)
is_yb_relation = IsYBRelationById(getrelid(rc->rti, range_table));
else
is_yb_relation = IsYBBackedRelation(target_relation);

if (is_yb_relation)
if (IsYBRelationById(getrelid(rc->rti, range_table)))
{
/* Need to fetch YB TID */
var = makeVar(rc->rti,
Expand Down
10 changes: 10 additions & 0 deletions src/postgres/src/test/regress/expected/yb_feature_temp.out
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,13 @@ INSERT INTO temptest VALUES (101, 201, 301), (101, 201, 301);
ERROR: duplicate key value violates unique constraint "temptest_pkey"
DETAIL: Key (k)=(101) already exists.
DROP TABLE temptest;
-- test temp table being used to update YB table.
CREATE TABLE test1 (x int, y int, z int);
INSERT INTO test1 VALUES (1, 2, 3);
CREATE TEMP TABLE test2 as table test1;
UPDATE test1 SET z = 2 FROM test2 WHERE test1.x = test2.x;
SELECT * FROM test1;
x | y | z
---+---+---
1 | 2 | 2
(1 row)
7 changes: 7 additions & 0 deletions src/postgres/src/test/regress/sql/yb_feature_temp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,10 @@ INSERT INTO temptest VALUES (100, 200, 300);
INSERT INTO temptest VALUES (101, 201, 301), (101, 201, 301);

DROP TABLE temptest;

-- test temp table being used to update YB table.
CREATE TABLE test1 (x int, y int, z int);
INSERT INTO test1 VALUES (1, 2, 3);
CREATE TEMP TABLE test2 as table test1;
UPDATE test1 SET z = 2 FROM test2 WHERE test1.x = test2.x;
SELECT * FROM test1;

0 comments on commit e11283e

Please sign in to comment.