|
|
|
@ -336,35 +336,12 @@ heap_create(const char *relname, |
|
|
|
|
*relfrozenxid = InvalidTransactionId; |
|
|
|
|
*relminmxid = InvalidMultiXactId; |
|
|
|
|
|
|
|
|
|
/* Handle reltablespace for specific relkinds. */ |
|
|
|
|
switch (relkind) |
|
|
|
|
{ |
|
|
|
|
case RELKIND_VIEW: |
|
|
|
|
case RELKIND_COMPOSITE_TYPE: |
|
|
|
|
case RELKIND_FOREIGN_TABLE: |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Force reltablespace to zero if the relation has no physical |
|
|
|
|
* storage. This is mainly just for cleanliness' sake. |
|
|
|
|
* |
|
|
|
|
* Partitioned tables and indexes don't have physical storage |
|
|
|
|
* either, but we want to keep their tablespace settings so that |
|
|
|
|
* their children can inherit it. |
|
|
|
|
*/ |
|
|
|
|
reltablespace = InvalidOid; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case RELKIND_SEQUENCE: |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Force reltablespace to zero for sequences, since we don't |
|
|
|
|
* support moving them around into different tablespaces. |
|
|
|
|
* Force reltablespace to zero if the relation kind does not support |
|
|
|
|
* tablespaces. This is mainly just for cleanliness' sake. |
|
|
|
|
*/ |
|
|
|
|
if (!RELKIND_HAS_TABLESPACE(relkind)) |
|
|
|
|
reltablespace = InvalidOid; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Decide whether to create storage. If caller passed a valid relfilenode, |
|
|
|
@ -409,35 +386,20 @@ heap_create(const char *relname, |
|
|
|
|
/*
|
|
|
|
|
* Have the storage manager create the relation's disk file, if needed. |
|
|
|
|
* |
|
|
|
|
* For relations the callback creates both the main and the init fork, for |
|
|
|
|
* indexes only the main fork is created. The other forks will be created |
|
|
|
|
* on demand. |
|
|
|
|
* For tables, the AM callback creates both the main and the init fork. |
|
|
|
|
* For others, only the main fork is created; the other forks will be |
|
|
|
|
* created on demand. |
|
|
|
|
*/ |
|
|
|
|
if (create_storage) |
|
|
|
|
{ |
|
|
|
|
switch (rel->rd_rel->relkind) |
|
|
|
|
{ |
|
|
|
|
case RELKIND_VIEW: |
|
|
|
|
case RELKIND_COMPOSITE_TYPE: |
|
|
|
|
case RELKIND_FOREIGN_TABLE: |
|
|
|
|
case RELKIND_PARTITIONED_TABLE: |
|
|
|
|
case RELKIND_PARTITIONED_INDEX: |
|
|
|
|
Assert(false); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case RELKIND_INDEX: |
|
|
|
|
case RELKIND_SEQUENCE: |
|
|
|
|
RelationCreateStorage(rel->rd_node, relpersistence); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case RELKIND_RELATION: |
|
|
|
|
case RELKIND_TOASTVALUE: |
|
|
|
|
case RELKIND_MATVIEW: |
|
|
|
|
if (RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind)) |
|
|
|
|
table_relation_set_new_filenode(rel, &rel->rd_node, |
|
|
|
|
relpersistence, |
|
|
|
|
relfrozenxid, relminmxid); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
else if (RELKIND_HAS_STORAGE(rel->rd_rel->relkind)) |
|
|
|
|
RelationCreateStorage(rel->rd_node, relpersistence); |
|
|
|
|
else |
|
|
|
|
Assert(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -1015,29 +977,16 @@ AddNewRelationTuple(Relation pg_class_desc, |
|
|
|
|
*/ |
|
|
|
|
new_rel_reltup = new_rel_desc->rd_rel; |
|
|
|
|
|
|
|
|
|
switch (relkind) |
|
|
|
|
{ |
|
|
|
|
case RELKIND_RELATION: |
|
|
|
|
case RELKIND_MATVIEW: |
|
|
|
|
case RELKIND_INDEX: |
|
|
|
|
case RELKIND_TOASTVALUE: |
|
|
|
|
/* The relation is real, but as yet empty */ |
|
|
|
|
/* The relation is empty */ |
|
|
|
|
new_rel_reltup->relpages = 0; |
|
|
|
|
new_rel_reltup->reltuples = -1; |
|
|
|
|
new_rel_reltup->relallvisible = 0; |
|
|
|
|
break; |
|
|
|
|
case RELKIND_SEQUENCE: |
|
|
|
|
|
|
|
|
|
/* Sequences always have a known size */ |
|
|
|
|
if (relkind == RELKIND_SEQUENCE) |
|
|
|
|
{ |
|
|
|
|
new_rel_reltup->relpages = 1; |
|
|
|
|
new_rel_reltup->reltuples = 1; |
|
|
|
|
new_rel_reltup->relallvisible = 0; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
/* Views, etc, have no disk storage */ |
|
|
|
|
new_rel_reltup->relpages = 0; |
|
|
|
|
new_rel_reltup->reltuples = -1; |
|
|
|
|
new_rel_reltup->relallvisible = 0; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
new_rel_reltup->relfrozenxid = relfrozenxid; |
|
|
|
@ -1235,11 +1184,25 @@ heap_create_with_catalog(const char *relname, |
|
|
|
|
if (!OidIsValid(relid)) |
|
|
|
|
{ |
|
|
|
|
/* Use binary-upgrade override for pg_class.oid/relfilenode? */ |
|
|
|
|
if (IsBinaryUpgrade && |
|
|
|
|
(relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE || |
|
|
|
|
relkind == RELKIND_VIEW || relkind == RELKIND_MATVIEW || |
|
|
|
|
relkind == RELKIND_COMPOSITE_TYPE || relkind == RELKIND_FOREIGN_TABLE || |
|
|
|
|
relkind == RELKIND_PARTITIONED_TABLE)) |
|
|
|
|
if (IsBinaryUpgrade) |
|
|
|
|
{ |
|
|
|
|
/*
|
|
|
|
|
* Indexes are not supported here; they use |
|
|
|
|
* binary_upgrade_next_index_pg_class_oid. |
|
|
|
|
*/ |
|
|
|
|
Assert(relkind != RELKIND_INDEX); |
|
|
|
|
Assert(relkind != RELKIND_PARTITIONED_INDEX); |
|
|
|
|
|
|
|
|
|
if (relkind == RELKIND_TOASTVALUE) |
|
|
|
|
{ |
|
|
|
|
/* There might be no TOAST table, so we have to test for it. */ |
|
|
|
|
if (OidIsValid(binary_upgrade_next_toast_pg_class_oid)) |
|
|
|
|
{ |
|
|
|
|
relid = binary_upgrade_next_toast_pg_class_oid; |
|
|
|
|
binary_upgrade_next_toast_pg_class_oid = InvalidOid; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
if (!OidIsValid(binary_upgrade_next_heap_pg_class_oid)) |
|
|
|
|
ereport(ERROR, |
|
|
|
@ -1249,15 +1212,9 @@ heap_create_with_catalog(const char *relname, |
|
|
|
|
relid = binary_upgrade_next_heap_pg_class_oid; |
|
|
|
|
binary_upgrade_next_heap_pg_class_oid = InvalidOid; |
|
|
|
|
} |
|
|
|
|
/* There might be no TOAST table, so we have to test for it. */ |
|
|
|
|
else if (IsBinaryUpgrade && |
|
|
|
|
OidIsValid(binary_upgrade_next_toast_pg_class_oid) && |
|
|
|
|
relkind == RELKIND_TOASTVALUE) |
|
|
|
|
{ |
|
|
|
|
relid = binary_upgrade_next_toast_pg_class_oid; |
|
|
|
|
binary_upgrade_next_toast_pg_class_oid = InvalidOid; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
|
|
|
|
|
if (!OidIsValid(relid)) |
|
|
|
|
relid = GetNewRelFileNode(reltablespace, pg_class_desc, |
|
|
|
|
relpersistence); |
|
|
|
|
} |
|
|
|
@ -1468,13 +1425,12 @@ heap_create_with_catalog(const char *relname, |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Make a dependency link to force the relation to be deleted if its |
|
|
|
|
* access method is. Do this only for relation and materialized views. |
|
|
|
|
* access method is. |
|
|
|
|
* |
|
|
|
|
* No need to add an explicit dependency for the toast table, as the |
|
|
|
|
* main table depends on it. |
|
|
|
|
*/ |
|
|
|
|
if (relkind == RELKIND_RELATION || |
|
|
|
|
relkind == RELKIND_MATVIEW) |
|
|
|
|
if (RELKIND_HAS_TABLE_AM(relkind) && relkind != RELKIND_TOASTVALUE) |
|
|
|
|
{ |
|
|
|
|
ObjectAddressSet(referenced, AccessMethodRelationId, accessmtd); |
|
|
|
|
add_exact_object_address(&referenced, addrs); |
|
|
|
|