aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2013-09-11 14:47:44 -0400
committerPeter Eisentraut <peter_e@gmx.net>2013-10-10 20:09:42 -0400
commit3dc543b3d84f048ca563af1bc98092f1e01e4a81 (patch)
tree0f715273457ea84075831aa7cea15cba6378409d
parent083b86e71bd39549927db6a4007b0073a98e5a00 (diff)
downloadpostgresql-3dc543b3d84f048ca563af1bc98092f1e01e4a81.tar.gz
postgresql-3dc543b3d84f048ca563af1bc98092f1e01e4a81.zip
Replace duplicate_oids with Perl implementation
It is more portable, more robust, and more readable. From: Andrew Dunstan <andrew@dunslane.net>
-rwxr-xr-xsrc/include/catalog/duplicate_oids60
1 files changed, 33 insertions, 27 deletions
diff --git a/src/include/catalog/duplicate_oids b/src/include/catalog/duplicate_oids
index 82c12f3afc2..f3d1136a35e 100755
--- a/src/include/catalog/duplicate_oids
+++ b/src/include/catalog/duplicate_oids
@@ -1,30 +1,36 @@
-#!/bin/sh
-#
-# duplicate_oids
-#
-# src/include/catalog/duplicate_oids
-#
-# finds manually-assigned oids that are duplicated in the system tables.
-#
-# run this script in src/include/catalog.
-#
+#!/usr/bin/perl
-# note: we exclude BKI_BOOTSTRAP relations since they are expected to have
-# matching DATA lines in pg_class.h and pg_type.h
+use strict;
+use warnings;
-cat pg_*.h toasting.h indexing.h | \
-egrep -v -e '^CATALOG\(.*BKI_BOOTSTRAP' | \
-sed -n -e 's/^DATA(insert *OID *= *\([0-9][0-9]*\).*$/\1/p' \
- -e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*BKI_ROWTYPE_OID(\([0-9][0-9]*\)).*$/\1,\2/p' \
- -e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
- -e 's/^DECLARE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
- -e 's/^DECLARE_UNIQUE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
- -e 's/^DECLARE_TOAST([^,]*, *\([0-9][0-9]*\), *\([0-9][0-9]*\).*$/\1,\2/p' | \
-tr ',' '\n' | \
-sort -n | \
-uniq -d | \
-grep '.'
+BEGIN
+{
+ @ARGV = (glob("pg_*.h"), qw(indexing.h toasting.h));
+}
-# nonzero exit code if lines were produced
-[ $? -eq 1 ]
-exit
+my %oidcounts;
+
+while(<>)
+{
+ next if /^CATALOG\(.*BKI_BOOTSTRAP/;
+ next unless
+ /^DATA\(insert *OID *= *(\d+)/ ||
+ /^CATALOG\([^,]*, *(\d+).*BKI_ROWTYPE_OID\((\d+)\)/ ||
+ /^CATALOG\([^,]*, *(\d+)/ ||
+ /^DECLARE_INDEX\([^,]*, *(\d+)/ ||
+ /^DECLARE_UNIQUE_INDEX\([^,]*, *(\d+)/ ||
+ /^DECLARE_TOAST\([^,]*, *(\d+), *(\d+)/;
+ $oidcounts{$1}++;
+ $oidcounts{$2}++ if $2;
+}
+
+my $found = 0;
+
+foreach my $oid (sort {$a <=> $b} keys %oidcounts)
+{
+ next unless $oidcounts{$oid} > 1;
+ $found = 1;
+ print "$oid\n";
+}
+
+exit $found;