head	1.9;
access;
symbols
	REL7_4_29:1.4.6.1
	REL8_0_25:1.8
	REL7_4_28:1.4.6.1
	REL8_0_24:1.8
	REL7_4_27:1.4.6.1
	REL8_0_23:1.8
	REL7_4_26:1.4.6.1
	REL8_0_22:1.8
	REL7_4_25:1.4.6.1
	REL8_0_21:1.8
	REL7_4_24:1.4.6.1
	REL8_0_20:1.8
	REL7_4_23:1.4.6.1
	REL8_0_19:1.8
	REL7_4_22:1.4.6.1
	REL8_0_18:1.8
	REL7_4_21:1.4.6.1
	REL8_0_17:1.8
	REL7_4_20:1.4.6.1
	REL8_0_16:1.8
	REL7_3_21:1.4.2.1
	REL7_4_19:1.4.6.1
	REL8_0_15:1.8
	REL7_3_20:1.4.2.1
	REL7_4_18:1.4.6.1
	REL8_0_14:1.8
	REL7_3_19:1.4.2.1
	REL7_4_17:1.4.6.1
	REL8_0_13:1.8
	REL8_0_12:1.8
	REL7_3_18:1.4.2.1
	REL7_4_16:1.4.6.1
	REL8_0_11:1.8
	REL8_0_10:1.8
	REL7_4_15:1.4.6.1
	REL7_3_17:1.4.2.1
	REL8_0_9:1.8
	REL7_4_14:1.4.6.1
	REL7_3_16:1.4.2.1
	REL7_3_15:1.4.2.1
	REL7_4_13:1.4.6.1
	REL8_0_8:1.8
	REL7_3_14:1.4.2.1
	REL7_4_12:1.4.6.1
	REL8_0_7:1.8
	REL7_3_13:1.4.2.1
	REL7_4_11:1.4.6.1
	REL8_0_6:1.8
	REL7_3_12:1.4.2.1
	REL7_4_10:1.4.6.1
	REL8_0_5:1.8
	REL7_3_11:1.4.2.1
	REL7_4_9:1.4.6.1
	REL8_0_4:1.8
	REL7_2_8:1.3.2.1
	REL7_3_10:1.4.2.1
	REL7_4_8:1.4.6.1
	REL8_0_3:1.8
	REL8_0_2:1.8
	REL7_2_7:1.3.2.1
	REL7_3_9:1.4.2.1
	REL7_4_7:1.4.6.1
	REL8_0_1:1.8
	REL8_0_STABLE:1.8.0.4
	REL8_0_0:1.8.0.2
	REL8_0_0RC5:1.8
	REL8_0_0RC4:1.8
	REL8_0_0RC3:1.8
	REL8_0_0RC2:1.8
	REL8_0_0RC1:1.8
	REL8_0_0BETA5:1.8
	REL8_0_0BETA4:1.5
	REL7_4_6:1.4.6.1
	REL7_3_8:1.4.2.1
	REL7_2_6:1.3.2.1
	REL8_0_0BETA3:1.4
	REL8_0_0BETA2:1.4
	REL7_2_5:1.3
	REL7_4_5:1.4
	REL7_3_7:1.4
	REL7_4_4:1.4
	REL8_0_0BETA1:1.4
	REL7_4_3:1.4
	REL7_4_2:1.4
	REL7_3_6:1.4
	REL7_4_1:1.4
	REL7_3_5:1.4
	REL7_4:1.4
	REL7_4_RC2:1.4
	REL7_4_STABLE:1.4.0.6
	REL7_4_RC1:1.4
	REL7_4_BETA5:1.4
	REL7_4_BETA4:1.4
	REL7_4_BETA3:1.4
	REL7_4_BETA2:1.4
	WIN32_DEV:1.4.0.4
	REL7_4_BETA1:1.4
	REL7_3_4:1.4
	REL7_3_2:1.4
	REL7_2_4:1.3
	REL7_3_STABLE:1.4.0.2
	REL7_2_3:1.3
	REL7_2_STABLE:1.3.0.2
	REL7_2:1.3
	REL7_2_RC2:1.3
	REL7_2_RC1:1.3
	REL7_2_BETA5:1.3
	REL7_2_BETA4:1.3
	REL7_2_BETA3:1.3
	REL7_2_BETA2:1.3
	REL7_2_BETA1:1.3
	REL7_1_2:1.2
	REL7_1_STABLE:1.2.0.6
	REL7_1_BETA:1.2
	REL7_1_BETA3:1.2
	REL7_1_BETA2:1.2
	REL7_1:1.2
	REL7_0_PATCHES:1.2.0.4
	REL7_0:1.2
	REL6_5_PATCHES:1.2.0.2
	REL6_5:1.2
	REL6_4:1.1.0.2;
locks; strict;
comment	@# @;


1.9
date	2005.06.23.02.33.27;	author tgl;	state dead;
branches;
next	1.8;

1.8
date	2004.11.04.02.04.07;	author momjian;	state Exp;
branches;
next	1.7;

1.7
date	2004.11.03.23.06.52;	author momjian;	state Exp;
branches;
next	1.6;

