Skip to content

Commit e11283e

Browse files
Fizaa LuthraFizaa Luthra
Fizaa Luthra
authored and
Fizaa Luthra
committed
[BACKPORT 2.6][YSQL] [#9572] Correctly determine is_yb_relation for row-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
1 parent 2220e08 commit e11283e

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/postgres/src/backend/optimizer/prep/preptlist.c

+1-7
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,7 @@ preprocess_targetlist(PlannerInfo *root)
143143

144144
if (rc->allMarkTypes & ~(1 << ROW_MARK_COPY))
145145
{
146-
bool is_yb_relation = false;
147-
if (!target_relation)
148-
is_yb_relation = IsYBRelationById(getrelid(rc->rti, range_table));
149-
else
150-
is_yb_relation = IsYBBackedRelation(target_relation);
151-
152-
if (is_yb_relation)
146+
if (IsYBRelationById(getrelid(rc->rti, range_table)))
153147
{
154148
/* Need to fetch YB TID */
155149
var = makeVar(rc->rti,

src/postgres/src/test/regress/expected/yb_feature_temp.out

+10
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,13 @@ INSERT INTO temptest VALUES (101, 201, 301), (101, 201, 301);
367367
ERROR: duplicate key value violates unique constraint "temptest_pkey"
368368
DETAIL: Key (k)=(101) already exists.
369369
DROP TABLE temptest;
370+
-- test temp table being used to update YB table.
371+
CREATE TABLE test1 (x int, y int, z int);
372+
INSERT INTO test1 VALUES (1, 2, 3);
373+
CREATE TEMP TABLE test2 as table test1;
374+
UPDATE test1 SET z = 2 FROM test2 WHERE test1.x = test2.x;
375+
SELECT * FROM test1;
376+
x | y | z
377+
---+---+---
378+
1 | 2 | 2
379+
(1 row)

src/postgres/src/test/regress/sql/yb_feature_temp.sql

+7
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,10 @@ INSERT INTO temptest VALUES (100, 200, 300);
303303
INSERT INTO temptest VALUES (101, 201, 301), (101, 201, 301);
304304

305305
DROP TABLE temptest;
306+
307+
-- test temp table being used to update YB table.
308+
CREATE TABLE test1 (x int, y int, z int);
309+
INSERT INTO test1 VALUES (1, 2, 3);
310+
CREATE TEMP TABLE test2 as table test1;
311+
UPDATE test1 SET z = 2 FROM test2 WHERE test1.x = test2.x;
312+
SELECT * FROM test1;

0 commit comments

Comments
 (0)