mirror of
https://github.com/postgres/postgres.git
synced 2025-06-20 15:22:23 +03:00
Generalize concept of temporary relations to "relation persistence".
This commit replaces pg_class.relistemp with pg_class.relpersistence; and also modifies the RangeVar node type to carry relpersistence rather than istemp. It also removes removes rd_istemp from RelationData and instead performs the correct computation based on relpersistence. For clarity, we add three new macros: RelationNeedsWAL(), RelationUsesLocalBuffers(), and RelationUsesTempNamespace(), so that we can clarify the purpose of each check that previous depended on rd_istemp. This is intended as infrastructure for the upcoming unlogged tables patch, as well as for future possible work on global temporary tables.
This commit is contained in:
@ -68,10 +68,10 @@ isViewOnTempTable_walker(Node *node, void *context)
|
||||
if (rte->rtekind == RTE_RELATION)
|
||||
{
|
||||
Relation rel = heap_open(rte->relid, AccessShareLock);
|
||||
bool istemp = rel->rd_istemp;
|
||||
char relpersistence = rel->rd_rel->relpersistence;
|
||||
|
||||
heap_close(rel, AccessShareLock);
|
||||
if (istemp)
|
||||
if (relpersistence == RELPERSISTENCE_TEMP)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -173,9 +173,9 @@ DefineVirtualRelation(const RangeVar *relation, List *tlist, bool replace)
|
||||
/*
|
||||
* Due to the namespace visibility rules for temporary objects, we
|
||||
* should only end up replacing a temporary view with another
|
||||
* temporary view, and vice versa.
|
||||
* temporary view, and similarly for permanent views.
|
||||
*/
|
||||
Assert(relation->istemp == rel->rd_istemp);
|
||||
Assert(relation->relpersistence == rel->rd_rel->relpersistence);
|
||||
|
||||
/*
|
||||
* Create a tuple descriptor to compare against the existing view, and
|
||||
@ -454,10 +454,11 @@ DefineView(ViewStmt *stmt, const char *queryString)
|
||||
* schema name.
|
||||
*/
|
||||
view = stmt->view;
|
||||
if (!view->istemp && isViewOnTempTable(viewParse))
|
||||
if (view->relpersistence == RELPERSISTENCE_PERMANENT
|
||||
&& isViewOnTempTable(viewParse))
|
||||
{
|
||||
view = copyObject(view); /* don't corrupt original command */
|
||||
view->istemp = true;
|
||||
view->relpersistence = RELPERSISTENCE_TEMP;
|
||||
ereport(NOTICE,
|
||||
(errmsg("view \"%s\" will be a temporary view",
|
||||
view->relname)));
|
||||
|
Reference in New Issue
Block a user