Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3973034

Browse files
committed
Don't reject ROW_MARK_REFERENCE rowmarks for materialized views.
We should allow this so that matviews can be referenced in UPDATE/DELETEstatements in READ COMMITTED isolation level. The requirement for thatis that a re-fetch by TID will see the same row version the query sawearlier, which is true of matviews, so there's no reason for therestriction. Per bug #9398.Michael Paquier, after a suggestion by me
1 parent13ea43a commit3973034

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

‎src/backend/executor/execMain.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,14 +1100,15 @@ CheckValidRowMarkRel(Relation rel, RowMarkType markType)
11001100
RelationGetRelationName(rel))));
11011101
break;
11021102
caseRELKIND_MATVIEW:
1103-
/* Should not get here */
1104-
ereport(ERROR,
1105-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1106-
errmsg("cannot lock rows in materialized view \"%s\"",
1107-
RelationGetRelationName(rel))));
1103+
/* Allow referencing a matview, but not actual locking clauses */
1104+
if (markType!=ROW_MARK_REFERENCE)
1105+
ereport(ERROR,
1106+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1107+
errmsg("cannot lock rows in materialized view \"%s\"",
1108+
RelationGetRelationName(rel))));
11081109
break;
11091110
caseRELKIND_FOREIGN_TABLE:
1110-
/* Should not get here */
1111+
/* Should not get here; planner should have used ROW_MARK_COPY */
11111112
ereport(ERROR,
11121113
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
11131114
errmsg("cannot lock rows in foreign table \"%s\"",

‎src/test/regress/expected/matview.out

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,29 @@ SELECT * FROM mv_v;
412412

413413
DROP TABLE v CASCADE;
414414
NOTICE: drop cascades to materialized view mv_v
415+
-- make sure that matview rows can be referenced as source rows (bug #9398)
416+
CREATE TABLE v AS SELECT generate_series(1,10) AS a;
417+
CREATE MATERIALIZED VIEW mv_v AS SELECT a FROM v WHERE a <= 5;
418+
DELETE FROM v WHERE EXISTS ( SELECT * FROM mv_v WHERE mv_v.a = v.a );
419+
SELECT * FROM v;
420+
a
421+
----
422+
6
423+
7
424+
8
425+
9
426+
10
427+
(5 rows)
428+
429+
SELECT * FROM mv_v;
430+
a
431+
---
432+
1
433+
2
434+
3
435+
4
436+
5
437+
(5 rows)
438+
439+
DROP TABLE v CASCADE;
440+
NOTICE: drop cascades to materialized view mv_v

‎src/test/regress/sql/matview.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,11 @@ REFRESH MATERIALIZED VIEW mv_v;
141141
SELECT*FROM v;
142142
SELECT*FROM mv_v;
143143
DROPTABLE v CASCADE;
144+
145+
-- make sure that matview rows can be referenced as source rows (bug #9398)
146+
CREATETABLEvASSELECT generate_series(1,10)AS a;
147+
CREATE MATERIALIZED VIEW mv_vASSELECT aFROM vWHERE a<=5;
148+
DELETEFROM vWHERE EXISTS (SELECT*FROM mv_vWHEREmv_v.a=v.a );
149+
SELECT*FROM v;
150+
SELECT*FROM mv_v;
151+
DROPTABLE v CASCADE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp