Optimise the pgDatatype population query [Greg Stark]
authordpage <dpage@a7884b65-44f6-0310-8a51-81a127f17b15>
Tue, 12 May 2009 15:03:39 +0000 (15:03 +0000)
committerdpage <dpage@a7884b65-44f6-0310-8a51-81a127f17b15>
Tue, 12 May 2009 15:03:39 +0000 (15:03 +0000)
git-svn-id: svn://svn.pgadmin.org/trunk/pgadmin3@7864 a7884b65-44f6-0310-8a51-81a127f17b15

pgadmin/schema/pgDatatype.cpp

index 0c42c477a3df305af25441c74513376c4a2fc3cd..d296b8d07c3feda31cdd380341d02394423a2b81 100644 (file)
@@ -180,10 +180,10 @@ DatatypeReader::DatatypeReader(pgDatabase *db, bool withDomains)
     else
         condition += wxT("IN ('b', 'c', 'e')");
 
-    condition += wxT("AND typname NOT IN (SELECT relname FROM pg_class WHERE relnamespace = typnamespace AND relkind != 'c' UNION SELECT '_' || relname FROM pg_class WHERE relnamespace = typnamespace AND relkind != 'c') ");
+    condition += wxT("AND NOT EXISTS (select 1 from pg_class where relnamespace=typnamespace and relname = typname and relkind != 'c') AND (typname not like '_%' OR NOT EXISTS (select 1 from pg_class where relnamespace=typnamespace and relname = substring(typname from 2)::name and relkind != 'c')) ");
 
     if (!settings->GetShowSystemObjects())
-        condition += wxT(" AND nsp.nspname NOT LIKE 'information_schema'");
+        condition += wxT(" AND nsp.nspname != 'information_schema'");
     init(db, condition);
 }
 
@@ -196,7 +196,7 @@ void DatatypeReader::init(pgDatabase *db, const wxString &condition)
         wxT("  FROM pg_type t\n")
         wxT("  JOIN pg_namespace nsp ON typnamespace=nsp.oid\n")
         wxT(" WHERE (NOT (typname = 'unknown' AND nspname = 'pg_catalog')) AND ") + condition + wxT("\n")
-        wxT(" ORDER BY CASE WHEN typtype='d' THEN 0 ELSE 1 END, (t.typelem>0)::bool, 1"));
+        wxT("  ORDER BY typtype != 'd', t.typelem > 0, 1"));
 }