* 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
| 388 | * reflect the result set of the materialized view's query. |
| 389 | */ |
| 390 | ObjectAddress |
| 391 | ExecRefreshMatView(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. */ |
no test coverage detected