Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/backend/executor/execMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,8 +1044,9 @@ standard_ExecutorRun(QueryDesc *queryDesc,
* NB: This can't handle well in utility mode, should REFRESH by user
* after that.
*/
if ((GP_ROLE_DISPATCH == Gp_role && es_processed > 0) ||
(IS_SINGLENODE() && (operation != CMD_SELECT) && estate->es_processed > 0))
if (IS_QD_OR_SINGLENODE() &&
((es_processed > 0 || estate->es_processed > 0) ||
!queryDesc->plannedstmt->canSetTag))
{
if (operation == CMD_INSERT ||
operation == CMD_UPDATE ||
Expand Down
55 changes: 55 additions & 0 deletions src/test/regress/expected/matview_data.out
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,61 @@ select mvname, datastatus from gp_matview_aux where mvname in ('mv0','mv1', 'mv2
mv3 | e
(1 row)

--
-- test issue https://github.com/cloudberrydb/cloudberrydb/issues/582
-- test rules
begin;
create table t1_issue_582(i int, j int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Cloudberry Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
create table t2_issue_582(i int, j int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Cloudberry Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
create table t3_issue_582(i int, j int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Cloudberry Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
create materialized view mv_t2_issue_582 as select j from t2_issue_582 where i = 1;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'j' as the Cloudberry Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
create rule r1 as on insert TO t1_issue_582 do also insert into t2_issue_582 values(1,1);
select count(*) from t1_issue_582;
count
-------
0
(1 row)

select count(*) from t2_issue_582;
count
-------
0
(1 row)

select mvname, datastatus from gp_matview_aux where mvname = 'mv_t2_issue_582';
mvname | datastatus
-----------------+------------
mv_t2_issue_582 | u
(1 row)

insert into t1_issue_582 values(1,1);
select count(*) from t1_issue_582;
count
-------
1
(1 row)

select count(*) from t2_issue_582;
count
-------
1
(1 row)

select mvname, datastatus from gp_matview_aux where mvname = 'mv_t2_issue_582';
mvname | datastatus
-----------------+------------
mv_t2_issue_582 | i
(1 row)

abort;
drop schema matview_data_schema cascade;
NOTICE: drop cascades to 3 other objects
DETAIL: drop cascades to table t2
Expand Down
18 changes: 18 additions & 0 deletions src/test/regress/sql/matview_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ drop materialized view mv2;
drop table t1 cascade;
select mvname, datastatus from gp_matview_aux where mvname in ('mv0','mv1', 'mv2', 'mv3');

--
-- test issue https://github.com/cloudberrydb/cloudberrydb/issues/582
-- test rules
begin;
create table t1_issue_582(i int, j int);
create table t2_issue_582(i int, j int);
create table t3_issue_582(i int, j int);
create materialized view mv_t2_issue_582 as select j from t2_issue_582 where i = 1;
create rule r1 as on insert TO t1_issue_582 do also insert into t2_issue_582 values(1,1);
select count(*) from t1_issue_582;
select count(*) from t2_issue_582;
select mvname, datastatus from gp_matview_aux where mvname = 'mv_t2_issue_582';
insert into t1_issue_582 values(1,1);
select count(*) from t1_issue_582;
select count(*) from t2_issue_582;
select mvname, datastatus from gp_matview_aux where mvname = 'mv_t2_issue_582';
abort;

drop schema matview_data_schema cascade;
reset enable_answer_query_using_materialized_views;
reset optimizer;