1.6
date	2004.11.03.22.46.15;	author momjian;	state Exp;
branches;
next	1.5;

1.5
date	2004.10.20.16.42.46;	author tgl;	state Exp;
branches;
next	1.4;

1.4
date	2002.09.05.19.57.32;	author tgl;	state Exp;
branches
	1.4.2.1
	1.4.6.1;
next	1.3;

1.3
date	2001.08.10.18.57.32;	author tgl;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	99.03.26.07.21.57;	author tgl;	state Exp;
branches;
next	1.1;

1.1
date	98.09.14.01.14.48;	author momjian;	state Exp;
branches;
next	;

1.3.2.1
date	2004.10.21.17.12.35;	author tgl;	state Exp;
branches;
next	;

1.4.2.1
date	2004.10.21.17.12.27;	author tgl;	state Exp;
branches;
next	;

1.4.6.1
date	2004.10.21.17.12.19;	author tgl;	state Exp;
branches;
next	;


desc
@@


1.9
log
@Move findoidjoins out of contrib and into src/tools, which is a more
logical place for it since it is of no use to users.  Per recent
discussions on cleaning up contrib.
@
text
@#! /bin/sh

# You first run findoidjoins on the template1 database, and send that
# output into this script to generate a list of SQL statements.

# NOTE: any field that findoidjoins thinks joins to more than one table
# will NOT be checked by the output of this script.  You should be
# suspicious of multiple entries in findoidjoins' output.

# Caution: you may need to use GNU awk.
AWK=${AWK:-awk}

TMP="${TMPDIR:-/tmp}/make_oidjoins_check.$$"
trap "rm -rf $TMP" 0 1 2 3 15

# Create a temporary directory with the proper permissions so no one can
# intercept our temporary files and cause a security breach.
OMASK="`umask`"
umask 077
if ! mkdir $TMP
then	echo "Can't create temporary directory $TMP." 1>&2
	exit 1
fi
umask "$OMASK"
unset OMASK

INPUTFILE="$TMP/a"
DUPSFILE="$TMP/b"
NONDUPSFILE="$TMP/c"

# Read input
cat "$@@" >$INPUTFILE

# Look for fields with multiple references.
cat $INPUTFILE | cut -d' ' -f2 | sort | uniq -d >$DUPSFILE
if [ -s $DUPSFILE ] ; then
	echo "Ignoring these fields that link to multiple tables:" 1>&2
	cat $DUPSFILE 1>&2
fi

# Get the non-multiply-referenced fields.
cat $INPUTFILE | while read LINE
do
	set -- $LINE
	grep "^$2\$" $DUPSFILE >/dev/null 2>&1 || echo $LINE
done >$NONDUPSFILE

# Generate the output.
cat $NONDUPSFILE |
$AWK -F'[ \.]' '\
	BEGIN \
	{
		printf "\
--\n\
-- This is created by pgsql/contrib/findoidjoins/make_oidjoin_check\n\
--\n";
	}
	{
		printf "\
SELECT	ctid, %s \n\
FROM	%s.%s fk \n\
WHERE	%s != 0 AND \n\
	NOT EXISTS(SELECT 1 FROM %s.%s pk WHERE pk.oid = fk.%s);\n",
	$4, $2, $3, $4,
	$6, $7, $4;
	}'

exit 0
@


1.8
log
@Honor TMPDIR.

Add the script name to the tmp directory name.

Move trap up now that the dir is more unique.
@
text
@@


1.7
log
@Move trap to after the directory is created.
@
text
@d13 2
a14 1
TMP="/tmp/$$"
a26 2
trap "rm -rf $TMP" 0 1 2 3 15

@


1.6
log
@Create temporary files securely.
@
text
@a13 1
trap "rm -rf $TMP" 0 1 2 3 15
d26 2
@


1.5
log
@Use temp files in current directory, not /tmp, to reduce security risk
while running this script.
@
text
@d13 2
a14 4
INPUTFILE="tmp$$a"
DUPSFILE="tmp$$b"
NONDUPSFILE="tmp$$c"
rm -f $INPUTFILE $DUPSFILE $NONDUPSFILE
d16 14
a29 1
trap "rm -f $INPUTFILE $DUPSFILE $NONDUPSFILE" 0 1 2 3 15
@


1.4
log
@findoidjoins is updated for schemas, does not use libpgeasy.
From Joe Conway.
@
text
@d13 6
a18 1
trap "rm -f /tmp/$$ /tmp/$$a /tmp/$$b" 0 1 2 3 15
d21 1
a21 1
cat "$@@" >/tmp/$$
d24 2
a25 2
cat /tmp/$$ | cut -d' ' -f2 | sort | uniq -d >/tmp/$$a
if [ -s /tmp/$$a ] ; then
d27 1
a27 1
	cat /tmp/$$a 1>&2
d31 1
a31 1
cat /tmp/$$ | while read LINE
d34 2
a35 2
	grep "^$2\$" /tmp/$$a >/dev/null 2>&1 || echo $LINE
done >/tmp/$$b
d38 1
a38 1
cat /tmp/$$b |
@


