diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/catalog/.gitignore | 1 | ||||
-rw-r--r-- | src/backend/catalog/Catalog.pm | 11 | ||||
-rw-r--r-- | src/backend/catalog/Makefile | 9 | ||||
-rw-r--r-- | src/backend/catalog/genbki.pl | 23 |
4 files changed, 35 insertions, 9 deletions
diff --git a/src/backend/catalog/.gitignore b/src/backend/catalog/.gitignore index 11e2e520232..4bd3ee9d7f3 100644 --- a/src/backend/catalog/.gitignore +++ b/src/backend/catalog/.gitignore @@ -1,4 +1,5 @@ /postgres.bki /schemapg.h +/system_constraints.sql /pg_*_d.h /bki-stamp diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm index a37c3271229..061f3d8c21e 100644 --- a/src/backend/catalog/Catalog.pm +++ b/src/backend/catalog/Catalog.pm @@ -94,14 +94,15 @@ sub ParseHeader push @{ $catalog{toasting} }, { parent_table => $1, toast_oid => $2, toast_index_oid => $3 }; } - elsif (/^DECLARE_(UNIQUE_)?INDEX\(\s*(\w+),\s*(\d+),\s*(.+)\)/) + elsif (/^DECLARE_(UNIQUE_)?INDEX(_PKEY)?\(\s*(\w+),\s*(\d+),\s*(.+)\)/) { push @{ $catalog{indexing} }, - { + { is_unique => $1 ? 1 : 0, - index_name => $2, - index_oid => $3, - index_decl => $4 + is_pkey => $2 ? 1 : 0, + index_name => $3, + index_oid => $4, + index_decl => $5 }; } elsif (/^CATALOG\((\w+),(\d+),(\w+)\)/) diff --git a/src/backend/catalog/Makefile b/src/backend/catalog/Makefile index c85f0ca7b66..995ddf12852 100644 --- a/src/backend/catalog/Makefile +++ b/src/backend/catalog/Makefile @@ -121,6 +121,7 @@ $(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,system_constraints.sql) '$(DESTDIR)$(datadir)/system_constraints.sql' $(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' @@ -130,11 +131,11 @@ installdirs: .PHONY: uninstall-data uninstall-data: - rm -f $(addprefix '$(DESTDIR)$(datadir)'/, postgres.bki system_views.sql information_schema.sql sql_features.txt) + rm -f $(addprefix '$(DESTDIR)$(datadir)'/, postgres.bki system_constraints.sql system_views.sql information_schema.sql sql_features.txt) -# postgres.bki and the generated headers are in the distribution tarball, -# so they are not cleaned here. +# postgres.bki, system_constraints.sql, and the generated headers are +# in the distribution tarball, so they are not cleaned here. clean: maintainer-clean: clean - rm -f bki-stamp postgres.bki $(GENERATED_HEADERS) + rm -f bki-stamp postgres.bki system_constraints.sql $(GENERATED_HEADERS) diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl index 009e215da1c..b68c1752c00 100644 --- a/src/backend/catalog/genbki.pl +++ b/src/backend/catalog/genbki.pl @@ -55,6 +55,7 @@ my %catalog_data; my @toast_decls; my @index_decls; my %oidcounts; +my @system_constraints; foreach my $header (@ARGV) { @@ -137,6 +138,17 @@ foreach my $header (@ARGV) $index->{index_name}, $index->{index_oid}, $index->{index_decl}; $oidcounts{ $index->{index_oid} }++; + + if ($index->{is_unique}) + { + $index->{index_decl} =~ /on (\w+) using/; + my $tblname = $1; + push @system_constraints, + sprintf "ALTER TABLE %s ADD %s USING INDEX %s;", + $tblname, + $index->{is_pkey} ? "PRIMARY KEY" : "UNIQUE", + $index->{index_name}; + } } } @@ -388,6 +400,9 @@ open my $bki, '>', $bkifile . $tmpext my $schemafile = $output_path . 'schemapg.h'; open my $schemapg, '>', $schemafile . $tmpext or die "can't open $schemafile$tmpext: $!"; +my $constraints_file = $output_path . 'system_constraints.sql'; +open my $constraints, '>', $constraints_file . $tmpext + or die "can't open $constraints_file$tmpext: $!"; # Generate postgres.bki and pg_*_d.h headers. @@ -648,6 +663,12 @@ die "genbki OID counter reached $GenbkiNextOid, overrunning FirstBootstrapObjectId\n" if $GenbkiNextOid > $FirstBootstrapObjectId; +# Now generate system_constraints.sql + +foreach my $c (@system_constraints) +{ + print $constraints $c, "\n"; +} # Now generate schemapg.h @@ -688,10 +709,12 @@ print $schemapg "\n#endif\t\t\t\t\t\t\t/* SCHEMAPG_H */\n"; # We're done emitting data close $bki; close $schemapg; +close $constraints; # Finally, rename the completed files into place. Catalog::RenameTempFile($bkifile, $tmpext); Catalog::RenameTempFile($schemafile, $tmpext); +Catalog::RenameTempFile($constraints_file, $tmpext); exit 0; |