Skip to content

Commit 3d48d86

Browse files
avaminglimy-ship-it
authored andcommitted
Maintain materialized view data status.
A materialized view's data could be seen as up to date with base tables if there are no writable operations since last Refresh of the view. If one of base tables in the query tree of a materailied view is modified, the view data is not up to date. And we could not use it to answer query. This commit maintain the data satus of a materialized view and it applies to normal materialized view, IVM with defer refresh. IVM with immediately refresh is always up to date. When a base table has writable operation, we try to update view data status as: - 'u'(up to date): Create Materialized View Refresh - 'e'(expired): Update base tables Delete base tables Refresh With No Data Truncate base tables Create Materialized View With No Data - 'i'(insert only): Insert info base tables Copy From Copy From on Segments - 'r'(up to date but reorganized): Cluster base tables Vacuum Full base tables Insert, Update, Delete, Copy From operations take effect if the actual affected rows > 0, ex: insert into t1 select * from t2; We don't need to update view if t2 has zero rows. The real status will be decided both by current and the status we try to mark as.Ex: we try to mark insert only on a expired status, it will not success. This doesn't work on utility mode, if user modified data in that mode, should refresh views if want to use it to answer query. AQUMV could use normal materialized views after this commit. Authored-by: Zhang Mingli avamingli@gmail.com
1 parent be38ff5 commit 3d48d86

34 files changed

+1700
-12
lines changed

gpMgmt/bin/gpcheckcat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,10 @@ def checkTableMissingEntry(cat):
12831283
if catname == "gp_segment_configuration":
12841284
return
12851285

1286+
# Skip gp_matview_aux or gp_matview_tables
1287+
if catname == "gp_matview_aux" or catname == "gp_matview_tables":
1288+
return
1289+
12861290
# skip shared/non-shared tables
12871291
if GV.opt['-S']:
12881292
if re.match("none", GV.opt['-S'], re.I) and isShared:
@@ -1533,6 +1537,10 @@ def checkTableInconsistentEntry(cat):
15331537
if catname == "gp_segment_configuration" or catname == "pg_appendonly":
15341538
return
15351539

1540+
# Skip gp_matview_aux or gp_matview_tables
1541+
if catname == "gp_matview_aux" or catname == "gp_matview_tables":
1542+
return
1543+
15361544
# skip shared/non-shared tables
15371545
if GV.opt['-S']:
15381546
if re.match("none", GV.opt['-S'], re.I) and isShared:

gpMgmt/bin/gppylib/gpcatalog.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class GPCatalogException(Exception):
3333
'pg_statistic_ext',
3434
'pg_statistic_ext_data',
3535
'gp_partition_template', # GPDB_12_MERGE_FIXME: is gp_partition_template intentionally missing from segments?
36-
'pg_event_trigger'
36+
'pg_event_trigger',
37+
'gp_matview_aux',
38+
'gp_matview_tables',
3739
]
3840

3941
# Hard coded tables that have different values on every segment

src/backend/catalog/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ OBJS += pg_extprotocol.o \
5353
oid_dispatch.o aocatalog.o storage_tablespace.o storage_database.o \
5454
storage_tablespace_twophase.o storage_tablespace_xact.o \
5555
gp_partition_template.o pg_task.o pg_task_run_history.o \
56+
gp_matview_aux.o \
5657
pg_directory_table.o storage_directory_table.o
5758

5859
CATALOG_JSON:= $(addprefix $(top_srcdir)/gpMgmt/bin/gppylib/data/, $(addsuffix .json,$(GP_MAJORVERSION)))
@@ -94,6 +95,8 @@ CATALOG_HEADERS := \
9495
pg_sequence.h pg_publication.h pg_publication_rel.h pg_subscription.h \
9596
pg_subscription_rel.h gp_partition_template.h pg_task.h pg_task_run_history.h \
9697
pg_profile.h pg_password_history.h pg_directory_table.h gp_storage_server.h \
98+
gp_matview_aux.h \
99+
gp_matview_tables.h \
97100
gp_storage_user_mapping.h
98101

99102
USE_INTERNAL_FTS_FOUND := $(if $(findstring USE_INTERNAL_FTS,$(CFLAGS)),true,false)

src/backend/catalog/catalog.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
#include "catalog/pg_stat_last_shoperation.h"
7777
#include "catalog/pg_statistic.h"
7878
#include "catalog/pg_trigger.h"
79+
#include "catalog/gp_matview_aux.h"
80+
#include "catalog/gp_matview_tables.h"
7981
#include "cdb/cdbvars.h"
8082

8183
#include "catalog/gp_indexing.h"
@@ -551,6 +553,16 @@ IsSharedRelation(Oid relationId)
551553
return true;
552554
}
553555

556+
/* materialized view aux and its indexes */
557+
if (relationId == GpMatviewAuxId ||
558+
relationId == GpMatviewAuxMvoidIndexId ||
559+
relationId == GpMatviewAuxMvnameIndexId ||
560+
relationId == GpMatviewAuxDatastatusIndexId ||
561+
relationId == GpMatviewTablesId ||
562+
relationId == GpMatviewTablesMvRelIndexId ||
563+
relationId == GpMatviewTablesRelIndexId)
564+
return true;
565+
554566
/* warehouse table and its indexes */
555567
if (relationId == GpWarehouseRelationId ||
556568
relationId == GpWarehouseOidIndexId ||

src/backend/catalog/dependency.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
#include "catalog/pg_profile.h"
101101
#include "catalog/pg_password_history.h"
102102
#include "commands/tablecmds.h"
103+
#include "catalog/gp_matview_aux.h"
103104

104105

105106
/*
@@ -209,7 +210,8 @@ static const Oid object_classes[] = {
209210
StorageServerRelationId, /* OCLASS_STORAGE_SERVER */
210211
StorageUserMappingRelationId, /* OCLASS_STORAGE_USER_MAPPING */
211212
ExtprotocolRelationId, /* OCLASS_EXTPROTOCOL */
212-
TaskRelationId /* OCLASS_TASK */
213+
GpMatviewAuxId, /* OCLASS_MATVIEW_AUX */
214+
TaskRelationId, /* OCLASS_TASK */
213215
};
214216

215217

@@ -1554,6 +1556,10 @@ doDeletion(const ObjectAddress *object, int flags)
15541556
RemoveTaskById(object->objectId);
15551557
break;
15561558

1559+
case OCLASS_MATVIEW_AUX:
1560+
RemoveMatviewAuxEntry(object->objectId);
1561+
break;
1562+
15571563
case OCLASS_CAST:
15581564
case OCLASS_COLLATION:
15591565
case OCLASS_CONVERSION:
@@ -2978,6 +2984,9 @@ getObjectClass(const ObjectAddress *object)
29782984
case TaskRelationId:
29792985
return OCLASS_TASK;
29802986

2987+
case GpMatviewAuxId:
2988+
return OCLASS_MATVIEW_AUX;
2989+
29812990
case DirectoryTableRelationId:
29822991
return OCLASS_DIRTABLE;
29832992

0 commit comments

Comments
 (0)