postgresql/src/tools/findoidjoins
Tom Lane dddfc4cb2e Prevent accidental linking of system-supplied copies of libpq.so etc.
We were being careless in some places about the order of -L switches in
link command lines, such that -L switches referring to external directories
could come before those referring to directories within the build tree.
This made it possible to accidentally link a system-supplied library, for
example /usr/lib/libpq.so, in place of the one built in the build tree.
Hilarity ensued, the more so the older the system-supplied library is.

To fix, break LDFLAGS into two parts, a sub-variable LDFLAGS_INTERNAL
and the main LDFLAGS variable, both of which are "recursively expanded"
so that they can be incrementally adjusted by different makefiles.
Establish a policy that -L switches for directories in the build tree
must always be added to LDFLAGS_INTERNAL, while -L switches for external
directories must always be added to LDFLAGS.  This is sufficient to
ensure a safe search order.  For simplicity, we typically also put -l
switches for the respective libraries into those same variables.
(Traditional make usage would have us put -l switches into LIBS, but
cleaning that up is a project for another day, as there's no clear
need for it.)

This turns out to also require separating SHLIB_LINK into two variables,
SHLIB_LINK and SHLIB_LINK_INTERNAL, with a similar rule about which
switches go into which variable.  And likewise for PG_LIBS.

Although this change might appear to affect external users of pgxs.mk,
I think it doesn't; they shouldn't have any need to touch the _INTERNAL
variables.

In passing, tweak src/common/Makefile so that the value of CPPFLAGS
recorded in pg_config lacks "-DFRONTEND" and the recorded value of
LDFLAGS lacks "-L../../../src/common".  Both of those things are
mistakes, apparently introduced during prior code rearrangements,
as old versions of pg_config don't print them.  In general we don't
want anything that's specific to the src/common subdirectory to
appear in those outputs.

This is certainly a bug fix, but in view of the lack of field
complaints, I'm unsure whether it's worth the risk of back-patching.
In any case it seems wise to see what the buildfarm makes of it first.

Discussion: https://postgr.es/m/25214.1522604295@sss.pgh.pa.us
2018-04-03 16:26:05 -04:00
..
.gitignore Update oidjoins regression test for 9.4. 2014-04-16 14:28:59 -04:00
findoidjoins.c Empty search_path in Autovacuum and non-psql/pgbench clients. 2018-02-26 07:39:44 -08:00
make_oidjoins_check Improve findoidjoins to cover more cases. 2011-04-23 19:33:17 -04:00
Makefile Prevent accidental linking of system-supplied copies of libpq.so etc. 2018-04-03 16:26:05 -04:00
README Update oidjoins regression test for v10. 2017-05-15 14:04:11 -04:00

src/tools/findoidjoins/README

findoidjoins
============

This program scans a database and prints oid fields (also reg* fields)
and the tables they join to.  It is normally used to check the system
catalog join relationships (shown below for 10devel as of 2017-05-15).

Historically this has been run against an empty database such as template1,
but there's a problem with that approach: some of the catalogs are empty
and so their joining columns won't show up in the output.  Current practice
is to run it against the regression-test database, which populates the
catalogs in interesting ways.

Note that unexpected matches may indicate bogus entries in system tables;
don't accept a peculiar match without question.  In particular, a field
shown as joining to more than one target table is probably messed up.
In v10, the *only* fields that should join to more than one target
table are:
pg_description.objoid, pg_depend.objid, pg_depend.refobjid,
pg_shdescription.objoid, pg_shdepend.objid, pg_shdepend.refobjid,
and pg_init_privs.objoid.
(Running make_oidjoins_check is an easy way to spot fields joining to more
than one table, BTW.)

