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

Function CheckRelationTableSpaceMove

src/backend/commands/tablecmds.c:3931–3971  ·  view source on GitHub ↗

* CheckRelationTableSpaceMove * Check if relation can be moved to new tablespace. * * NOTE: The caller must hold AccessExclusiveLock on the relation. * * Returns true if the relation can be moved to the new tablespace; raises * an error if it is not possible to do the move; returns false if the move * would have no effect. */

Source from the content-addressed store, hash-verified

3929 * would have no effect.
3930 */
3931bool
3932CheckRelationTableSpaceMove(Relation rel, Oid newTableSpaceId)
3933{
3934 Oid oldTableSpaceId;
3935
3936 /*
3937 * No work if no change in tablespace. Note that MyDatabaseTableSpace is
3938 * stored as 0.
3939 */
3940 oldTableSpaceId = rel->rd_rel->reltablespace;
3941 if (newTableSpaceId == oldTableSpaceId ||
3942 (newTableSpaceId == MyDatabaseTableSpace && oldTableSpaceId == 0))
3943 return false;
3944
3945 /*
3946 * We cannot support moving mapped relations into different tablespaces.
3947 * (In particular this eliminates all shared catalogs.)
3948 */
3949 if (RelationIsMapped(rel))
3950 ereport(ERROR,
3951 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3952 errmsg("cannot move system relation \"%s\"",
3953 RelationGetRelationName(rel))));
3954
3955 /* Cannot move a non-shared relation into pg_global */
3956 if (newTableSpaceId == GLOBALTABLESPACE_OID)
3957 ereport(ERROR,
3958 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3959 errmsg("only shared relations can be placed in pg_global tablespace")));
3960
3961 /*
3962 * Do not allow moving temp tables of other backends ... their local
3963 * buffer manager is not going to cope.
3964 */
3965 if (RELATION_IS_OTHER_TEMP(rel))
3966 ereport(ERROR,
3967 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3968 errmsg("cannot move temporary tables of other sessions")));
3969
3970 return true;
3971}
3972
3973/*
3974 * SetRelationTableSpace

Callers 4

SetRelationTableSpaceFunction · 0.85
ATExecSetTableSpaceFunction · 0.85
reindex_indexFunction · 0.85

Calls 2

errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected