Skip to content

Commit 63fcf2d

Browse files
avaminglimy-ship-it
authored andcommitted
Forbid inherits tables to store into gp_matview_aux.
Inherits tables are not supported for AQUMV. There may be wrong results if we store it in gp_matview_aux. And cause mislead for the view status. Forbid inherits tables when store into gp_matview_aux. Authored-by: Zhang Mingli avamingli@gmail.com
1 parent bd3fb36 commit 63fcf2d

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

src/backend/catalog/gp_matview_aux.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "catalog/dependency.h"
2121
#include "catalog/gp_matview_aux.h"
2222
#include "catalog/gp_matview_tables.h"
23+
#include "catalog/pg_inherits.h"
2324
#include "catalog/pg_type.h"
2425
#include "catalog/indexing.h"
2526
#include "cdb/cdbvars.h"
@@ -91,6 +92,17 @@ GetViewBaseRelids(const Query *viewQuery)
9192
if (get_rel_relkind(rte->relid) != RELKIND_RELATION)
9293
return NIL;
9394

95+
/*
96+
* inherit tables are not supported.
97+
* FIXME: left a door for partition table which will be supported soon.
98+
*/
99+
bool can_be_partition = (get_rel_relkind(rte->relid) == RELKIND_PARTITIONED_TABLE) ||
100+
get_rel_relispartition(rte->relid);
101+
102+
if (!can_be_partition &&
103+
(has_superclass(rte->relid) || has_subclass(rte->relid)))
104+
return NIL;
105+
94106
relids = list_make1_oid(rte->relid);
95107

96108
return relids;

src/test/regress/expected/matview_data.out

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,29 @@ select datastatus from gp_matview_aux where mvname = 'mv2';
303303
i
304304
(1 row)
305305

306+
--
307+
-- test issue https://github.com/cloudberrydb/cloudberrydb/issues/582
308+
-- test inherits
309+
--
310+
begin;
311+
create table tp_issue_582(i int, j int);
312+
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Cloudberry Database data distribution key for this table.
313+
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
314+
create table tc_issue_582(i int) inherits (tp_issue_582);
315+
NOTICE: table has parent, setting distribution columns to match parent table
316+
NOTICE: merging column "i" with inherited definition
317+
insert into tp_issue_582 values(1, 1), (2, 2);
318+
insert into tc_issue_582 values(1, 1);
319+
create materialized view mv_tp_issue_582 as select * from tp_issue_582;
320+
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'i' as the Cloudberry Database data distribution key for this table.
321+
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
322+
-- should be null.
323+
select mvname, datastatus from gp_matview_aux where mvname = 'mv_tp_issue_582';
324+
mvname | datastatus
325+
--------+------------
326+
(0 rows)
327+
328+
abort;
306329
-- test drop table
307330
select mvname, datastatus from gp_matview_aux where mvname in ('mv0','mv1', 'mv2', 'mv3');
308331
mvname | datastatus

src/test/regress/sql/matview_data.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ COPY t2 from stdin;
108108
\.
109109
select datastatus from gp_matview_aux where mvname = 'mv2';
110110

111+
--
112+
-- test issue https://github.com/cloudberrydb/cloudberrydb/issues/582
113+
-- test inherits
114+
--
115+
begin;
116+
create table tp_issue_582(i int, j int);
117+
create table tc_issue_582(i int) inherits (tp_issue_582);
118+
insert into tp_issue_582 values(1, 1), (2, 2);
119+
insert into tc_issue_582 values(1, 1);
120+
create materialized view mv_tp_issue_582 as select * from tp_issue_582;
121+
-- should be null.
122+
select mvname, datastatus from gp_matview_aux where mvname = 'mv_tp_issue_582';
123+
abort;
124+
111125
-- test drop table
112126
select mvname, datastatus from gp_matview_aux where mvname in ('mv0','mv1', 'mv2', 'mv3');
113127
drop materialized view mv2;

0 commit comments

Comments
 (0)