update refreshmatviews

This commit is contained in:
sqyyeah
2020-08-29 18:33:15 +08:00
parent a257e3b9a0
commit 459be3ac29

View File

@ -166,10 +166,9 @@ void ExecRefreshMatView(const RefreshMatViewStmt* stmt, const char* queryString,
tableSpace = matviewRel->rd_rel->reltablespace;
heap_close(matviewRel, NoLock);
/* Create the transient table that will receive the regenerated data. */
OIDNewHeap = make_new_heap(matviewOid, tableSpace, ExclusiveLock);
LockRelationOid(OIDNewHeap, AccessExclusiveLock);
dest = CreateTransientRelDestReceiver(OIDNewHeap);
/*
* Now lock down security-restricted operations.
@ -183,9 +182,12 @@ void ExecRefreshMatView(const RefreshMatViewStmt* stmt, const char* queryString,
t_thrd.storage_cxt.EnlargeDeadlockTimeout = true;
LockRelationOid(matviewOid, AccessExclusiveLock);
refresh_by_heap_swap(matviewOid, OIDNewHeap);
if (!stmt->skipData)
pgstat_count_heap_insert(matviewRel, processed);
heap_close(matviewRel, NoLock);
/* Roll back any GUC changes */
AtEOXact_GUC(false, save_nestlevel);