The shell script make_oidjoins_check converts findoidjoins' output
into an SQL script that checks for dangling links (entries in an
OID or REG* column that don't match any row in the expected table).
Note that fields joining to more than one table are NOT processed,
just reported as linking to more than one table.

The result of make_oidjoins_check should be installed as the "oidjoins"
regression test.  The oidjoins test should be updated after any
revision in the patterns of cross-links between system tables.
(Typically we update it at the end of each development cycle.)

NOTE: as of v10, make_oidjoins_check produces two bogus join checks:
Join pg_catalog.pg_class.relfilenode => pg_catalog.pg_class.oid
Join pg_catalog.pg_database.datlastsysoid => pg_catalog.pg_database.oid
These are artifacts and should not be added to the oidjoins regression test.
You might also get output for pg_shdepend.refobjid and pg_shdescription.objoid,
neither of which should be added to the regression test.

In short, the procedure is:

1. make installcheck in src/test/regress
2. cd here, make
3. ./findoidjoins regression >foj.out
4. ./make_oidjoins_check foj.out >oidjoins.sql
5. paste foj.out below, removing the entries reported as duplicative
   by make_oidjoins_check or described as bogus above
6. remove bogus tests in oidjoins.sql as per above
7. copy oidjoins.sql to src/test/regress/sql/,
   and update oidjoins.out to match.
8. Review diffs to ensure they correspond to new catalog relationships,
   then commit.  (Sometimes, a pre-existing catalog relationship might
   become newly visible here as a result of the regression tests populating
   a catalog they didn't before.  That's OK too.)

---------------------------------------------------------------------------

Join pg_catalog.pg_aggregate.aggfnoid => pg_catalog.pg_proc.oid
Join pg_catalog.pg_aggregate.aggtransfn => pg_catalog.pg_proc.oid
Join pg_catalog.pg_aggregate.aggfinalfn => pg_catalog.pg_proc.oid
Join pg_catalog.pg_aggregate.aggcombinefn => pg_catalog.pg_proc.oid
Join pg_catalog.pg_aggregate.aggserialfn => pg_catalog.pg_proc.oid
Join pg_catalog.pg_aggregate.aggdeserialfn => pg_catalog.pg_proc.oid
Join pg_catalog.pg_aggregate.aggmtransfn => pg_catalog.pg_proc.oid
Join pg_catalog.pg_aggregate.aggminvtransfn => pg_catalog.pg_proc.oid
Join pg_catalog.pg_aggregate.aggmfinalfn => pg_catalog.pg_proc.oid
Join pg_catalog.pg_aggregate.aggsortop => pg_catalog.pg_operator.oid
Join pg_catalog.pg_aggregate.aggtranstype => pg_catalog.pg_type.oid
Join pg_catalog.pg_aggregate.aggmtranstype => pg_catalog.pg_type.oid
Join pg_catalog.pg_am.amhandler => pg_catalog.pg_proc.oid
Join pg_catalog.pg_amop.amopfamily => pg_catalog.pg_opfamily.oid
Join pg_catalog.pg_amop.amoplefttype => pg_catalog.pg_type.oid
Join pg_catalog.pg_amop.amoprighttype => pg_catalog.pg_type.oid
Join pg_catalog.pg_amop.amopopr => pg_catalog.pg_operator.oid
Join pg_catalog.pg_amop.amopmethod => pg_catalog.pg_am.oid
Join pg_catalog.pg_amop.amopsortfamily => pg_catalog.pg_opfamily.oid
Join pg_catalog.pg_amproc.amprocfamily => pg_catalog.pg_opfamily.oid
Join pg_catalog.pg_amproc.amproclefttype => pg_catalog.pg_type.oid
Join pg_catalog.pg_amproc.amprocrighttype => pg_catalog.pg_type.oid
Join pg_catalog.pg_amproc.amproc => pg_catalog.pg_proc.oid
Join pg_catalog.pg_attrdef.adrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_attribute.attrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_attribute.atttypid => pg_catalog.pg_type.oid
Join pg_catalog.pg_attribute.attcollation => pg_catalog.pg_collation.oid
Join pg_catalog.pg_auth_members.roleid => pg_catalog.pg_authid.oid
Join pg_catalog.pg_auth_members.member => pg_catalog.pg_authid.oid
Join pg_catalog.pg_auth_members.grantor => pg_catalog.pg_authid.oid
Join pg_catalog.pg_cast.castsource => pg_catalog.pg_type.oid
Join pg_catalog.pg_cast.casttarget => pg_catalog.pg_type.oid
Join pg_catalog.pg_cast.castfunc => pg_catalog.pg_proc.oid
Join pg_catalog.pg_class.relnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_class.reltype => pg_catalog.pg_type.oid
Join pg_catalog.pg_class.reloftype => pg_catalog.pg_type.oid
Join pg_catalog.pg_class.relowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_class.relam => pg_catalog.pg_am.oid
Join pg_catalog.pg_class.reltablespace => pg_catalog.pg_tablespace.oid
Join pg_catalog.pg_class.reltoastrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_collation.collnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_collation.collowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_constraint.connamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_constraint.conrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_constraint.contypid => pg_catalog.pg_type.oid
Join pg_catalog.pg_constraint.conindid => pg_catalog.pg_class.oid
Join pg_catalog.pg_constraint.confrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_conversion.connamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_conversion.conowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_conversion.conproc => pg_catalog.pg_proc.oid
Join pg_catalog.pg_database.datdba => pg_catalog.pg_authid.oid
Join pg_catalog.pg_database.dattablespace => pg_catalog.pg_tablespace.oid
Join pg_catalog.pg_db_role_setting.setdatabase => pg_catalog.pg_database.oid
Join pg_catalog.pg_depend.classid => pg_catalog.pg_class.oid
Join pg_catalog.pg_depend.refclassid => pg_catalog.pg_class.oid
Join pg_catalog.pg_description.classoid => pg_catalog.pg_class.oid
Join pg_catalog.pg_enum.enumtypid => pg_catalog.pg_type.oid
Join pg_catalog.pg_extension.extowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_extension.extnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_foreign_data_wrapper.fdwowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_foreign_server.srvowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_foreign_server.srvfdw => pg_catalog.pg_foreign_data_wrapper.oid
Join pg_catalog.pg_index.indexrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_index.indrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_inherits.inhrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_inherits.inhparent => pg_catalog.pg_class.oid
Join pg_catalog.pg_init_privs.classoid => pg_catalog.pg_class.oid
Join pg_catalog.pg_language.lanowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_language.lanplcallfoid => pg_catalog.pg_proc.oid
Join pg_catalog.pg_language.laninline => pg_catalog.pg_proc.oid
Join pg_catalog.pg_language.lanvalidator => pg_catalog.pg_proc.oid
Join pg_catalog.pg_largeobject.loid => pg_catalog.pg_largeobject_metadata.oid
Join pg_catalog.pg_largeobject_metadata.lomowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_namespace.nspowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_opclass.opcmethod => pg_catalog.pg_am.oid
Join pg_catalog.pg_opclass.opcnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_opclass.opcowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_opclass.opcfamily => pg_catalog.pg_opfamily.oid
Join pg_catalog.pg_opclass.opcintype => pg_catalog.pg_type.oid
Join pg_catalog.pg_opclass.opckeytype => pg_catalog.pg_type.oid
Join pg_catalog.pg_operator.oprnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_operator.oprowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_operator.oprleft => pg_catalog.pg_type.oid
Join pg_catalog.pg_operator.oprright => pg_catalog.pg_type.oid
Join pg_catalog.pg_operator.oprresult => pg_catalog.pg_type.oid
Join pg_catalog.pg_operator.oprcom => pg_catalog.pg_operator.oid
Join pg_catalog.pg_operator.oprnegate => pg_catalog.pg_operator.oid
Join pg_catalog.pg_operator.oprcode => pg_catalog.pg_proc.oid
Join pg_catalog.pg_operator.oprrest => pg_catalog.pg_proc.oid
Join pg_catalog.pg_operator.oprjoin => pg_catalog.pg_proc.oid
Join pg_catalog.pg_opfamily.opfmethod => pg_catalog.pg_am.oid
Join pg_catalog.pg_opfamily.opfnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_opfamily.opfowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_partitioned_table.partrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_policy.polrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_proc.pronamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_proc.proowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_proc.prolang => pg_catalog.pg_language.oid
Join pg_catalog.pg_proc.provariadic => pg_catalog.pg_type.oid
Join pg_catalog.pg_proc.protransform => pg_catalog.pg_proc.oid
Join pg_catalog.pg_proc.prorettype => pg_catalog.pg_type.oid
Join pg_catalog.pg_range.rngtypid => pg_catalog.pg_type.oid
Join pg_catalog.pg_range.rngsubtype => pg_catalog.pg_type.oid
Join pg_catalog.pg_range.rngcollation => pg_catalog.pg_collation.oid
Join pg_catalog.pg_range.rngsubopc => pg_catalog.pg_opclass.oid
Join pg_catalog.pg_range.rngcanonical => pg_catalog.pg_proc.oid
Join pg_catalog.pg_range.rngsubdiff => pg_catalog.pg_proc.oid
Join pg_catalog.pg_rewrite.ev_class => pg_catalog.pg_class.oid
Join pg_catalog.pg_sequence.seqrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_sequence.seqtypid => pg_catalog.pg_type.oid
Join pg_catalog.pg_shdepend.refclassid => pg_catalog.pg_class.oid
Join pg_catalog.pg_shdescription.classoid => pg_catalog.pg_class.oid
Join pg_catalog.pg_statistic.starelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_statistic.staop1 => pg_catalog.pg_operator.oid
Join pg_catalog.pg_statistic.staop2 => pg_catalog.pg_operator.oid
Join pg_catalog.pg_statistic.staop3 => pg_catalog.pg_operator.oid
Join pg_catalog.pg_statistic.staop4 => pg_catalog.pg_operator.oid
Join pg_catalog.pg_statistic.staop5 => pg_catalog.pg_operator.oid
Join pg_catalog.pg_statistic_ext.stxrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_statistic_ext.stxnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_statistic_ext.stxowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_tablespace.spcowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_transform.trftype => pg_catalog.pg_type.oid
Join pg_catalog.pg_transform.trflang => pg_catalog.pg_language.oid
Join pg_catalog.pg_transform.trffromsql => pg_catalog.pg_proc.oid
Join pg_catalog.pg_transform.trftosql => pg_catalog.pg_proc.oid
Join pg_catalog.pg_trigger.tgrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_trigger.tgfoid => pg_catalog.pg_proc.oid
Join pg_catalog.pg_trigger.tgconstrrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_trigger.tgconstrindid => pg_catalog.pg_class.oid
Join pg_catalog.pg_trigger.tgconstraint => pg_catalog.pg_constraint.oid
Join pg_catalog.pg_ts_config.cfgnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_ts_config.cfgowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_ts_config.cfgparser => pg_catalog.pg_ts_parser.oid
Join pg_catalog.pg_ts_config_map.mapcfg => pg_catalog.pg_ts_config.oid
Join pg_catalog.pg_ts_config_map.mapdict => pg_catalog.pg_ts_dict.oid
Join pg_catalog.pg_ts_dict.dictnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_ts_dict.dictowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_ts_dict.dicttemplate => pg_catalog.pg_ts_template.oid
Join pg_catalog.pg_ts_parser.prsnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_ts_parser.prsstart => pg_catalog.pg_proc.oid
Join pg_catalog.pg_ts_parser.prstoken => pg_catalog.pg_proc.oid
Join pg_catalog.pg_ts_parser.prsend => pg_catalog.pg_proc.oid
Join pg_catalog.pg_ts_parser.prsheadline => pg_catalog.pg_proc.oid
Join pg_catalog.pg_ts_parser.prslextype => pg_catalog.pg_proc.oid
Join pg_catalog.pg_ts_template.tmplnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_ts_template.tmplinit => pg_catalog.pg_proc.oid
Join pg_catalog.pg_ts_template.tmpllexize => pg_catalog.pg_proc.oid
Join pg_catalog.pg_type.typnamespace => pg_catalog.pg_namespace.oid
Join pg_catalog.pg_type.typowner => pg_catalog.pg_authid.oid
Join pg_catalog.pg_type.typrelid => pg_catalog.pg_class.oid
Join pg_catalog.pg_type.typelem => pg_catalog.pg_type.oid
Join pg_catalog.pg_type.typarray => pg_catalog.pg_type.oid
Join pg_catalog.pg_type.typinput => pg_catalog.pg_proc.oid
Join pg_catalog.pg_type.typoutput => pg_catalog.pg_proc.oid
Join pg_catalog.pg_type.typreceive => pg_catalog.pg_proc.oid
Join pg_catalog.pg_type.typsend => pg_catalog.pg_proc.oid
Join pg_catalog.pg_type.typmodin => pg_catalog.pg_proc.oid
Join pg_catalog.pg_type.typmodout => pg_catalog.pg_proc.oid
Join pg_catalog.pg_type.typanalyze => pg_catalog.pg_proc.oid
Join pg_catalog.pg_type.typbasetype => pg_catalog.pg_type.oid
Join pg_catalog.pg_type.typcollation => pg_catalog.pg_collation.oid
Join pg_catalog.pg_constraint.conpfeqop []=> pg_catalog.pg_operator.oid
Join pg_catalog.pg_constraint.conppeqop []=> pg_catalog.pg_operator.oid
Join pg_catalog.pg_constraint.conffeqop []=> pg_catalog.pg_operator.oid
Join pg_catalog.pg_constraint.conexclop []=> pg_catalog.pg_operator.oid
Join pg_catalog.pg_proc.proallargtypes []=> pg_catalog.pg_type.oid

---------------------------------------------------------------------------

Bruce Momjian (bruce@momjian.us)
Updated for 7.3 by Joe Conway (mail@joeconway.com)