mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Move materialized views' is-populated status into their pg_class entries.
Previously this state was represented by whether the view's disk file had zero or nonzero size, which is problematic for numerous reasons, since it's breaking a fundamental assumption about heap storage. This was done to allow unlogged matviews to revert to unpopulated status after a crash despite our lack of any ability to update catalog entries post-crash. However, this poses enough risk of future problems that it seems better to not support unlogged matviews until we can find another way. Accordingly, revert that choice as well as a number of existing kluges forced by it in favor of creating a pg_class.relispopulated flag column.
This commit is contained in:
@ -834,30 +834,3 @@ pg_relation_filepath(PG_FUNCTION_ARGS)
|
||||
|
||||
PG_RETURN_TEXT_P(cstring_to_text(path));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Indicate whether a relation is scannable.
|
||||
*
|
||||
* Currently, this is always true except for a materialized view which has not
|
||||
* been populated. It is expected that other conditions for allowing a
|
||||
* materialized view to be scanned will be added in later releases.
|
||||
*/
|
||||
Datum
|
||||
pg_relation_is_scannable(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid relid;
|
||||
Relation relation;
|
||||
bool result;
|
||||
|
||||
relid = PG_GETARG_OID(0);
|
||||
relation = try_relation_open(relid, AccessShareLock);
|
||||
|
||||
if (relation == NULL)
|
||||
PG_RETURN_BOOL(false);
|
||||
|
||||
result = RelationIsScannable(relation);
|
||||
|
||||
relation_close(relation, AccessShareLock);
|
||||
PG_RETURN_BOOL(result);
|
||||
}
|
||||
|
34
src/backend/utils/cache/relcache.c
vendored
34
src/backend/utils/cache/relcache.c
vendored
@ -37,7 +37,6 @@
|
||||
#include "access/transam.h"
|
||||
#include "access/xact.h"
|
||||
#include "catalog/catalog.h"
|
||||
#include "catalog/heap.h"
|
||||
#include "catalog/index.h"
|
||||
#include "catalog/indexing.h"
|
||||
#include "catalog/namespace.h"
|
||||
@ -956,12 +955,6 @@ RelationBuildDesc(Oid targetRelId, bool insertIt)
|
||||
/* make sure relation is marked as having no open file yet */
|
||||
relation->rd_smgr = NULL;
|
||||
|
||||
if (relation->rd_rel->relkind == RELKIND_MATVIEW &&
|
||||
heap_is_matview_init_state(relation))
|
||||
relation->rd_ispopulated = false;
|
||||
else
|
||||
relation->rd_ispopulated = true;
|
||||
|
||||
/*
|
||||
* now we can free the memory allocated for pg_class_tuple
|
||||
*/
|
||||
@ -1459,6 +1452,9 @@ formrdesc(const char *relationName, Oid relationReltype,
|
||||
/* formrdesc is used only for permanent relations */
|
||||
relation->rd_rel->relpersistence = RELPERSISTENCE_PERMANENT;
|
||||
|
||||
/* ... and they're always populated, too */
|
||||
relation->rd_rel->relispopulated = true;
|
||||
|
||||
relation->rd_rel->relpages = 0;
|
||||
relation->rd_rel->reltuples = 0;
|
||||
relation->rd_rel->relallvisible = 0;
|
||||
@ -1531,7 +1527,6 @@ formrdesc(const char *relationName, Oid relationReltype,
|
||||
* initialize physical addressing information for the relation
|
||||
*/
|
||||
RelationInitPhysicalAddr(relation);
|
||||
relation->rd_ispopulated = true;
|
||||
|
||||
/*
|
||||
* initialize the rel-has-index flag, using hardwired knowledge
|
||||
@ -1756,7 +1751,6 @@ RelationReloadIndexInfo(Relation relation)
|
||||
heap_freetuple(pg_class_tuple);
|
||||
/* We must recalculate physical address in case it changed */
|
||||
RelationInitPhysicalAddr(relation);
|
||||
relation->rd_ispopulated = true;
|
||||
|
||||
/*
|
||||
* For a non-system index, there are fields of the pg_index row that are
|
||||
@ -1905,11 +1899,6 @@ RelationClearRelation(Relation relation, bool rebuild)
|
||||
if (relation->rd_isnailed)
|
||||
{
|
||||
RelationInitPhysicalAddr(relation);
|
||||
if (relation->rd_rel->relkind == RELKIND_MATVIEW &&
|
||||
heap_is_matview_init_state(relation))
|
||||
relation->rd_ispopulated = false;
|
||||
else
|
||||
relation->rd_ispopulated = true;
|
||||
|
||||
if (relation->rd_rel->relkind == RELKIND_INDEX)
|
||||
{
|
||||
@ -2671,6 +2660,12 @@ RelationBuildLocalRelation(const char *relname,
|
||||
break;
|
||||
}
|
||||
|
||||
/* if it's a materialized view, it's not populated initially */
|
||||
if (relkind == RELKIND_MATVIEW)
|
||||
rel->rd_rel->relispopulated = false;
|
||||
else
|
||||
rel->rd_rel->relispopulated = true;
|
||||
|
||||
/*
|
||||
* Insert relation physical and logical identifiers (OIDs) into the right
|
||||
* places. For a mapped relation, we set relfilenode to zero and rely on
|
||||
@ -2698,12 +2693,6 @@ RelationBuildLocalRelation(const char *relname,
|
||||
|
||||
RelationInitPhysicalAddr(rel);
|
||||
|
||||
/* materialized view not initially scannable */
|
||||
if (relkind == RELKIND_MATVIEW)
|
||||
rel->rd_ispopulated = false;
|
||||
else
|
||||
rel->rd_ispopulated = true;
|
||||
|
||||
/*
|
||||
* Okay to insert into the relcache hash tables.
|
||||
*/
|
||||
@ -4448,11 +4437,6 @@ load_relcache_init_file(bool shared)
|
||||
*/
|
||||
RelationInitLockInfo(rel);
|
||||
RelationInitPhysicalAddr(rel);
|
||||
if (rel->rd_rel->relkind == RELKIND_MATVIEW &&
|
||||
heap_is_matview_init_state(rel))
|
||||
rel->rd_ispopulated = false;
|
||||
else
|
||||
rel->rd_ispopulated = true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user