Remove separate files for the initial contents of pg_(sh)description
authorHeikki Linnakangas
Sun, 19 Jan 2020 11:54:58 +0000 (13:54 +0200)
committerHeikki Linnakangas
Sun, 19 Jan 2020 11:54:58 +0000 (13:54 +0200)
This data was only in separate files because it was the most convenient
way to handle it with a shell script. Now that we use a general-purpose
programming language, it's easy to assemble the data into the same format
as the rest of the catalogs and output it into postgres.bki. This allows
removal of some special-purpose code from initdb.c.

Discussion: https://www.postgresql.org/message-id/CACPNZCtVFtjHre6hg9dput0qRPp39pzuyA2A6BT8wdgrRy%2BQdA%40mail.gmail.com
Author: John Naylor

src/backend/catalog/.gitignore
src/backend/catalog/Makefile
src/backend/catalog/genbki.pl
src/bin/initdb/initdb.c
src/tools/msvc/clean.bat

index 9abe91d6e6424e1797add7f6ee364b84acea0ba3..11e2e5202326b9d55207860b30a7c3a84e042af7 100644 (file)
@@ -1,6 +1,4 @@
 /postgres.bki
-/postgres.description
-/postgres.shdescription
 /schemapg.h
 /pg_*_d.h
 /bki-stamp
index 61db650755ec349f9dc9a13a1e1441e29ebc7d8a..d5da81c80166bb78dab31c2eac76157ea1e4e46b 100644 (file)
@@ -44,8 +44,6 @@ OBJS = \
    storage.o \
    toasting.o
 
-BKIFILES = postgres.bki postgres.description postgres.shdescription
-
 include $(top_srcdir)/src/backend/common.mk
 
 # Note: the order of this list determines the order in which the catalog
@@ -127,8 +125,6 @@ $(top_builddir)/src/include/catalog/header-stamp: bki-stamp
 .PHONY: install-data
 install-data: bki-stamp installdirs
    $(INSTALL_DATA) $(call vpathsearch,postgres.bki) '$(DESTDIR)$(datadir)/postgres.bki'
-   $(INSTALL_DATA) $(call vpathsearch,postgres.description) '$(DESTDIR)$(datadir)/postgres.description'
-   $(INSTALL_DATA) $(call vpathsearch,postgres.shdescription) '$(DESTDIR)$(datadir)/postgres.shdescription'
    $(INSTALL_DATA) $(srcdir)/system_views.sql '$(DESTDIR)$(datadir)/system_views.sql'
    $(INSTALL_DATA) $(srcdir)/information_schema.sql '$(DESTDIR)$(datadir)/information_schema.sql'
    $(INSTALL_DATA) $(srcdir)/sql_features.txt '$(DESTDIR)$(datadir)/sql_features.txt'
@@ -138,12 +134,11 @@ installdirs:
 
 .PHONY: uninstall-data
 uninstall-data:
-   rm -f $(addprefix '$(DESTDIR)$(datadir)'/, $(BKIFILES) system_views.sql information_schema.sql sql_features.txt)
+   rm -f $(addprefix '$(DESTDIR)$(datadir)'/, postgres.bki system_views.sql information_schema.sql sql_features.txt)
 
-# postgres.bki, postgres.description, postgres.shdescription,
-# and the generated headers are in the distribution tarball,
+# postgres.bki and the generated headers are in the distribution tarball,
 # so they are not cleaned here.
 clean:
 
 maintainer-clean: clean
-   rm -f bki-stamp $(BKIFILES) $(GENERATED_HEADERS)
+   rm -f bki-stamp postgres.bki $(GENERATED_HEADERS)
index 887fb28578af99376e4e84a5af4b5f5f669eb96a..803251207b03a1844e1626e5d459a0f6981154d6 100644 (file)
@@ -2,10 +2,9 @@
 #----------------------------------------------------------------------
 #
 # genbki.pl
-#    Perl script that generates postgres.bki, postgres.description,
-#    postgres.shdescription, and symbol definition headers from specially
-#    formatted header files and data files.  The BKI files are used to
-#    initialize the postgres template database.
+#    Perl script that generates postgres.bki and symbol definition
+#    headers from specially formatted header files and data files.
+#    postgres.bki is used to initialize the postgres template database.
 #
 # Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
 # Portions Copyright (c) 1994, Regents of the University of California
@@ -93,9 +92,29 @@ foreach my $header (@ARGV)
        my $data = Catalog::ParseData($datfile, $schema, 0);
        $catalog_data{$catname} = $data;
 
