On 2/19/18, Joe Conway <m...@joeconway.com> wrote:
> The attached does exactly this. Gives all system tables toast tables
> except pg_class, pg_attribute, and pg_index, and includes cat version
> bump and regression test in misc_sanity.
>
> Any further discussion, comments, complaints?

Hi Joe,
There's been a little bit-rot with duplicate OIDs and the regression
test. The first attached patch fixes that (applies on top of yours).

It occurred to be that we could go further and create most toast
tables automatically by taking advantage of the fact that the toast
creation function is a no-op if there are no varlena attributes. The
second patch (applies on top of the first) demonstrates a setup where
only shared and bootstrap catalogs need to have toast declarations
specified manually with fixed OIDs. It's possible this way is more
fragile, though.

I also did some non-scientific performance testing. On my machine,
initdb takes at least:
HEAD ~1040 ms
patch ~1070 ms
with my addenda ~1075 ms

A little slower, but within the noise of variation.

-John Naylor

> Joe
>
> --
> Crunchy Data - http://crunchydata.com
> PostgreSQL Support for Secure Enterprises
> Consulting, Training, & Open Source Development
>
diff --git a/src/include/catalog/toasting.h b/src/include/catalog/toasting.h
index ee54487..1387569 100644
--- a/src/include/catalog/toasting.h
+++ b/src/include/catalog/toasting.h
@@ -46,9 +46,9 @@ extern void BootstrapToastTable(char *relName,
  */
 
 /* normal catalogs */
-DECLARE_TOAST(pg_aggregate, 4139, 4140);
+DECLARE_TOAST(pg_aggregate, 4187, 4188);
 DECLARE_TOAST(pg_attrdef, 2830, 2831);
-DECLARE_TOAST(pg_collation, 4141, 4142);
+DECLARE_TOAST(pg_collation, 4189, 4190);
 DECLARE_TOAST(pg_constraint, 2832, 2833);
 DECLARE_TOAST(pg_default_acl, 4143, 4144);
 DECLARE_TOAST(pg_description, 2834, 2835);
diff --git a/src/test/regress/expected/misc_sanity.out b/src/test/regress/expected/misc_sanity.out
index 0be74d2..ad10a7e 100644
--- a/src/test/regress/expected/misc_sanity.out
+++ b/src/test/regress/expected/misc_sanity.out
@@ -92,11 +92,12 @@ ORDER BY 1,2;
 --------------+---------------+--------------
  pg_attribute | attacl        | aclitem[]
  pg_attribute | attfdwoptions | text[]
+ pg_attribute | attmissingval | anyarray
  pg_attribute | attoptions    | text[]
  pg_class     | relacl        | aclitem[]
  pg_class     | reloptions    | text[]
  pg_class     | relpartbound  | pg_node_tree
  pg_index     | indexprs      | pg_node_tree
  pg_index     | indpred       | pg_node_tree
-(8 rows)
+(9 rows)
 
diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y
index 4c72989..9f5a3b9 100644
--- a/src/backend/bootstrap/bootparse.y
+++ b/src/backend/bootstrap/bootparse.y
@@ -27,10 +27,13 @@
 #include "catalog/heap.h"
 #include "catalog/namespace.h"
 #include "catalog/pg_am.h"
+#include "catalog/pg_amproc.h"
 #include "catalog/pg_attribute.h"
 #include "catalog/pg_authid.h"
 #include "catalog/pg_class.h"
+#include "catalog/pg_index.h"
 #include "catalog/pg_namespace.h"
+#include "catalog/pg_opclass.h"
 #include "catalog/pg_tablespace.h"
 #include "catalog/toasting.h"
 #include "commands/defrem.h"
@@ -255,6 +258,23 @@ Boot_CreateStmt:
 													  InvalidOid,
 													  NULL);
 						elog(DEBUG4, "relation created with OID %u", id);
+
+						/*
+						 * Create a toast table for all non-shared catalogs
+						 * that have any varlena attributes, except for pg_index.
+						 * We also exclude catalogs that need to be populated
+						 * in order for toast tables to be created. These don't
+						 * currently have varlenas, so this is just future-proofing.
+						 */
+						if (!shared_relation
+							&& id != IndexRelationId
+							&& id != AccessMethodRelationId
+							&& id != OperatorClassRelationId
+							&& id != AccessMethodProcedureRelationId)
+						{
+							NewRelationCreateToastTable(id, (Datum) 0);
+						}
+						elog(DEBUG4, "creating toast table for table \"%s\"", $2);
 					}
 					do_end();
 				}
