Sait Talha Nisanci 2020-12-30 14:00:08 +03:00
parent 6c9872d182
commit c8237b6c73
3 changed files with 25 additions and 0 deletions

View File

@ -149,6 +149,13 @@ CreateCimv(CimvCreate *cimvCreate)
elog(ERROR, "SPI_connect failed");
}
Oid savedUserId = InvalidOid;
int savedSecurityContext = 0;
/* make sure we have write access */
GetUserIdAndSecContext(&savedUserId, &savedSecurityContext);
SetUserIdAndSecContext(CitusExtensionOwner(), SECURITY_LOCAL_USERID_CHANGE);
CreateMatTable(cimvCreate, false);
if (cimvCreate->createOptions->schedule != NULL)
@ -172,6 +179,8 @@ CreateCimv(CimvCreate *cimvCreate)
{
RefreshCimv(cimvCreate->formCimv, cimvCreate->stmt->into->skipData, true);
}
SetUserIdAndSecContext(savedUserId, savedSecurityContext);
}

View File

@ -50,6 +50,13 @@ RefreshCimv(Form_pg_cimv formCimv, bool skipData, bool isCreate)
elog(ERROR, "SPI_connect failed");
}
Oid savedUserId = InvalidOid;
int savedSecurityContext = 0;
/* make sure we have write access */
GetUserIdAndSecContext(&savedUserId, &savedSecurityContext);
SetUserIdAndSecContext(CitusExtensionOwner(), SECURITY_LOCAL_USERID_CHANGE);
const char *matTableSchemaName = get_namespace_name(get_rel_namespace(
formCimv->mattable));
const char *matTableName = get_rel_name(formCimv->mattable);
@ -149,6 +156,8 @@ RefreshCimv(Form_pg_cimv formCimv, bool skipData, bool isCreate)
}
}
SetUserIdAndSecContext(savedUserId, savedSecurityContext);
/* Close SPI context. */
if (SPI_finish() != SPI_OK_FINISH)
{

View File

@ -460,10 +460,17 @@ multi_ProcessUtility(PlannedStmt *pstmt,
bool continueProcessing = true;
if (IsA(parsetree, CreateTableAsStmt))
{
Oid savedUserId = InvalidOid;
int savedSecurityContext = 0;
/* make sure we have write access */
GetUserIdAndSecContext(&savedUserId, &savedSecurityContext);
SetUserIdAndSecContext(CitusExtensionOwner(), SECURITY_LOCAL_USERID_CHANGE);
continueProcessing = !ProcessCreateMaterializedViewStmt((const
CreateTableAsStmt *)
parsetree, queryString,
pstmt);
SetUserIdAndSecContext(savedUserId, savedSecurityContext);
}
if (IsA(parsetree, RefreshMatViewStmt))