1#!/bin/sh
2#
3# unused_oids
4#
5# src/include/catalog/unused_oids
6#
7#	finds blocks of manually-assignable oids that have not already been
8#	claimed by post_hackers.  primarily useful for finding available
9#	oids for new internal functions.  the numbers printed are inclusive
10#	ranges of unused oids.
11#
12#	before using a large empty block, make sure you aren't about
13#	to take over what was intended as expansion space for something
14#	else.
15#
16#	run this script in src/include/catalog.
17#
18
19
20AWK="awk"
21
22# Get FirstBootstrapObjectId from access/transam.h
23FIRSTOBJECTID=`grep '#define[ 	]*FirstBootstrapObjectId' ../access/transam.h | $AWK '{ print $3 }'`
24export FIRSTOBJECTID
25
26# this part (down to the uniq step) should match the duplicate_oids script
27# note: we exclude BKI_BOOTSTRAP relations since they are expected to have
28# matching DATA lines in pg_class.h and pg_type.h
29
30cat pg_*.h toasting.h indexing.h | \
31egrep -v -e '^CATALOG\(.*BKI_BOOTSTRAP' | \
32sed -n	-e 's/^DATA(insert *OID *= *\([0-9][0-9]*\).*$/\1/p' \
33	-e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*BKI_ROWTYPE_OID(\([0-9][0-9]*\)).*$/\1,\2/p' \
34	-e 's/^CATALOG([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
35	-e 's/^DECLARE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
36	-e 's/^DECLARE_UNIQUE_INDEX([^,]*, *\([0-9][0-9]*\).*$/\1/p' \
37	-e 's/^DECLARE_TOAST([^,]*, *\([0-9][0-9]*\), *\([0-9][0-9]*\).*$/\1,\2/p' | \
38tr ',' '\n' | \
39sort -n | \
40uniq | \
41$AWK '
42BEGIN {
43	last = 0;
44}
45/^[0-9]/ {
46	if ($1 > last + 1) {
47		if ($1 > last + 2) {
48			print last + 1, "-", $1 - 1;
49		} else {
50			print last + 1;
51		}
52	}
53	last = $1;
54}
55END {
56	print last + 1, "-", ENVIRON["FIRSTOBJECTID"]-1;
57}'
58