diff --git a/src/backend/catalog/Makefile b/src/backend/catalog/Makefile
index 0865240..48a871a 100644
--- a/src/backend/catalog/Makefile
+++ b/src/backend/catalog/Makefile
@@ -27,12 +27,13 @@ include $(top_srcdir)/src/backend/common.mk
 
 # Note: the order of this list determines the order in which the catalog
 # header files are assembled into postgres.bki.  BKI_BOOTSTRAP catalogs
-# must appear first, and there are reputedly other, undocumented ordering
-# dependencies.
+# must appear first, followed by catalogs needed for creating toast tables.
+# There are reputedly other, undocumented ordering dependencies.
 CATALOG_HEADERS := \
 	pg_proc.h pg_type.h pg_attribute.h pg_class.h \
-	pg_attrdef.h pg_constraint.h pg_inherits.h pg_index.h pg_operator.h \
-	pg_opfamily.h pg_opclass.h pg_am.h pg_amop.h pg_amproc.h \
+	pg_index.h pg_am.h pg_opclass.h pg_amproc.h \
+	pg_operator.h pg_opfamily.h pg_amop.h \
+	pg_attrdef.h pg_constraint.h pg_inherits.h \
 	pg_language.h pg_largeobject_metadata.h pg_largeobject.h pg_aggregate.h \
 	pg_statistic_ext.h \
 	pg_statistic.h pg_rewrite.h pg_trigger.h pg_event_trigger.h pg_description.h \
diff --git a/src/include/catalog/toasting.h b/src/include/catalog/toasting.h
index 1387569..df2595e 100644
--- a/src/include/catalog/toasting.h
+++ b/src/include/catalog/toasting.h
@@ -42,37 +42,14 @@ extern void BootstrapToastTable(char *relName,
  * the OID to assign to the toast table, and the OID to assign to the
  * toast table's index.  The reason we hard-wire these OIDs is that we
  * need stable OIDs for shared relations, and that includes toast tables
- * of shared relations.
+ * of shared relations.  Most non-shared catalogs get a toast table
+ * at the time they're created, but that won't work for bootstrap catalogs,
+ * so just hard-wire the toast declarations for them here.
  */
 
-/* normal catalogs */
-DECLARE_TOAST(pg_aggregate, 4187, 4188);
-DECLARE_TOAST(pg_attrdef, 2830, 2831);
-DECLARE_TOAST(pg_collation, 4189, 4190);
-DECLARE_TOAST(pg_constraint, 2832, 2833);
-DECLARE_TOAST(pg_default_acl, 4143, 4144);
-DECLARE_TOAST(pg_description, 2834, 2835);
-DECLARE_TOAST(pg_event_trigger, 4145, 4146);
-DECLARE_TOAST(pg_extension, 4147, 4148);
-DECLARE_TOAST(pg_foreign_data_wrapper, 4149, 4150);
-DECLARE_TOAST(pg_foreign_server, 4151, 4152);
-DECLARE_TOAST(pg_foreign_table, 4153, 4154);
-DECLARE_TOAST(pg_init_privs, 4155, 4156);
-DECLARE_TOAST(pg_language, 4157, 4158);
-DECLARE_TOAST(pg_largeobject, 4159, 4160);
-DECLARE_TOAST(pg_largeobject_metadata, 4161, 4162);
-DECLARE_TOAST(pg_namespace, 4163, 4164);
-DECLARE_TOAST(pg_partitioned_table, 4165, 4166);
-DECLARE_TOAST(pg_policy, 4167, 4168);
+/* bootstrap catalogs, excluding pg_class and pg_attribute */
 DECLARE_TOAST(pg_proc, 2836, 2837);
-DECLARE_TOAST(pg_rewrite, 2838, 2839);
-DECLARE_TOAST(pg_seclabel, 3598, 3599);
-DECLARE_TOAST(pg_statistic, 2840, 2841);
-DECLARE_TOAST(pg_statistic_ext, 3439, 3440);
-DECLARE_TOAST(pg_trigger, 2336, 2337);
-DECLARE_TOAST(pg_ts_dict, 4169, 4170);
 DECLARE_TOAST(pg_type, 4171, 4172);
-DECLARE_TOAST(pg_user_mapping, 4173, 4174);
 
 /* shared catalogs */
 DECLARE_TOAST(pg_authid, 4175, 4176);

Reply via email to