Permalink
Browse files

Fix the queries used to get object comments to allow

for duplicate OIDs that may be present following use
of pg_upgrade.
  • Loading branch information...
1 parent 0d9af94 commit e33eab7fca30c1dc4cf90f03dfa83d98c5f1c2e0 @dpage dpage committed Dec 7, 2012
View
@@ -37,6 +37,9 @@ Changes
Date Dev Ver Change details
---------- --- ------ --------------
+2012-12-07 DP 1.16.2 Fix the queries used to get object comments to allow
+ for duplicate OIDs that may be present following use
+ of pg_upgrade.
2012-12-03 DP 1.16.1 Prevent a crash that could happen if further changes
were made on a dialogue after using the Apply button.
[Akshay Joshi]
@@ -243,7 +243,7 @@ pgObject *edbPackageFactory::CreateObjects(pgCollection *collection, ctlTree *br
sql = wxT("SELECT nsp.oid, nsp.xmin, nspname AS pkgname,\n") + pkgsrc +
wxT(" nspacl AS pkgacl, pg_get_userbyid(nspowner) AS owner, description\n")
wxT(" FROM pg_namespace nsp")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=nsp.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=nsp.oid AND des.classoid='pg_namespace'::regclass)\n")
+ whereclause
+ restriction +
wxT(" ORDER BY nspname;");
@@ -489,7 +489,7 @@ pgObject *gpExtTableFactory::CreateObjects(pgCollection *collection, ctlTree *br
pgSet *extTables = collection->GetDatabase()->ExecuteSet(
wxT("SELECT c.oid, c.xmin, c.relname, pg_get_userbyid(c.relowner) AS exttableowner, c.relacl AS relacl, description \n")
wxT(" FROM pg_class c\n")
- wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=c.oid and des.objsubid=0)\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=c.oid AND des.objsubid=0 AND des.classoid='pg_class'::regclass)\n")
wxT(" WHERE (c.relkind = 'x' OR (c.relkind = 'r' AND c.relstorage = 'x'))\n")
wxT(" AND relnamespace = ") + collection->GetSchema()->GetOidStr() + wxT("\n")
+ restriction
@@ -137,7 +137,7 @@ pgObject *gpPartitionFactory::CreateObjects(pgCollection *coll, ctlTree *browser
query += wxT(" FROM pg_class rel JOIN pg_partition_rule pr ON(rel.oid = pr.parchildrelid) JOIN pg_partition p ON (pr.paroid = p.oid)\n")
wxT(" JOIN pg_inherits i ON (rel.oid = i.inhrelid) \n")
wxT(" LEFT OUTER JOIN pg_tablespace ta on ta.oid=rel.reltablespace\n")
- wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=rel.oid AND des.objsubid=0)\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=rel.oid AND des.objsubid=0 AND des.classoid='pg_class'::regclass)\n")
wxT(" LEFT OUTER JOIN pg_constraint c ON c.conrelid=rel.oid AND c.contype='p'\n");
query += wxT(" LEFT OUTER JOIN gp_distribution_policy gpd ON gpd.localoid=rel.oid\n");
query += wxT(" WHERE relkind = 'r' ");
@@ -266,7 +266,7 @@ pgObject *pgAggregateFactory::CreateObjects(pgCollection *collection, ctlTree *b
wxT(" JOIN pg_proc pr ON pr.oid = ag.aggfnoid\n")
wxT(" JOIN pg_type tt on tt.oid=aggtranstype\n")
wxT(" JOIN pg_type tf on tf.oid=prorettype\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=aggfnoid::oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=aggfnoid::oid AND des.classoid='pg_aggregate'::regclass)\n")
wxT(" WHERE pronamespace = ") + collection->GetSchema()->GetOidStr()
+ restriction
+ wxT("\n ORDER BY aggname"));
@@ -172,7 +172,7 @@ pgObject *pgCastFactory::CreateObjects(pgCollection *collection, ctlTree *browse
wxT(" JOIN pg_namespace nt ON nt.oid=tt.typnamespace\n")
wxT(" LEFT JOIN pg_proc pr ON pr.oid=castfunc\n")
wxT(" LEFT JOIN pg_namespace np ON np.oid=pr.pronamespace\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=ca.oid AND des.objsubid=0\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=ca.oid AND des.objsubid=0 AND des.classoid='pg_cast'::regclass)\n")
+ restriction + systemRestriction +
wxT(" ORDER BY st.typname, tt.typname"));
@@ -115,7 +115,7 @@ pgObject *pgCatalogObjectFactory::CreateObjects(pgCollection *collection, ctlTre
wxString qry = wxT("SELECT c.oid, c.relname, pg_get_userbyid(relowner) AS owner, description\n")
wxT(" FROM pg_class c\n")
- wxT(" LEFT OUTER JOIN pg_description d ON d.objoid=c.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description d ON (d.objoid=c.oid AND d.classoid='pg_class'::regclass)\n")
wxT(" WHERE relnamespace = ") + NumToStr(collection->GetSchema()->GetOid()) + wxT("::oid\n");
qry += restriction +
@@ -213,7 +213,7 @@ pgObject *pgCheckFactory::CreateObjects(pgCollection *coll, ctlTree *browser, co
wxT(" FROM pg_constraint c\n")
wxT(" JOIN pg_class cl ON cl.oid=conrelid\n")
wxT(" JOIN pg_namespace nl ON nl.oid=relnamespace\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=c.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=c.oid AND des.classoid='pg_constraint'::regclass)\n")
wxT(" WHERE contype = 'c' AND conrelid = ") + NumToStr(collection->GetOid())
+ restriction + wxT("::oid\n")
wxT("UNION\n")
@@ -223,7 +223,7 @@ pgObject *pgCheckFactory::CreateObjects(pgCollection *coll, ctlTree *browser, co
wxT(" FROM pg_constraint c\n")
wxT(" JOIN pg_type t ON t.oid=contypid\n")
wxT(" JOIN pg_namespace nl ON nl.oid=typnamespace\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=t.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=t.oid AND des.classoid='pg_constraint'::regclass)\n")
wxT(" WHERE contype = 'c' AND contypid = ") + NumToStr(collection->GetOid())
+ restriction + wxT("::oid\n")
wxT(" ORDER BY conname");
@@ -169,7 +169,7 @@ pgObject *pgCollationFactory::CreateObjects(pgCollection *collection, ctlTree *b
wxT(" pg_get_userbyid(c.collowner) as cowner, description\n")
wxT(" FROM pg_collation c\n")
wxT(" JOIN pg_namespace n ON n.oid=c.collnamespace\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=c.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=c.oid AND des.classoid='pg_collation'::regclass)\n")
wxT(" WHERE c.collnamespace = ") + NumToStr(collection->GetSchema()->GetOid()) + wxT("::oid\n")
+ restriction +
wxT(" ORDER BY c.collname"));
View
2 pgadmin/schema/pgColumn.cpp 100755 → 100644
@@ -585,7 +585,7 @@ pgObject *pgColumnFactory::CreateObjects(pgCollection *coll, ctlTree *browser, c
wxT(" JOIN pg_namespace na ON na.oid=cl.relnamespace\n")
wxT(" LEFT OUTER JOIN pg_type et ON et.oid=ty.typelem\n")
wxT(" LEFT OUTER JOIN pg_attrdef def ON adrelid=att.attrelid AND adnum=att.attnum\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=att.attrelid AND des.objsubid=att.attnum\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=att.attrelid AND des.objsubid=att.attnum AND des.classoid='pg_attribute'::regclass)\n")
wxT(" LEFT OUTER JOIN (pg_depend JOIN pg_class cs ON objid=cs.oid AND cs.relkind='S') ON refobjid=att.attrelid AND refobjsubid=att.attnum\n")
wxT(" LEFT OUTER JOIN pg_namespace ns ON ns.oid=cs.relnamespace\n")
wxT(" LEFT OUTER JOIN pg_index pi ON pi.indrelid=att.attrelid AND indisprimary\n");
@@ -162,7 +162,7 @@ pgObject *pgConversionFactory::CreateObjects(pgCollection *collection, ctlTree *
wxT(" FROM pg_conversion co\n")
wxT(" JOIN pg_proc pr ON pr.oid=conproc\n")
wxT(" JOIN pg_namespace na ON na.oid=pr.pronamespace\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=co.oid AND des.objsubid=0\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=co.oid AND des.objsubid=0 AND des.classoid='pg_conversion'::regclass)\n")
wxT(" WHERE connamespace = ") + collection->GetSchema()->GetOidStr()
+ restriction + wxT("\n")
wxT(" ORDER BY conname"));
@@ -831,7 +831,7 @@ pgObject *pgDatabaseFactory::CreateObjects(pgCollection *collection, ctlTree *br
datconnlimit + datcollate + datctype + seclabelsql +
wxT(" FROM pg_database db\n")
wxT(" LEFT OUTER JOIN pg_tablespace ta ON db.dattablespace=ta.OID\n")
- wxT(" LEFT OUTER JOIN pg_shdescription descr ON (db.oid=descr.objoid AND descr.objoid='pg_database'::regclass)\n")
+ wxT(" LEFT OUTER JOIN pg_shdescription descr ON (db.oid=descr.objoid AND descr.classoid='pg_database'::regclass)\n")
+ restr +
wxT(" ORDER BY datname"));
}
@@ -847,7 +847,7 @@ pgObject *pgDatabaseFactory::CreateObjects(pgCollection *collection, ctlTree *br
wxT(" LEFT OUTER JOIN pg_tablespace ta ON db.dattablespace=ta.OID\n")
wxT(" LEFT OUTER JOIN ")
+ wxString(collection->GetConnection()->BackendMinimumVersion(8, 2) ? wxT("pg_shdescription") : wxT("pg_description")) +
- wxT(" descr ON db.oid=descr.objoid\n")
+ wxT(" descr ON (db.oid=descr.objoid AND descr.classoid='pg_database'::regclass)\n")
+ restr +
wxT(" ORDER BY datname"));
else
@@ -857,7 +857,7 @@ pgObject *pgDatabaseFactory::CreateObjects(pgCollection *collection, ctlTree *br
wxT("has_database_privilege(db.oid, 'CREATE') as cancreate,\n")
wxT("descr.description\n")
wxT(" FROM pg_database db\n")
- wxT(" LEFT OUTER JOIN pg_description descr ON db.oid=descr.objoid\n")
+ wxT(" LEFT OUTER JOIN pg_description descr ON (db.oid=descr.objoid AND descr.classoid='pg_database'::regclass)\n")
+ restr +
wxT(" ORDER BY datname"));
@@ -273,7 +273,7 @@ pgObject *pgDomainFactory::CreateObjects(pgCollection *collection, ctlTree *brow
sql += wxT("\n FROM pg_type d\n")
wxT(" JOIN pg_type b ON b.oid = d.typbasetype\n")
wxT(" JOIN pg_namespace bn ON bn.oid=b.typnamespace\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=d.oid\n");
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=d.oid AND des.classoid='pg_type'::regclass)\n");
if (collection->GetDatabase()->BackendMinimumVersion(9, 1))
sql += wxT(" LEFT OUTER JOIN pg_collation c ON d.typcollation=c.oid\n")
wxT(" LEFT OUTER JOIN pg_namespace cn ON c.collnamespace=cn.oid\n");
@@ -200,7 +200,7 @@ pgObject *pgForeignDataWrapperFactory::CreateObjects(pgCollection *collection, c
sql += wxT(" FROM pg_foreign_data_wrapper fdw\n")
wxT(" LEFT OUTER JOIN pg_proc vh on vh.oid=fdwhandler\n")
wxT(" LEFT OUTER JOIN pg_proc vp on vp.oid=fdwvalidator\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=fdw.oid AND des.objsubid=0\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=fdw.oid AND des.objsubid=0 AND des.classoid='pg_foreign_data_wrapper'::regclass)\n")
+ restriction + wxT("\n")
wxT(" ORDER BY fdwname");
}
@@ -213,7 +213,7 @@ pgObject *pgForeignDataWrapperFactory::CreateObjects(pgCollection *collection, c
wxT("pg_get_userbyid(fdwowner) as fdwowner\n");
sql += wxT(" FROM pg_foreign_data_wrapper fdw\n")
wxT(" LEFT OUTER JOIN pg_proc vp on vp.oid=fdwvalidator\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=fdw.oid AND des.objsubid=0\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=fdw.oid AND des.objsubid=0 AND des.classoid='pg_foreign_data_wrapper'::regclass)\n")
+ restriction + wxT("\n")
wxT(" ORDER BY fdwname");
}
@@ -295,7 +295,7 @@ pgObject *pgForeignKeyFactory::CreateObjects(pgCollection *coll, ctlTree *browse
wxT(" JOIN pg_namespace nl ON nl.oid=cl.relnamespace\n")
wxT(" JOIN pg_class cr ON cr.oid=confrelid\n")
wxT(" JOIN pg_namespace nr ON nr.oid=cr.relnamespace\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=ct.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=ct.oid AND des.classoid='pg_constraint'::regclass)\n")
wxT(" WHERE contype='f' AND conrelid = ") + collection->GetOidStr()
+ restriction + wxT("\n")
wxT(" ORDER BY conname");
@@ -196,7 +196,7 @@ pgObject *pgForeignServerFactory::CreateObjects(pgCollection *collection, ctlTre
wxT("pg_get_userbyid(srvowner) as srvowner\n")
wxT(" FROM pg_foreign_server srv\n")
wxT(" LEFT OUTER JOIN pg_foreign_data_wrapper fdw on fdw.oid=srvfdw\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=srv.oid AND des.objsubid=0\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=srv.oid AND des.objsubid=0 AND des.classoid='pg_foreign_server'::regclass)\n")
wxT(" WHERE srvfdw = ") + collection->GetOidStr()
+ restriction + wxT("\n")
wxT(" ORDER BY srvname");
@@ -360,7 +360,7 @@ pgObject *pgForeignTableFactory::CreateObjects(pgCollection *collection, ctlTree
wxT(" FROM pg_class c\n")
wxT(" JOIN pg_foreign_table ft ON c.oid=ft.ftrelid\n")
wxT(" LEFT OUTER JOIN pg_foreign_server fs ON ft.ftserver=fs.oid\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=c.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=c.oid AND des.classoid='pg_class'::regclass)\n")
wxT(" WHERE c.relnamespace = ") + collection->GetSchema()->GetOidStr() + wxT("\n")
+ restriction +
wxT(" ORDER BY c.relname");
@@ -659,7 +659,7 @@ pgFunction *pgFunctionFactory::AppendFunctions(pgObject *obj, pgSchema *schema,
wxT(" JOIN pg_type typ ON typ.oid=prorettype\n")
wxT(" JOIN pg_namespace typns ON typns.oid=typ.typnamespace\n")
wxT(" JOIN pg_language lng ON lng.oid=prolang\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=pr.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=pr.oid AND des.classoid='pg_proc'::regclass)\n")
+ restriction +
wxT(" ORDER BY proname"));
@@ -552,8 +552,8 @@ pgObject *pgIndexBaseFactory::CreateObjects(pgCollection *coll, ctlTree *browser
wxT(" JOIN pg_am am ON am.oid=cls.relam\n")
wxT(" LEFT JOIN pg_depend dep ON (dep.classid = cls.tableoid AND dep.objid = cls.oid AND dep.refobjsubid = '0' AND dep.refclassid=(SELECT oid FROM pg_class WHERE relname='pg_constraint') AND dep.deptype='i')\n")
wxT(" LEFT OUTER JOIN pg_constraint con ON (con.tableoid = dep.refclassid AND con.oid = dep.refobjid)\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=cls.oid\n")
- wxT(" LEFT OUTER JOIN pg_description desp ON (desp.objoid=con.oid AND desp.objsubid = 0)\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=cls.oid AND des.classoid='pg_class'::regclass)\n")
+ wxT(" LEFT OUTER JOIN pg_description desp ON (desp.objoid=con.oid AND desp.objsubid = 0 AND des.classoid='pg_constraint'::regclass)\n")
wxT(" WHERE indrelid = ") + collection->GetOidStr()
+ restriction + wxT("\n")
wxT(" ORDER BY cls.relname");
@@ -184,7 +184,7 @@ pgObject *pgLanguageFactory::CreateObjects(pgCollection *collection, ctlTree *br
if (collection->GetConnection()->BackendMinimumVersion(9, 0))
sql += wxT(" LEFT OUTER JOIN pg_proc ip on ip.oid=laninline\n");
sql += wxT(" LEFT OUTER JOIN pg_proc vp on vp.oid=lanvalidator\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=lan.oid AND des.objsubid=0\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=lan.oid AND des.objsubid=0 AND des.classoid='pg_language'::regclass)\n")
wxT(" WHERE lanispl IS TRUE")
+ restriction + wxT("\n")
wxT(" ORDER BY lanname");
@@ -271,7 +271,7 @@ pgObject *pgOperatorFactory::CreateObjects(pgCollection *collection, ctlTree *br
wxT(" JOIN pg_type et on et.oid=op.oprresult\n")
wxT(" LEFT OUTER JOIN pg_operator co ON co.oid=op.oprcom\n")
wxT(" LEFT OUTER JOIN pg_operator ne ON ne.oid=op.oprnegate\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=op.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=op.oid AND des.classoid='pg_operator'::regclass)\n")
wxT(" WHERE op.oprnamespace = ") + collection->GetSchema()->GetOidStr()
+ restriction + wxT("\n")
wxT(" ORDER BY op.oprname"));
@@ -294,7 +294,7 @@ pgObject *pgOperatorFactory::CreateObjects(pgCollection *collection, ctlTree *br
wxT(" LEFT OUTER JOIN pg_operator rso ON rso.oid=op.oprrsortop\n")
wxT(" LEFT OUTER JOIN pg_operator lco ON lco.oid=op.oprltcmpop\n")
wxT(" LEFT OUTER JOIN pg_operator gco ON gco.oid=op.oprgtcmpop\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=op.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=op.oid AND des.classoid='pg_operator'::regclass)\n")
wxT(" WHERE op.oprnamespace = ") + collection->GetSchema()->GetOidStr()
+ restriction + wxT("\n")
wxT(" ORDER BY op.oprname"));
@@ -208,7 +208,7 @@ pgObject *pgRuleFactory::CreateObjects(pgCollection *collection, ctlTree *browse
wxT(" FROM pg_rewrite rw\n")
wxT(" JOIN pg_class cl ON cl.oid=rw.ev_class\n")
wxT(" JOIN pg_namespace nsp ON nsp.oid=cl.relnamespace\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=rw.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=rw.oid AND des.classoid='pg_rewrite'::regclass)\n")
wxT(" WHERE ev_class = ") + NumToStr(collection->GetOid())
+ restriction + wxT("\n")
wxT(" ORDER BY rw.rulename"));
@@ -512,7 +512,7 @@ pgObject *pgSchemaBaseFactory::CreateObjects(pgCollection *collection, ctlTree *
wxT(" nsp.nspname, nsp.oid, pg_get_userbyid(nspowner) AS namespaceowner, nspacl, description,")
wxT(" FALSE as cancreate\n")
wxT(" FROM pg_namespace nsp\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=nsp.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=nsp.oid AND des.classoid='pg_namespace'::regclass)\n")
+ restr +
wxT(" ORDER BY 1, nspname");
}
@@ -537,7 +537,7 @@ pgObject *pgSchemaBaseFactory::CreateObjects(pgCollection *collection, ctlTree *
sql += wxT(",\n(SELECT array_agg(provider) FROM pg_seclabels sl2 WHERE sl2.objoid=nsp.oid) AS providers");
}
sql += wxT("\n FROM pg_namespace nsp\n")
- wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=nsp.oid\n")
+ wxT(" LEFT OUTER JOIN pg_description des ON (des.objoid=nsp.oid AND des.classoid='pg_namespace'::regclass)\n")
+ restr +
wxT(" ORDER BY 1, nspname");
}
Oops, something went wrong.

0 comments on commit e33eab7

Please sign in to comment.