-       # Check for duplicated OIDs while we're at it.
        foreach my $row (@$data)
        {
+           # Generate entries for pg_description and pg_shdescription.
+           if (defined $row->{descr})
+           {
+               my %descr = (
+                   objoid      => $row->{oid},
+                   classoid    => $catalog->{relation_oid},
+                   objsubid    => 0,
+                   description => $row->{descr});
+
+               if ($catalog->{shared_relation})
+               {
+                   delete $descr{objsubid};
+                   push @{ $catalog_data{pg_shdescription} }, \%descr;
+               }
+               else
+               {
+                   push @{ $catalog_data{pg_description}}, \%descr;
+               }
+           }
+
+           # Check for duplicated OIDs while we're at it.
            $oidcounts{ $row->{oid} }++ if defined $row->{oid};
        }
    }
@@ -361,15 +380,8 @@ open my $bki, '>', $bkifile . $tmpext
 my $schemafile = $output_path . 'schemapg.h';
 open my $schemapg, '>', $schemafile . $tmpext
   or die "can't open $schemafile$tmpext: $!";
-my $descrfile = $output_path . 'postgres.description';
-open my $descr, '>', $descrfile . $tmpext
-  or die "can't open $descrfile$tmpext: $!";
-my $shdescrfile = $output_path . 'postgres.shdescription';
-open my $shdescr, '>', $shdescrfile . $tmpext
-  or die "can't open $shdescrfile$tmpext: $!";
 
-# Generate postgres.bki, postgres.description, postgres.shdescription,
-# and pg_*_d.h headers.
+# Generate postgres.bki and pg_*_d.h headers.
 
 # version marker for .bki file
 print $bki "# PostgreSQL $major_version\n";
@@ -579,22 +591,6 @@ EOM
        # Write to postgres.bki
        print_bki_insert(\%bki_values, $schema);
 
