Skip to content

Commit

Permalink
Fix REFRESH fast path.
Browse files Browse the repository at this point in the history
If a table is vacuum or clutered, we should not avoid
REFRESH for mvs have it.
Else, if it's a partition or partitioned now and later,
we could not use it for Append Agg.

Authored-by: Zhang Mingli [email protected]
  • Loading branch information
avamingli committed Nov 21, 2024
1 parent f92faf0 commit 5f03ab1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/backend/catalog/gp_matview_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,16 @@ MatviewIsGeneralyUpToDate(Oid mvoid)
return ((auxform->datastatus == MV_DATA_STATUS_UP_TO_DATE) ||
(auxform->datastatus == MV_DATA_STATUS_UP_REORGANIZED));
}

bool
MatviewIsUpToDate(Oid mvoid)
{
HeapTuple mvauxtup = SearchSysCacheCopy1(MVAUXOID, ObjectIdGetDatum(mvoid));

/* Not a candidate we recorded. */
if (!HeapTupleIsValid(mvauxtup))
return false;

Form_gp_matview_aux auxform = (Form_gp_matview_aux) GETSTRUCT(mvauxtup);
return (auxform->datastatus == MV_DATA_STATUS_UP_TO_DATE);
}
2 changes: 1 addition & 1 deletion src/backend/commands/matview.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
if (gp_enable_refresh_fast_path &&
!RelationIsIVM(matviewRel) &&
!stmt->skipData &&
MatviewIsGeneralyUpToDate(matviewOid))
MatviewIsUpToDate(matviewOid))
{
table_close(matviewRel, NoLock);

Expand Down
2 changes: 2 additions & 0 deletions src/include/catalog/gp_matview_aux.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ extern bool MatviewUsableForAppendAgg(Oid mvoid);

extern bool MatviewIsGeneralyUpToDate(Oid mvoid);

extern bool MatviewIsUpToDate(Oid mvoid);

#endif /* GP_MATVIEW_AUX_H */

0 comments on commit 5f03ab1

Please sign in to comment.