mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Update findoidjoins for 6.5: remove workaround for long-dead bug,
use NOT EXISTS() which is a lot faster than NOT IN (), update documentation.
This commit is contained in:
@ -1,17 +1,37 @@
|
||||
:
|
||||
#! /bin/sh
|
||||
|
||||
# You first run findoidjoins on the template1 database, and send that
|
||||
# output into this file 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}
|
||||
|
||||
trap "rm -f /tmp/$$ /tmp/$$a /tmp/$$b" 0 1 2 3 15
|
||||
|
||||
# Read input
|
||||
cat "$@" >/tmp/$$
|
||||
|
||||
# Look for fields with multiple references.
|
||||
cat /tmp/$$ | cut -d' ' -f2 | sort | uniq -d >/tmp/$$a
|
||||
if [ -s /tmp/$$a ] ; then
|
||||
echo "Ignoring these fields that link to multiple tables:" 1>&2
|
||||
cat /tmp/$$a 1>&2
|
||||
fi
|
||||
|
||||
# Get the non-multiply-referenced fields.
|
||||
cat /tmp/$$ | while read LINE
|
||||
do
|
||||
set -- $LINE
|
||||
grep "$2" /tmp/$$a >/dev/null 2>&1 || echo $LINE
|
||||
done >/tmp/$$b
|
||||
|
||||
# Generate the output.
|
||||
cat /tmp/$$b |
|
||||
awk -F'[ \.]' '\
|
||||
$AWK -F'[ \.]' '\
|
||||
BEGIN \
|
||||
{
|
||||
printf "\
|
||||
@ -23,13 +43,11 @@ awk -F'[ \.]' '\
|
||||
printf "\
|
||||
SELECT oid, %s.%s \n\
|
||||
FROM %s \n\
|
||||
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") ? ")" : "";
|
||||
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;
|
||||
}'
|
||||
|
||||
exit 0
|
||||
|
Reference in New Issue
Block a user