From 8d2ce084e5a5dd824939bf70639acee6266b3573 Mon Sep 17 00:00:00 2001 From: lukeman Date: Thu, 15 Aug 2024 19:27:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86issue=EF=BC=9Amerge=20into?= =?UTF-8?q?=E6=BA=90=E4=B8=BA=E7=89=A9=E5=8C=96=E8=A7=86=E5=9B=BE=EF=BC=8C?= =?UTF-8?q?=E6=8A=A5=E9=94=99cannot=20lock=20rows=20in=20materialized=20vi?= =?UTF-8?q?ew?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gausskernel/runtime/executor/execMain.cpp | 12 ++++++---- .../regress/expected/merge_into_updated.out | 24 +++++++++++++++++++ src/test/regress/sql/merge_into_updated.sql | 24 +++++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/gausskernel/runtime/executor/execMain.cpp b/src/gausskernel/runtime/executor/execMain.cpp index a09bbb031..cf3c6600c 100755 --- a/src/gausskernel/runtime/executor/execMain.cpp +++ b/src/gausskernel/runtime/executor/execMain.cpp @@ -1786,11 +1786,13 @@ static void CheckValidRowMarkRel(Relation rel, RowMarkType markType) errmsg("cannot lock rows in contview \"%s\"", RelationGetRelationName(rel)))); break; case RELKIND_MATVIEW: - /* Should not get here */ - ereport(ERROR, - (errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("cannot lock rows in materialized view \"%s\"", - RelationGetRelationName(rel)))); + /* Allow referencing a matview, but not actual locking clauses */ + if (markType != ROW_MARK_REFERENCE) { + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot lock rows in materialized view \"%s\"", + RelationGetRelationName(rel)))); + } break; case RELKIND_FOREIGN_TABLE: /* Should not get here; planner should have used ROW_MARK_COPY */ diff --git a/src/test/regress/expected/merge_into_updated.out b/src/test/regress/expected/merge_into_updated.out index 993e20df3..3f996778b 100644 --- a/src/test/regress/expected/merge_into_updated.out +++ b/src/test/regress/expected/merge_into_updated.out @@ -134,6 +134,30 @@ select c1, c2, to_char(c3, 'yyyy-mm-dd') from t1 order by c1; 4 | e | 2023-09-19 (2 rows) +-- materialized view +drop table if exists t_a; +NOTICE: table "t_a" does not exist, skipping +drop table if exists t_b; +NOTICE: table "t_b" does not exist, skipping +create table t_a( +a_id int, +a_name varchar2(100) +); +create table t_b( +b_id int, +b_name varchar2(100) +); +DROP materialized VIEW if exists v_t_b; +NOTICE: materialized view "v_t_b" does not exist, skipping +create materialized view v_t_b as select * from t_b; +MERGE INTO t_a a +USING v_t_b vb +on (a.a_id=vb.b_id) +WHEN MATCHED THEN +update set a.a_name=vb.b_name; +DROP materialized VIEW v_t_b; +drop table t_a; +drop table t_b; drop schema merge_into_updated cascade; NOTICE: drop cascades to 2 other objects DETAIL: drop cascades to table t1 diff --git a/src/test/regress/sql/merge_into_updated.sql b/src/test/regress/sql/merge_into_updated.sql index 4d2b13af3..46dcf4c81 100644 --- a/src/test/regress/sql/merge_into_updated.sql +++ b/src/test/regress/sql/merge_into_updated.sql @@ -115,4 +115,28 @@ end; \parallel off select c1, c2, to_char(c3, 'yyyy-mm-dd') from t1 order by c1; +-- materialized view +drop table if exists t_a; +drop table if exists t_b; +create table t_a( +a_id int, +a_name varchar2(100) +); +create table t_b( +b_id int, +b_name varchar2(100) +); +DROP materialized VIEW if exists v_t_b; +create materialized view v_t_b as select * from t_b; + +MERGE INTO t_a a +USING v_t_b vb +on (a.a_id=vb.b_id) +WHEN MATCHED THEN +update set a.a_name=vb.b_name; + +DROP materialized VIEW v_t_b; +drop table t_a; +drop table t_b; + drop schema merge_into_updated cascade;