@@ -336,35 +336,12 @@ heap_create(const char *relname,
336
336
* relfrozenxid = InvalidTransactionId ;
337
337
* relminmxid = InvalidMultiXactId ;
338
338
339
- /* Handle reltablespace for specific relkinds. */
340
- switch (relkind )
341
- {
342
- case RELKIND_VIEW :
343
- case RELKIND_COMPOSITE_TYPE :
344
- case RELKIND_FOREIGN_TABLE :
345
-
346
- /*
347
- * Force reltablespace to zero if the relation has no physical
348
- * storage. This is mainly just for cleanliness' sake.
349
- *
350
- * Partitioned tables and indexes don't have physical storage
351
- * either, but we want to keep their tablespace settings so that
352
- * their children can inherit it.
353
- */
354
- reltablespace = InvalidOid ;
355
- break ;
356
-
357
- case RELKIND_SEQUENCE :
358
-
359
- /*
360
- * Force reltablespace to zero for sequences, since we don't
361
- * support moving them around into different tablespaces.
362
- */
363
- reltablespace = InvalidOid ;
364
- break ;
365
- default :
366
- break ;
367
- }
339
+ /*
340
+ * Force reltablespace to zero if the relation kind does not support
341
+ * tablespaces. This is mainly just for cleanliness' sake.
342
+ */
343
+ if (!RELKIND_HAS_TABLESPACE (relkind ))
344
+ reltablespace = InvalidOid ;
368
345
369
346
/*
370
347
* Decide whether to create storage. If caller passed a valid relfilenode,
@@ -409,35 +386,20 @@ heap_create(const char *relname,
409
386
/*
410
387
* Have the storage manager create the relation's disk file, if needed.
411
388
*
412
- * Forrelations the callback creates both the main and the init fork, for
413
- *indexes only the main fork is created. The other forks will be created
414
- * on demand.
389
+ * Fortables, theAM callback creates both the main and the init fork.
390
+ *For others, only the main fork is created; the other forks will be
391
+ *created on demand.
415
392
*/
416
393
if (create_storage )
417
394
{
418
- switch (rel -> rd_rel -> relkind )
419
- {
420
- case RELKIND_VIEW :
421
- case RELKIND_COMPOSITE_TYPE :
422
- case RELKIND_FOREIGN_TABLE :
423
- case RELKIND_PARTITIONED_TABLE :
424
- case RELKIND_PARTITIONED_INDEX :
425
- Assert (false);
426
- break ;
427
-
428
- case RELKIND_INDEX :
429
- case RELKIND_SEQUENCE :
430
- RelationCreateStorage (rel -> rd_node ,relpersistence );
431
- break ;
432
-
433
- case RELKIND_RELATION :
434
- case RELKIND_TOASTVALUE :
435
- case RELKIND_MATVIEW :
436
- table_relation_set_new_filenode (rel ,& rel -> rd_node ,
437
- relpersistence ,
438
- relfrozenxid ,relminmxid );
439
- break ;
440
- }
395
+ if (RELKIND_HAS_TABLE_AM (rel -> rd_rel -> relkind ))
396
+ table_relation_set_new_filenode (rel ,& rel -> rd_node ,
397
+ relpersistence ,
398
+ relfrozenxid ,relminmxid );
399
+ else if (RELKIND_HAS_STORAGE (rel -> rd_rel -> relkind ))
400
+ RelationCreateStorage (rel -> rd_node ,relpersistence );
401
+ else
402
+ Assert (false);
441
403
}
442
404
443
405
/*
@@ -1015,29 +977,16 @@ AddNewRelationTuple(Relation pg_class_desc,
1015
977
*/
1016
978
new_rel_reltup = new_rel_desc -> rd_rel ;
1017
979
1018
- switch (relkind )
980
+ /* The relation is empty */
981
+ new_rel_reltup -> relpages = 0 ;
982
+ new_rel_reltup -> reltuples = -1 ;
983
+ new_rel_reltup -> relallvisible = 0 ;
984
+
985
+ /* Sequences always have a known size */
986
+ if (relkind == RELKIND_SEQUENCE )
1019
987
{
1020
- case RELKIND_RELATION :
1021
- case RELKIND_MATVIEW :
1022
- case RELKIND_INDEX :
1023
- case RELKIND_TOASTVALUE :
1024
- /* The relation is real, but as yet empty */
1025
- new_rel_reltup -> relpages = 0 ;
1026
- new_rel_reltup -> reltuples = -1 ;
1027
- new_rel_reltup -> relallvisible = 0 ;
1028
- break ;
1029
- case RELKIND_SEQUENCE :
1030
- /* Sequences always have a known size */
1031
- new_rel_reltup -> relpages = 1 ;
1032
- new_rel_reltup -> reltuples = 1 ;
1033
- new_rel_reltup -> relallvisible = 0 ;
1034
- break ;
1035
- default :
1036
- /* Views, etc, have no disk storage */
1037
- new_rel_reltup -> relpages = 0 ;
1038
- new_rel_reltup -> reltuples = -1 ;
1039
- new_rel_reltup -> relallvisible = 0 ;
1040
- break ;
988
+ new_rel_reltup -> relpages = 1 ;
989
+ new_rel_reltup -> reltuples = 1 ;
1041
990
}
1042
991
1043
992
new_rel_reltup -> relfrozenxid = relfrozenxid ;
@@ -1235,29 +1184,37 @@ heap_create_with_catalog(const char *relname,
1235
1184
if (!OidIsValid (relid ))
1236
1185
{
1237
1186
/* Use binary-upgrade override for pg_class.oid/relfilenode? */
1238
- if (IsBinaryUpgrade &&
1239
- (relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE ||
1240
- relkind == RELKIND_VIEW || relkind == RELKIND_MATVIEW ||
1241
- relkind == RELKIND_COMPOSITE_TYPE || relkind == RELKIND_FOREIGN_TABLE ||
1242
- relkind == RELKIND_PARTITIONED_TABLE ))
1187
+ if (IsBinaryUpgrade )
1243
1188
{
1244
- if (!OidIsValid (binary_upgrade_next_heap_pg_class_oid ))
1245
- ereport (ERROR ,
1246
- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
1247
- errmsg ("pg_class heap OID value not set when in binary upgrade mode" )));
1189
+ /*
1190
+ * Indexes are not supported here; they use
1191
+ * binary_upgrade_next_index_pg_class_oid.
1192
+ */
1193
+ Assert (relkind != RELKIND_INDEX );
1194
+ Assert (relkind != RELKIND_PARTITIONED_INDEX );
1248
1195
1249
- relid = binary_upgrade_next_heap_pg_class_oid ;
1250
- binary_upgrade_next_heap_pg_class_oid = InvalidOid ;
1251
- }
1252
- /* There might be no TOAST table, so we have to test for it. */
1253
- else if (IsBinaryUpgrade &&
1254
- OidIsValid (binary_upgrade_next_toast_pg_class_oid )&&
1255
- relkind == RELKIND_TOASTVALUE )
1256
- {
1257
- relid = binary_upgrade_next_toast_pg_class_oid ;
1258
- binary_upgrade_next_toast_pg_class_oid = InvalidOid ;
1196
+ if (relkind == RELKIND_TOASTVALUE )
1197
+ {
1198
+ /* There might be no TOAST table, so we have to test for it. */
1199
+ if (OidIsValid (binary_upgrade_next_toast_pg_class_oid ))
1200
+ {
1201
+ relid = binary_upgrade_next_toast_pg_class_oid ;
1202
+ binary_upgrade_next_toast_pg_class_oid = InvalidOid ;
1203
+ }
1204
+ }
1205
+ else
1206
+ {
1207
+ if (!OidIsValid (binary_upgrade_next_heap_pg_class_oid ))
1208
+ ereport (ERROR ,
1209
+ (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
1210
+ errmsg ("pg_class heap OID value not set when in binary upgrade mode" )));
1211
+
1212
+ relid = binary_upgrade_next_heap_pg_class_oid ;
1213
+ binary_upgrade_next_heap_pg_class_oid = InvalidOid ;
1214
+ }
1259
1215
}
1260
- else
1216
+
1217
+ if (!OidIsValid (relid ))
1261
1218
relid = GetNewRelFileNode (reltablespace ,pg_class_desc ,
1262
1219
relpersistence );
1263
1220
}
@@ -1468,13 +1425,12 @@ heap_create_with_catalog(const char *relname,
1468
1425
1469
1426
/*
1470
1427
* Make a dependency link to force the relation to be deleted if its
1471
- * access method is. Do this only for relation and materialized views.
1428
+ * access method is.
1472
1429
*
1473
1430
* No need to add an explicit dependency for the toast table, as the
1474
1431
* main table depends on it.
1475
1432
*/
1476
- if (relkind == RELKIND_RELATION ||
1477
- relkind == RELKIND_MATVIEW )
1433
+ if (RELKIND_HAS_TABLE_AM (relkind )&& relkind != RELKIND_TOASTVALUE )
1478
1434
{
1479
1435
ObjectAddressSet (referenced ,AccessMethodRelationId ,accessmtd );
1480
1436
add_exact_object_address (& referenced ,addrs );