1.4.2.1
log
@Back-patch make_oidjoins_check security improvement.
@
text
@d13 1
a13 6
INPUTFILE="tmp$$a"
DUPSFILE="tmp$$b"
NONDUPSFILE="tmp$$c"
rm -f $INPUTFILE $DUPSFILE $NONDUPSFILE

trap "rm -f $INPUTFILE $DUPSFILE $NONDUPSFILE" 0 1 2 3 15
d16 1
a16 1
cat "$@@" >$INPUTFILE
d19 2
a20 2
cat $INPUTFILE | cut -d' ' -f2 | sort | uniq -d >$DUPSFILE
if [ -s $DUPSFILE ] ; then
d22 1
a22 1
	cat $DUPSFILE 1>&2
d26 1
a26 1
cat $INPUTFILE | while read LINE
d29 2
a30 2
	grep "^$2\$" $DUPSFILE >/dev/null 2>&1 || echo $LINE
done >$NONDUPSFILE
d33 1
a33 1
cat $NONDUPSFILE |
@


1.4.6.1
log
@Back-patch make_oidjoins_check security improvement.
@
text
@d13 1
a13 6
INPUTFILE="tmp$$a"
DUPSFILE="tmp$$b"
NONDUPSFILE="tmp$$c"
rm -f $INPUTFILE $DUPSFILE $NONDUPSFILE

trap "rm -f $INPUTFILE $DUPSFILE $NONDUPSFILE" 0 1 2 3 15
d16 1
a16 1
cat "$@@" >$INPUTFILE
d19 2
a20 2
cat $INPUTFILE | cut -d' ' -f2 | sort | uniq -d >$DUPSFILE
if [ -s $DUPSFILE ] ; then
d22 1
a22 1
	cat $DUPSFILE 1>&2
d26 1
a26 1
cat $INPUTFILE | while read LINE
d29 2
a30 2
	grep "^$2\$" $DUPSFILE >/dev/null 2>&1 || echo $LINE
done >$NONDUPSFILE
d33 1
a33 1
cat $NONDUPSFILE |
@


1.3
log
@Make OIDs optional, per discussions in pghackers.  WITH OIDS is still the
default, but OIDS are removed from many system catalogs that don't need them.
Some interesting side effects: TOAST pointers are 20 bytes not 32 now;
pg_description has a three-column key instead of one.

Bugs fixed in passing: BINARY cursors work again; pg_class.relhaspkey
has some usefulness; pg_dump dumps comments on indexes, rules, and
triggers in a valid order.

initdb forced.
@
text
@d29 1
a29 1
	grep "$2" /tmp/$$a >/dev/null 2>&1 || echo $LINE
d44 6
a49 7
SELECT	ctid, %s.%s \n\
FROM	%s \n\
WHERE	%s.%s != 0 AND \n\
	NOT EXISTS(SELECT * FROM %s AS t1 WHERE t1.oid = %s.%s);\n",
	$2, $3, $2,
	$2, $3,
	$5, $2, $3;
@


1.3.2.1
log
@Back-patch make_oidjoins_check security improvement.
@
text
@d13 1
a13 6
INPUTFILE="tmp$$a"
DUPSFILE="tmp$$b"
NONDUPSFILE="tmp$$c"
rm -f $INPUTFILE $DUPSFILE $NONDUPSFILE

trap "rm -f $INPUTFILE $DUPSFILE $NONDUPSFILE" 0 1 2 3 15
d16 1
a16 1
cat "$@@" >$INPUTFILE
d19 2
a20 2
cat $INPUTFILE | cut -d' ' -f2 | sort | uniq -d >$DUPSFILE
if [ -s $DUPSFILE ] ; then
d22 1
a22 1
	cat $DUPSFILE 1>&2
d26 1
a26 1
cat $INPUTFILE | while read LINE
d29 2
a30 2
	grep "^$2\$" $DUPSFILE >/dev/null 2>&1 || echo $LINE
done >$NONDUPSFILE
d33 1
a33 1
cat $NONDUPSFILE |
@


1.2
log
@Update findoidjoins for 6.5: remove workaround for long-dead bug,
use NOT EXISTS() which is a lot faster than NOT IN (),
update documentation.
@
text
@d4 1
a4 1
# output into this file to generate a list of SQL statements.
d44 1
a44 1
SELECT	oid, %s.%s \n\
@


1.1
log
@Add new make_oidjoin_check utility and template1_check.sql.  Fix some
pg_operator problems.
@
text
@d1 2
a2 1
:
d5 8
d15 1
d17 2
d20 6
d31 2
d34 1
a34 1
awk -F'[ \.]' '\
d46 5
a50 9
WHERE	%s%s.%s%s NOT IN (SELECT oid FROM %s) AND \n\
	%s%s.%s%s != 0;\n", 	$2, $3, $2,
				($5 == "pg_proc") ? "RegprocToOid(" : "",
				$2, $3,
				($5 == "pg_proc") ? ")" : "",
				$5,
				($5 == "pg_proc") ? "RegprocToOid(" : "",
				$2, $3,
				($5 == "pg_proc") ? ")" : "";
d52 2
@
