@@ -546,6 +546,28 @@ describeFunctions(const char *functypes, const char *func_pattern,
546546 appendPQExpBufferStr (& buf , " )\n" );
547547 }
548548
549+ /*
550+ * Use p.pronamespace here, rather than n.nspname, so that the
551+ * system schemas can be filtered during the pg_proc scan, before calling
552+ * pg_function_is_visible(). The latter can populate catalog caches for
553+ * every function it examines. The ARRAY subquery becomes an InitPlan and
554+ * quietly ignores either schema if it does not exist.
555+ */
556+ if (!showSystem && !func_pattern )
557+ {
558+ if (have_where )
559+ appendPQExpBufferStr (& buf , " AND " );
560+ else
561+ {
562+ appendPQExpBufferStr (& buf , "WHERE " );
563+ have_where = true;
564+ }
565+ appendPQExpBufferStr (& buf ,
566+ "p.pronamespace <> ALL (ARRAY(\n"
567+ " SELECT oid FROM pg_catalog.pg_namespace\n"
568+ " WHERE nspname IN ('pg_catalog', 'information_schema')))\n" );
569+ }
570+
549571 if (!validateSQLNamePattern (& buf , func_pattern , have_where , false,
550572 "n.nspname" , "p.proname" , NULL ,
551573 "pg_catalog.pg_function_is_visible(p.oid)" ,
@@ -586,10 +608,6 @@ describeFunctions(const char *functypes, const char *func_pattern,
586608 }
587609 }
588610
589- if (!showSystem && !func_pattern )
590- appendPQExpBufferStr (& buf , " AND n.nspname <> 'pg_catalog'\n"
591- " AND n.nspname <> 'information_schema'\n" );
592-
593611 appendPQExpBufferStr (& buf , "ORDER BY 1, 2, 4;" );
594612
595613 res = PSQLexec (buf .data );
0 commit comments