-       # Write comments to postgres.description and
-       # postgres.shdescription
-       if (defined $bki_values{descr})
-       {
-           if ($catalog->{shared_relation})
-           {
-               printf $shdescr "%s\t%s\t%s\n",
-                 $bki_values{oid}, $catname, $bki_values{descr};
-           }
-           else
-           {
-               printf $descr "%s\t%s\t0\t%s\n",
-                 $bki_values{oid}, $catname, $bki_values{descr};
-           }
-       }
-
        # Emit OID symbol
        if (defined $bki_values{oid_symbol})
        {
@@ -673,14 +669,10 @@ print $schemapg "\n#endif\t\t\t\t\t\t\t/* SCHEMAPG_H */\n";
 # We're done emitting data
 close $bki;
 close $schemapg;
-close $descr;
-close $shdescr;
 
 # Finally, rename the completed files into place.
 Catalog::RenameTempFile($bkifile,     $tmpext);
 Catalog::RenameTempFile($schemafile,  $tmpext);
-Catalog::RenameTempFile($descrfile,   $tmpext);
-Catalog::RenameTempFile($shdescrfile, $tmpext);
 
 exit 0;
 
@@ -967,9 +959,9 @@ Options:
     --set-version    PostgreSQL version number for initdb cross-check
     --include-path   Include path in source tree
 
-genbki.pl generates BKI files and symbol definition
+genbki.pl generates postgres.bki and symbol definition
 headers from specially formatted header files and .dat
-files.  The BKI files are used to initialize the
+files.  postgres.bki is used to initialize the
 postgres template database.
 
 Report bugs to .
index ec6d0bdf8e9eec9d6e82d5e0c225808ac61bf982..7f1534aebb46d658af534961af424f1e86f21262 100644 (file)
@@ -151,8 +151,6 @@ static int  wal_segment_size_mb;
 static const char *progname;
 static int encodingid;
 static char *bki_file;
-static char *desc_file;
-static char *shdesc_file;
 static char *hba_file;
 static char *ident_file;
 static char *conf_file;
@@ -1644,38 +1642,11 @@ setup_sysviews(FILE *cmdfd)
 }
 
 /*
- * load description data
+ * fill in extra description data
  */
 static void
 setup_description(FILE *cmdfd)
 {
-   PG_CMD_PUTS("CREATE TEMP TABLE tmp_pg_description ( "
-               "   objoid oid, "
-               "   classname name, "
-               "   objsubid int4, "
-               "   description text);\n\n");
-
-   PG_CMD_PRINTF("COPY tmp_pg_description FROM E'%s';\n\n",
-                  escape_quotes(desc_file));
-
-   PG_CMD_PUTS("INSERT INTO pg_description "
-               " SELECT t.objoid, c.oid, t.objsubid, t.description "
-               "  FROM tmp_pg_description t, pg_class c "
-               "    WHERE c.relname = t.classname;\n\n");
-
-   PG_CMD_PUTS("CREATE TEMP TABLE tmp_pg_shdescription ( "
-               " objoid oid, "
-               " classname name, "
-               " description text);\n\n");
-
-   PG_CMD_PRINTF("COPY tmp_pg_shdescription FROM E'%s';\n\n",
-                  escape_quotes(shdesc_file));
-
-   PG_CMD_PUTS("INSERT INTO pg_shdescription "
-               " SELECT t.objoid, c.oid, t.description "
-               "  FROM tmp_pg_shdescription t, pg_class c "
-               "   WHERE c.relname = t.classname;\n\n");
-
    /* Create default descriptions for operator implementation functions */
    PG_CMD_PUTS("WITH funcdescs AS ( "
                "SELECT p.oid as p_oid, o.oid as o_oid, oprname "
@@ -1689,13 +1660,6 @@ setup_description(FILE *cmdfd)
                "  AND NOT EXISTS (SELECT 1 FROM pg_description "
                "   WHERE objoid = o_oid AND classoid = 'pg_operator'::regclass"
                "         AND description LIKE 'deprecated%');\n\n");
-
-   /*
-    * Even though the tables are temp, drop them explicitly so they don't get
-    * copied into template0/postgres databases.
-    */
-   PG_CMD_PUTS("DROP TABLE tmp_pg_description;\n\n");
-   PG_CMD_PUTS("DROP TABLE tmp_pg_shdescription;\n\n");
 }
 
 /*
@@ -2586,8 +2550,6 @@ void
 setup_data_file_paths(void)
 {
    set_input(&bki_file, "postgres.bki");
-   set_input(&desc_file, "postgres.description");
-   set_input(&shdesc_file, "postgres.shdescription");
    set_input(&hba_file, "pg_hba.conf.sample");
    set_input(&ident_file, "pg_ident.conf.sample");
    set_input(&conf_file, "postgresql.conf.sample");
@@ -2602,13 +2564,11 @@ setup_data_file_paths(void)
                "VERSION=%s\n"
                "PGDATA=%s\nshare_path=%s\nPGPATH=%s\n"
                "POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n"
-               "POSTGRES_DESCR=%s\nPOSTGRES_SHDESCR=%s\n"
                "POSTGRESQL_CONF_SAMPLE=%s\n"
                "PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n",
                PG_VERSION,
                pg_data, share_path, bin_path,
                username, bki_file,
-               desc_file, shdesc_file,
                conf_file,
                hba_file, ident_file);
        if (show_setting)
@@ -2616,8 +2576,6 @@ setup_data_file_paths(void)
    }
 
    check_input(bki_file);
-   check_input(desc_file);
-   check_input(shdesc_file);
    check_input(hba_file);
    check_input(ident_file);
    check_input(conf_file);
index 235de932532d08378c896ec5ebad5c3d183077ef..672bb2d65031f9f2cc3a36ea453f4c5b9a393dbb 100755 (executable)
@@ -71,8 +71,6 @@ if %DIST%==1 if exist src\interfaces\ecpg\preproc\c_kwlist_d.h del /q src\interf
 if %DIST%==1 if exist src\interfaces\ecpg\preproc\ecpg_kwlist_d.h del /q src\interfaces\ecpg\preproc\ecpg_kwlist_d.h
 if %DIST%==1 if exist src\interfaces\ecpg\preproc\preproc.y del /q src\interfaces\ecpg\preproc\preproc.y
 if %DIST%==1 if exist src\backend\catalog\postgres.bki del /q src\backend\catalog\postgres.bki
-if %DIST%==1 if exist src\backend\catalog\postgres.description del /q src\backend\catalog\postgres.description
-if %DIST%==1 if exist src\backend\catalog\postgres.shdescription del /q src\backend\catalog\postgres.shdescription
 if %DIST%==1 if exist src\backend\catalog\schemapg.h del /q src\backend\catalog\schemapg.h
 if %DIST%==1 if exist src\backend\catalog\pg_*_d.h del /q src\backend\catalog\pg_*_d.h
 if %DIST%==1 if exist src\backend\catalog\bki-stamp del /q src\backend\catalog\bki-stamp