diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-03-11 04:36:43 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-03-11 04:36:43 +0000 |
commit | e6555b436e44fc43f14b3d8c1f782fbd3924485d (patch) | |
tree | d25247408f1af6952d2ee97ba38cbe1ad710839a /src/bin/psql/describe.c | |
parent | 4df5c6c7195cf9382d249d6371d2c8e02d46a7ae (diff) | |
download | postgresql-e6555b436e44fc43f14b3d8c1f782fbd3924485d.tar.gz postgresql-e6555b436e44fc43f14b3d8c1f782fbd3924485d.zip |
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.
Diffstat (limited to 'src/bin/psql/describe.c')
-rw-r--r-- | src/bin/psql/describe.c | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index a6fa883c47b..d1610e21393 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -8,7 +8,7 @@ * * 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" @@ -1417,21 +1417,17 @@ describeOneTableDetails(const char *schemaname, if (pset.sversion >= 90000) appendPQExpBuffer(&buf, " (NOT i.indimmediate) AND " - "EXISTS (SELECT 1 FROM pg_catalog.pg_depend d, " - "pg_catalog.pg_constraint con WHERE " - "d.classid = 'pg_catalog.pg_class'::pg_catalog.regclass AND " - "d.objid = i.indexrelid AND " - "d.refclassid = 'pg_catalog.pg_constraint'::pg_catalog.regclass AND " - "d.refobjid = con.oid AND d.deptype = 'i' AND " - "con.condeferrable) AS condeferrable,\n" + "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint " + "WHERE conrelid = i.indrelid AND " + "conindid = i.indexrelid AND " + "contype IN ('p','u','x') AND " + "condeferrable) AS condeferrable,\n" " (NOT i.indimmediate) AND " - "EXISTS (SELECT 1 FROM pg_catalog.pg_depend d, " - "pg_catalog.pg_constraint con WHERE " - "d.classid = 'pg_catalog.pg_class'::pg_catalog.regclass AND " - "d.objid = i.indexrelid AND " - "d.refclassid = 'pg_catalog.pg_constraint'::pg_catalog.regclass AND " - "d.refobjid = con.oid AND d.deptype = 'i' AND " - "con.condeferred) AS condeferred,\n"); + "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint " + "WHERE conrelid = i.indrelid AND " + "conindid = i.indexrelid AND " + "contype IN ('p','u','x') AND " + "condeferred) AS condeferred,\n"); else appendPQExpBuffer(&buf, " false AS condeferrable, false AS condeferred,\n"); @@ -1553,21 +1549,17 @@ describeOneTableDetails(const char *schemaname, if (pset.sversion >= 90000) appendPQExpBuffer(&buf, ",\n (NOT i.indimmediate) AND " - "EXISTS (SELECT 1 FROM pg_catalog.pg_depend d, " - "pg_catalog.pg_constraint con WHERE " - "d.classid = 'pg_catalog.pg_class'::pg_catalog.regclass AND " - "d.objid = i.indexrelid AND " - "d.refclassid = 'pg_catalog.pg_constraint'::pg_catalog.regclass AND " - "d.refobjid = con.oid AND d.deptype = 'i' AND " - "con.condeferrable) AS condeferrable" + "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint " + "WHERE conrelid = i.indrelid AND " + "conindid = i.indexrelid AND " + "contype IN ('p','u','x') AND " + "condeferrable) AS condeferrable" ",\n (NOT i.indimmediate) AND " - "EXISTS (SELECT 1 FROM pg_catalog.pg_depend d, " - "pg_catalog.pg_constraint con WHERE " - "d.classid = 'pg_catalog.pg_class'::pg_catalog.regclass AND " - "d.objid = i.indexrelid AND " - "d.refclassid = 'pg_catalog.pg_constraint'::pg_catalog.regclass AND " - "d.refobjid = con.oid AND d.deptype = 'i' AND " - "con.condeferred) AS condeferred"); + "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint " + "WHERE conrelid = i.indrelid AND " + "conindid = i.indexrelid AND " + "contype IN ('p','u','x') AND " + "condeferred) AS condeferred"); else appendPQExpBuffer(&buf, ", false AS condeferrable, false AS condeferred"); if (pset.sversion >= 80000) |