blob: dc7aaa8aea592cd7df669b434969f0742e25c79e [file] [log] [blame]
-- disable ORCA
SET optimizer TO off;
create schema matview_data_schema;
set search_path to matview_data_schema;
create table t1(a int, b int);
create table t2(a int, b int);
insert into t1 select i, i+1 from generate_series(1, 5) i;
insert into t1 select i, i+1 from generate_series(1, 3) i;
create materialized view mv0 as select * from t1;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Apache Cloudberry 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 mv1 as select a, count(*), sum(b) from t1 group by a;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Apache Cloudberry 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 mv2 as select * from t2;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Apache Cloudberry 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.
-- all mv are up to date
select mvname, datastatus from gp_matview_aux where mvname in ('mv0','mv1', 'mv2');
mvname | datastatus
--------+------------
mv0 | u
mv1 | u
mv2 | u
(3 rows)
-- truncate in self transaction
begin;
create table t3(a int, b int);
create materialized view mv3 as select * from t3;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Apache Cloudberry 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.
select datastatus from gp_matview_aux where mvname = 'mv3';
datastatus
------------
u
(1 row)
truncate t3;
select datastatus from gp_matview_aux where mvname = 'mv3';
datastatus
------------
e
(1 row)
end;
-- trcuncate
refresh materialized view mv3;
select datastatus from gp_matview_aux where mvname = 'mv3';
datastatus
------------
u
(1 row)
truncate t3;
select datastatus from gp_matview_aux where mvname = 'mv3';
datastatus
------------
e
(1 row)
-- insert and refresh
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
u
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
u
(1 row)
insert into t1 values (1, 2);
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
i
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
i
(1 row)
-- insert but no rows changes
refresh materialized view mv0;
refresh materialized view mv1;
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
u
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
u
(1 row)
insert into t1 select * from t3;
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
u
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
u
(1 row)
-- update
refresh materialized view mv0;
refresh materialized view mv1;
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
u
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
u
(1 row)
update t1 set a = 10 where a = 1;
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
e
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
e
(1 row)
-- delete
refresh materialized view mv0;
refresh materialized view mv1;
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
u
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
u
(1 row)
delete from t1 where a = 10;
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
e
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
e
(1 row)
-- vacuum
refresh materialized view mv0;
refresh materialized view mv1;
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
u
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
u
(1 row)
vacuum t1;
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
u
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
u
(1 row)
vacuum full t1;
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
r
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
r
(1 row)
-- insert after vacuum full
insert into t1 values(1, 2);
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
e
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
e
(1 row)
-- vacuum full after insert
refresh materialized view mv0;
refresh materialized view mv1;
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
u
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
u
(1 row)
insert into t1 values(1, 2);
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
i
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
i
(1 row)
vacuum full t1;
select datastatus from gp_matview_aux where mvname = 'mv0';
datastatus
------------
e
(1 row)
select datastatus from gp_matview_aux where mvname = 'mv1';
datastatus
------------
e
(1 row)
-- Refresh With No Data
refresh materialized view mv2;
select datastatus from gp_matview_aux where mvname = 'mv2';
datastatus
------------
u
(1 row)
refresh materialized view mv2 with no data;
select datastatus from gp_matview_aux where mvname = 'mv2';
datastatus
------------
e
(1 row)
-- Copy
refresh materialized view mv2;
select datastatus from gp_matview_aux where mvname = 'mv2';
datastatus
------------
u
(1 row)
-- 0 rows
COPY t2 from stdin;
select datastatus from gp_matview_aux where mvname = 'mv2';
datastatus
------------
u
(1 row)
COPY t2 from stdin;
select datastatus from gp_matview_aux where mvname = 'mv2';
datastatus
------------
i
(1 row)
--
-- test issue https://github.com/apache/cloudberry/issues/582
-- test inherits
--
begin;
create table tp_issue_582(i int, j int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Apache Cloudberry 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 tc_issue_582(i int) inherits (tp_issue_582);
NOTICE: table has parent, setting distribution columns to match parent table
NOTICE: merging column "i" with inherited definition
insert into tp_issue_582 values(1, 1), (2, 2);
insert into tc_issue_582 values(1, 1);
create materialized view mv_tp_issue_582 as select * from tp_issue_582;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'i' as the Apache Cloudberry 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.
-- should be null.
select mvname, datastatus from gp_matview_aux where mvname = 'mv_tp_issue_582';
mvname | datastatus
--------+------------
(0 rows)
abort;
-- test drop table
select mvname, datastatus from gp_matview_aux where mvname in ('mv0','mv1', 'mv2', 'mv3');
mvname | datastatus
--------+------------
mv3 | e
mv0 | e
mv1 | e
mv2 | i
(4 rows)
drop materialized view mv2;
drop table t1 cascade;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to materialized view mv0
drop cascades to materialized view mv1
select mvname, datastatus from gp_matview_aux where mvname in ('mv0','mv1', 'mv2', 'mv3');
mvname | datastatus
--------+------------
mv3 | e
(1 row)
--
-- test issue https://github.com/apache/cloudberry/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 Apache Cloudberry 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 Apache Cloudberry 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 Apache Cloudberry 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 Apache Cloudberry 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;
--
-- test issue https://github.com/apache/cloudberry/issues/582
-- test writable CTE
--
begin;
create table t_cte_issue_582(i int, j int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Apache Cloudberry 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_t_cte_issue_582 as select j from t_cte_issue_582 where i = 1;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'j' as the Apache Cloudberry 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.
select mvname, datastatus from gp_matview_aux where mvname = 'mv_t_cte_issue_582';
mvname | datastatus
--------------------+------------
mv_t_cte_issue_582 | u
(1 row)
with mod1 as (insert into t_cte_issue_582 values(1, 1) returning *) select * from mod1;
i | j
---+---
1 | 1
(1 row)
select mvname, datastatus from gp_matview_aux where mvname = 'mv_t_cte_issue_582';
mvname | datastatus
--------------------+------------
mv_t_cte_issue_582 | e
(1 row)
abort;
-- test partitioned tables
create table par(a int, b int, c int) partition by range(b)
subpartition by range(c) subpartition template (start (1) end (3) every (1))
(start(1) end(3) every(1));
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry 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.
insert into par values(1, 1, 1), (1, 1, 2), (2, 2, 1), (2, 2, 2);
create materialized view mv_par as select * from par;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Apache Cloudberry 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_par1 as select * from par_1_prt_1;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Apache Cloudberry 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_par1_1 as select * from par_1_prt_1_2_prt_1;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Apache Cloudberry 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_par1_2 as select * from par_1_prt_1_2_prt_2;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Apache Cloudberry 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_par2 as select * from par_1_prt_2;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Apache Cloudberry 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_par2_1 as select * from par_1_prt_2_2_prt_1;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Apache Cloudberry 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.
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par | u
mv_par1 | u
mv_par1_1 | u
mv_par1_2 | u
mv_par2 | u
mv_par2_1 | u
(6 rows)
insert into par_1_prt_1 values (1, 1, 1);
-- mv_par1* shoud be updated
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par1_2 | u
mv_par2 | u
mv_par2_1 | u
mv_par1_1 | i
mv_par1 | i
mv_par | i
(6 rows)
insert into par values (1, 2, 2);
-- mv_par* should be updated
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par1_2 | u
mv_par2_1 | u
mv_par1_1 | i
mv_par1 | i
mv_par | i
mv_par2 | u
(6 rows)
refresh materialized view mv_par;
refresh materialized view mv_par1;
refresh materialized view mv_par1_1;
refresh materialized view mv_par1_2;
refresh materialized view mv_par2;
refresh materialized view mv_par2_1;
begin;
insert into par_1_prt_2_2_prt_1 values (1, 2, 1);
-- mv_par1* should not be updated
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par1 | u
mv_par1_1 | u
mv_par1_2 | u
mv_par2_1 | i
mv_par2 | i
mv_par | i
(6 rows)
abort;
begin;
truncate par_1_prt_2;
-- mv_par1* should not be updated
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par1 | u
mv_par1_1 | u
mv_par1_2 | u
mv_par2_1 | e
mv_par2 | e
mv_par | e
(6 rows)
abort;
truncate par_1_prt_2;
-- mv_par1* should not be updated
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par1 | u
mv_par1_1 | u
mv_par1_2 | u
mv_par2_1 | e
mv_par2 | e
mv_par | e
(6 rows)
refresh materialized view mv_par;
refresh materialized view mv_par1;
refresh materialized view mv_par1_1;
refresh materialized view mv_par1_2;
refresh materialized view mv_par2;
refresh materialized view mv_par2_1;
vacuum full par_1_prt_1_2_prt_1;
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par1_2 | u
mv_par2 | u
mv_par2_1 | u
mv_par1_1 | r
mv_par1 | r
mv_par | r
(6 rows)
refresh materialized view mv_par;
refresh materialized view mv_par1;
refresh materialized view mv_par1_1;
refresh materialized view mv_par1_2;
refresh materialized view mv_par2;
refresh materialized view mv_par2_1;
vacuum full par;
-- all should be updated.
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par2 | r
mv_par | r
mv_par2_1 | r
mv_par1_2 | r
mv_par1 | r
mv_par1_1 | r
(6 rows)
refresh materialized view mv_par;
refresh materialized view mv_par1;
refresh materialized view mv_par1_1;
refresh materialized view mv_par1_2;
refresh materialized view mv_par2;
refresh materialized view mv_par2_1;
begin;
create table par_1_prt_1_2_prt_3 partition of par_1_prt_1 for values from (3) to (4);
NOTICE: table has parent, setting distribution columns to match parent table
-- update status when partition of
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par1_1 | u
mv_par1_2 | u
mv_par2 | u
mv_par2_1 | u
mv_par1 | e
mv_par | e
(6 rows)
abort;
begin;
drop table par_1_prt_1 cascade;
NOTICE: drop cascades to 3 other objects
DETAIL: drop cascades to materialized view mv_par1_1
drop cascades to materialized view mv_par1_2
drop cascades to materialized view mv_par1
-- update status when drop table
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par2 | u
mv_par2_1 | u
mv_par | e
(3 rows)
abort;
begin;
alter table par_1_prt_1 detach partition par_1_prt_1_2_prt_1;
-- update status when detach
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par1_1 | u
mv_par1_2 | u
mv_par2 | u
mv_par2_1 | u
mv_par1 | e
mv_par | e
(6 rows)
abort;
begin;
create table new_par(a int, b int, c int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry 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.
-- update status when attach
alter table par_1_prt_1 attach partition new_par for values from (4) to (5);
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par1_1 | u
mv_par1_2 | u
mv_par2 | u
mv_par2_1 | u
mv_par1 | e
mv_par | e
(6 rows)
abort;
--
-- Maintain materialized views on partitioned tables from bottom to up.
--
insert into par values(1, 1, 1), (1, 1, 2), (2, 2, 1), (2, 2, 2);
refresh materialized view mv_par;
refresh materialized view mv_par1;
refresh materialized view mv_par1_1;
refresh materialized view mv_par1_2;
refresh materialized view mv_par2;
refresh materialized view mv_par2_1;
begin;
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par | u
mv_par1 | u
mv_par1_1 | u
mv_par1_2 | u
mv_par2 | u
mv_par2_1 | u
(6 rows)
insert into par values(1, 1, 1), (1, 1, 2);
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par2 | u
mv_par2_1 | u
mv_par1_1 | i
mv_par1 | i
mv_par | i
mv_par1_2 | i
(6 rows)
abort;
begin;
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par | u
mv_par1 | u
mv_par1_1 | u
mv_par1_2 | u
mv_par2 | u
mv_par2_1 | u
(6 rows)
insert into par_1_prt_2_2_prt_1 values(2, 2, 1);
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par1 | u
mv_par1_1 | u
mv_par1_2 | u
mv_par2_1 | i
mv_par2 | i
mv_par | i
(6 rows)
abort;
begin;
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par | u
mv_par1 | u
mv_par1_1 | u
mv_par1_2 | u
mv_par2 | u
mv_par2_1 | u
(6 rows)
delete from par where b = 2 and c = 1;
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par1 | u
mv_par1_1 | u
mv_par1_2 | u
mv_par2_1 | e
mv_par2 | e
mv_par | e
(6 rows)
abort;
begin;
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par | u
mv_par1 | u
mv_par1_1 | u
mv_par1_2 | u
mv_par2 | u
mv_par2_1 | u
(6 rows)
delete from par_1_prt_1_2_prt_2;
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par1_1 | u
mv_par2 | u
mv_par2_1 | u
mv_par1_2 | e
mv_par1 | e
mv_par | e
(6 rows)
abort;
-- Across partition update.
begin;
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par | u
mv_par1 | u
mv_par1_1 | u
mv_par1_2 | u
mv_par2 | u
mv_par2_1 | u
(6 rows)
update par set c = 2 where b = 1 and c = 1;
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par2 | u
mv_par2_1 | u
mv_par1_2 | i
mv_par1_1 | e
mv_par1 | e
mv_par | e
(6 rows)
abort;
-- Split Update with acrosss partition update.
begin;
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par | u
mv_par1 | u
mv_par1_1 | u
mv_par1_2 | u
mv_par2 | u
mv_par2_1 | u
(6 rows)
update par set c = 2, a = 2 where b = 1 and c = 1;
select mvname, datastatus from gp_matview_aux where mvname like 'mv_par%';
mvname | datastatus
-----------+------------
mv_par2 | u
mv_par2_1 | u
mv_par1_2 | i
mv_par1_1 | e
mv_par1 | e
mv_par | e
(6 rows)
abort;
-- Test report warning if extend protocol data is not consumed.
--start_ignore
drop extension gp_inject_fault;
create extension gp_inject_fault;
--end_ignore
select gp_inject_fault_infinite('consume_extend_protocol_data', 'skip', dbid)
from gp_segment_configuration where role = 'p' and content = -1;
gp_inject_fault_infinite
--------------------------
Success:
(1 row)
begin;
update par set c = 2 where b = 1 and c = 1;
WARNING: fail to find leafs of partitioned table: par
end;
WARNING: Extend Protocol Data unconsumed, subtag: 2
WARNING: Extend Protocol Data unconsumed, subtag: 0
begin;
insert into par values(1, 1, 1), (1, 1, 2);
WARNING: fail to find leafs of partitioned table: par
end;
WARNING: Extend Protocol Data unconsumed, subtag: 0
begin;
update par set c = 2, a = 2 where b = 1 and c = 1;
WARNING: fail to find leafs of partitioned table: par
end;
WARNING: Extend Protocol Data unconsumed, subtag: 2
WARNING: Extend Protocol Data unconsumed, subtag: 0
begin;
insert into par values(1, 1, 1), (1, 1, 2), (2, 2, 1), (2, 2, 2);
WARNING: fail to find leafs of partitioned table: par
delete from par_1_prt_1_2_prt_2;
end;
WARNING: Extend Protocol Data unconsumed, subtag: 2
WARNING: Extend Protocol Data unconsumed, subtag: 0
begin;
insert into par values(1, 1, 1), (1, 1, 2), (2, 2, 1), (2, 2, 2);
WARNING: fail to find leafs of partitioned table: par
update par set c = 2, a = 2 where b = 1 and c = 1;
WARNING: fail to find leafs of partitioned table: par
end;
WARNING: Extend Protocol Data unconsumed, subtag: 2
WARNING: Extend Protocol Data unconsumed, subtag: 0
select gp_inject_fault('consume_extend_protocol_data', 'reset', dbid)
from gp_segment_configuration where role = 'p' and content = -1;
gp_inject_fault
-----------------
Success:
(1 row)
--
-- End of Maintain materialized views on partitioned tables from bottom to up.
--
-- Test Rename matview.
begin;
create materialized view mv_name1 as
select * from par with no data;
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' as the Apache Cloudberry 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.
select count(*) from gp_matview_aux where mvname = 'mv_name1';
count
-------
1
(1 row)
alter materialized view mv_name1 rename to mv_name2;
select count(*) from gp_matview_aux where mvname = 'mv_name1';
count
-------
0
(1 row)
select count(*) from gp_matview_aux where mvname = 'mv_name2';
count
-------
1
(1 row)
abort;
--start_ignore
drop schema matview_data_schema cascade;
NOTICE: drop cascades to 3 other objects
DETAIL: drop cascades to table t2
drop cascades to table t3
drop cascades to materialized view mv3
--end_ignore
reset enable_answer_query_using_materialized_views;
reset optimizer;