MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecRefreshMatView

Function ExecRefreshMatView

src/backend/commands/matview.c:390–759  ·  view source on GitHub ↗

* ExecRefreshMatView -- execute a REFRESH MATERIALIZED VIEW command * * This refreshes the materialized view by creating a new table and swapping * the relfilenodes of the new table and the old materialized view, so the OID * of the original materialized view is preserved. Thus we do not lose GRANT * nor references to this materialized view. * * If WITH NO DATA was specified, this is effect

Source from the content-addressed store, hash-verified

388 * reflect the result set of the materialized view's query.
389 */
390ObjectAddress
391ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
392 ParamListInfo params, QueryCompletion *qc)
393{
394 Oid matviewOid;
395 Relation matviewRel;
396 Query *dataQuery;
397 Query *viewQuery;
398 Oid tableSpace;
399 Oid relowner;
400 Oid OIDNewHeap;
401 DestReceiver *dest;
402 uint64 processed = 0;
403 bool concurrent;
404 LOCKMODE lockmode;
405 char relpersistence;
406 Oid save_userid;
407 int save_sec_context;
408 int save_nestlevel;
409 ObjectAddress address;
410 RefreshClause *refreshClause;
411 bool oldPopulated;
412 bool ao_has_index;
413
414 /* MATERIALIZED_VIEW_FIXME: Refresh MatView is not MPP-fied. */
415
416 /* Determine strength of lock needed. */
417 concurrent = stmt->concurrent;
418 lockmode = concurrent ? ExclusiveLock : AccessExclusiveLock;
419
420 /*
421 * Get a lock until end of transaction.
422 */
423 matviewOid = RangeVarGetRelidExtended(stmt->relation,
424 lockmode, 0,
425 RangeVarCallbackOwnsTable, NULL);
426 matviewRel = table_open(matviewOid, NoLock);
427 relowner = matviewRel->rd_rel->relowner;
428
429 /*
430 * Switch to the owner's userid, so that any functions are run as that
431 * user. Also lock down security-restricted operations and arrange to
432 * make GUC variable changes local to this command.
433 */
434 GetUserIdAndSecContext(&save_userid, &save_sec_context);
435 SetUserIdAndSecContext(relowner,
436 save_sec_context | SECURITY_RESTRICTED_OPERATION);
437 save_nestlevel = NewGUCNestLevel();
438 oldPopulated = RelationIsPopulated(matviewRel);
439
440 /* Make sure it is a materialized view. */
441 if (matviewRel->rd_rel->relkind != RELKIND_MATVIEW)
442 ereport(ERROR,
443 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
444 errmsg("\"%s\" is not a materialized view",
445 RelationGetRelationName(matviewRel))));
446
447 /* Check that CONCURRENTLY is not specified if not populated. */

Callers 1

ProcessUtilitySlowFunction · 0.85

Calls 15

RangeVarGetRelidExtendedFunction · 0.85
table_openFunction · 0.85
GetUserIdAndSecContextFunction · 0.85
SetUserIdAndSecContextFunction · 0.85
NewGUCNestLevelFunction · 0.85
get_matview_queryFunction · 0.85
rewriteQueryForIMMVFunction · 0.85
RelationGetIndexListFunction · 0.85
index_openFunction · 0.85
is_usable_unique_indexFunction · 0.85
index_closeFunction · 0.85

Tested by

no test coverage detected