Simplify a couple of pg_dump and psql \d queries about index constraints
by joining to pg_constraint.conindid, instead of the former technique of joining indirectly through pg_depend. This is much more straightforward and probably faster as well. I had originally desisted from changing these queries when conindid was added because I was worried about losing performance, but if we join on conrelid as well as conindid then the index on conrelid can be used when pg_constraint is large.
This commit is contained in:
parent
4df5c6c719
commit
e6555b436e
@ -25,7 +25,7 @@
|
|||||||
* http://archives.postgresql.org/pgsql-bugs/2010-02/msg00187.php
|
* http://archives.postgresql.org/pgsql-bugs/2010-02/msg00187.php
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.577 2010/03/03 23:38:44 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.578 2010/03/11 04:36:43 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -3956,6 +3956,11 @@ getIndexes(TableInfo tblinfo[], int numTables)
|
|||||||
* that is related by an internal dependency link to the index. If we
|
* that is related by an internal dependency link to the index. If we
|
||||||
* find one, create a CONSTRAINT entry linked to the INDEX entry. We
|
* find one, create a CONSTRAINT entry linked to the INDEX entry. We
|
||||||
* assume an index won't have more than one internal dependency.
|
* assume an index won't have more than one internal dependency.
|
||||||
|
*
|
||||||
|
* As of 9.0 we don't need to look at pg_depend but can check for
|
||||||
|
* a match to pg_constraint.conindid. The check on conrelid is
|
||||||
|
* redundant but useful because that column is indexed while conindid
|
||||||
|
* is not.
|
||||||
*/
|
*/
|
||||||
resetPQExpBuffer(query);
|
resetPQExpBuffer(query);
|
||||||
if (g_fout->remoteVersion >= 90000)
|
if (g_fout->remoteVersion >= 90000)
|
||||||
@ -3975,13 +3980,10 @@ getIndexes(TableInfo tblinfo[], int numTables)
|
|||||||
"array_to_string(t.reloptions, ', ') AS options "
|
"array_to_string(t.reloptions, ', ') AS options "
|
||||||
"FROM pg_catalog.pg_index i "
|
"FROM pg_catalog.pg_index i "
|
||||||
"JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
|
"JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
|
||||||
"LEFT JOIN pg_catalog.pg_depend d "
|
|
||||||
"ON (d.classid = t.tableoid "
|
|
||||||
"AND d.objid = t.oid "
|
|
||||||
"AND d.deptype = 'i') "
|
|
||||||
"LEFT JOIN pg_catalog.pg_constraint c "
|
"LEFT JOIN pg_catalog.pg_constraint c "
|
||||||
"ON (d.refclassid = c.tableoid "
|
"ON (i.indrelid = c.conrelid AND "
|
||||||
"AND d.refobjid = c.oid) "
|
"i.indexrelid = c.conindid AND "
|
||||||
|
"c.contype IN ('p','u','x')) "
|
||||||
"WHERE i.indrelid = '%u'::pg_catalog.oid "
|
"WHERE i.indrelid = '%u'::pg_catalog.oid "
|
||||||
"ORDER BY indexname",
|
"ORDER BY indexname",
|
||||||
tbinfo->dobj.catId.oid);
|
tbinfo->dobj.catId.oid);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.239 2010/03/01 20:55:45 heikki Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.240 2010/03/11 04:36:43 tgl Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
@ -1417,21 +1417,17 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
if (pset.sversion >= 90000)
|
if (pset.sversion >= 90000)
|
||||||
appendPQExpBuffer(&buf,
|
appendPQExpBuffer(&buf,
|
||||||
" (NOT i.indimmediate) AND "
|
" (NOT i.indimmediate) AND "
|
||||||
"EXISTS (SELECT 1 FROM pg_catalog.pg_depend d, "
|
"EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
|
||||||
"pg_catalog.pg_constraint con WHERE "
|
"WHERE conrelid = i.indrelid AND "
|
||||||
"d.classid = 'pg_catalog.pg_class'::pg_catalog.regclass AND "
|
"conindid = i.indexrelid AND "
|
||||||
"d.objid = i.indexrelid AND "
|
"contype IN ('p','u','x') AND "
|
||||||
"d.refclassid = 'pg_catalog.pg_constraint'::pg_catalog.regclass AND "
|
"condeferrable) AS condeferrable,\n"
|
||||||
"d.refobjid = con.oid AND d.deptype = 'i' AND "
|
|
||||||
"con.condeferrable) AS condeferrable,\n"
|
|
||||||
" (NOT i.indimmediate) AND "
|
" (NOT i.indimmediate) AND "
|
||||||
"EXISTS (SELECT 1 FROM pg_catalog.pg_depend d, "
|
"EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
|
||||||
"pg_catalog.pg_constraint con WHERE "
|
"WHERE conrelid = i.indrelid AND "
|
||||||
"d.classid = 'pg_catalog.pg_class'::pg_catalog.regclass AND "
|
"conindid = i.indexrelid AND "
|
||||||
"d.objid = i.indexrelid AND "
|
"contype IN ('p','u','x') AND "
|
||||||
"d.refclassid = 'pg_catalog.pg_constraint'::pg_catalog.regclass AND "
|
"condeferred) AS condeferred,\n");
|
||||||
"d.refobjid = con.oid AND d.deptype = 'i' AND "
|
|
||||||
"con.condeferred) AS condeferred,\n");
|
|
||||||
else
|
else
|
||||||
appendPQExpBuffer(&buf,
|
appendPQExpBuffer(&buf,
|
||||||
" false AS condeferrable, false AS condeferred,\n");
|
" false AS condeferrable, false AS condeferred,\n");
|
||||||
@ -1553,21 +1549,17 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
if (pset.sversion >= 90000)
|
if (pset.sversion >= 90000)
|
||||||
appendPQExpBuffer(&buf,
|
appendPQExpBuffer(&buf,
|
||||||
",\n (NOT i.indimmediate) AND "
|
",\n (NOT i.indimmediate) AND "
|
||||||
"EXISTS (SELECT 1 FROM pg_catalog.pg_depend d, "
|
"EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
|
||||||
"pg_catalog.pg_constraint con WHERE "
|
"WHERE conrelid = i.indrelid AND "
|
||||||
"d.classid = 'pg_catalog.pg_class'::pg_catalog.regclass AND "
|
"conindid = i.indexrelid AND "
|
||||||
"d.objid = i.indexrelid AND "
|
"contype IN ('p','u','x') AND "
|
||||||
"d.refclassid = 'pg_catalog.pg_constraint'::pg_catalog.regclass AND "
|
"condeferrable) AS condeferrable"
|
||||||
"d.refobjid = con.oid AND d.deptype = 'i' AND "
|
|
||||||
"con.condeferrable) AS condeferrable"
|
|
||||||
",\n (NOT i.indimmediate) AND "
|
",\n (NOT i.indimmediate) AND "
|
||||||
"EXISTS (SELECT 1 FROM pg_catalog.pg_depend d, "
|
"EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
|
||||||
"pg_catalog.pg_constraint con WHERE "
|
"WHERE conrelid = i.indrelid AND "
|
||||||
"d.classid = 'pg_catalog.pg_class'::pg_catalog.regclass AND "
|
"conindid = i.indexrelid AND "
|
||||||
"d.objid = i.indexrelid AND "
|
"contype IN ('p','u','x') AND "
|
||||||
"d.refclassid = 'pg_catalog.pg_constraint'::pg_catalog.regclass AND "
|
"condeferred) AS condeferred");
|
||||||
"d.refobjid = con.oid AND d.deptype = 'i' AND "
|
|
||||||
"con.condeferred) AS condeferred");
|
|
||||||
else
|
else
|
||||||
appendPQExpBuffer(&buf, ", false AS condeferrable, false AS condeferred");
|
appendPQExpBuffer(&buf, ", false AS condeferrable, false AS condeferred");
|
||||||
if (pset.sversion >= 80000)
|
if (pset.sversion >= 80000)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user