sraoss / pgsql-ivm

IVM (Incremental View Maintenance) development for PostgreSQL
Other
129 stars 12 forks source link

The view that does not match causes IVM failed #150

Closed yugo-n closed 1 year ago

yugo-n commented 2 years ago

Reported by huyajun in https://www.postgresql.org/message-id/tencent_FCAF11BCA5003FD16BDDFDDA5D6A19587809%40qq.com

Sometimes no error when the columns of the created materialized view do not match. But the hidden column of IMV is overwritten to z which will cause refresh failed. The problem should be that checkRuleResultList we should only skip imv hidden columns check

Create table t( a int);
create incremental materialized view s(y,z)  as select  count(1) as b from t;
=# insert into t values (1);
ERROR:  column mv.__ivm_count__ does not exist
LINE 1: ...pdt AS (UPDATE public.s AS mv SET __ivm_count__ = mv.__ivm_c...
                                                             ^
QUERY:  WITH updt AS (UPDATE public.s AS mv SET __ivm_count__ = mv.__ivm_count__ OPERATOR(pg_catalog.+) diff.__ivm_count__ , y = (mv.y OPERATOR(pg_catalog.+) diff.y) FROM new_delta AS diff WHERE true RETURNING NULL) INSERT INTO public.s (y, z)SELECT y, z FROM new_delta AS diff WHERE NOT EXISTS (SELECT 1 FROM updt AS mv WHERE true);