]> granicus.if.org Git - postgresql/commitdiff
Adjust psql describe queries so that any pg_foo_is_visible() condition
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 18 Jul 2005 17:40:14 +0000 (17:40 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 18 Jul 2005 17:40:14 +0000 (17:40 +0000)
is applied last, after other constraints such as name patterns.  This
is useful first because the pg_foo_is_visible() functions are relatively
expensive, and second because it minimizes the prospects for race
conditions.  The change is fragile though since it makes unwarranted
assumptions about planner behavior, ie, that WHERE clauses will be
executed in the original order if there's not reason to change it.
This should fix ... or at least hide ... an intermittent failure in the
prepared_xacts regression test, while we think about what else to do.

src/bin/psql/describe.c

index 603c709022631ded3e6fb3ca8ed38d1f35690783..9903771185fcb02fa2e8fc4e1593cc05b7daf58e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.120 2005/07/02 17:01:52 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.121 2005/07/18 17:40:14 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "describe.h"
@@ -421,7 +421,7 @@ permissionsList(const char *pattern)
         */
        processNamePattern(&buf, pattern, true, false,
                                           "n.nspname", "c.relname", NULL,
-               "pg_catalog.pg_table_is_visible(c.oid) AND n.nspname !~ '^pg_'");
+               "n.nspname !~ '^pg_' AND pg_catalog.pg_table_is_visible(c.oid)");
 
        appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
 
@@ -1913,6 +1913,32 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
        /*
         * Now decide what we need to emit.
         */
+       if (namebuf.len > 0)
+       {
+               /* We have a name pattern, so constrain the namevar(s) */
+
+               appendPQExpBufferChar(&namebuf, '$');
+               /* Optimize away ".*$", and possibly the whole pattern */
+               if (namebuf.len >= 3 &&
+                       strcmp(namebuf.data + (namebuf.len - 3), ".*$") == 0)
+                       namebuf.data[namebuf.len - 3] = '\0';
+
+               if (namebuf.data[0])
+               {
+                       WHEREAND();
+                       if (altnamevar)
+                               appendPQExpBuffer(buf,
+                                                                 "(%s ~ '^%s'\n"
+                                                                 "        OR %s ~ '^%s')\n",
+                                                                 namevar, namebuf.data,
+                                                                 altnamevar, namebuf.data);
+                       else
+                               appendPQExpBuffer(buf,
+                                                                 "%s ~ '^%s'\n",
+                                                                 namevar, namebuf.data);
+               }
+       }
+
        if (schemabuf.len > 0)
        {
                /* We have a schema pattern, so constrain the schemavar */
@@ -1940,32 +1966,6 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
                }
        }
 
-       if (namebuf.len > 0)
-       {
-               /* We have a name pattern, so constrain the namevar(s) */
-
-               appendPQExpBufferChar(&namebuf, '$');
-               /* Optimize away ".*$", and possibly the whole pattern */
-               if (namebuf.len >= 3 &&
-                       strcmp(namebuf.data + (namebuf.len - 3), ".*$") == 0)
-                       namebuf.data[namebuf.len - 3] = '\0';
-
-               if (namebuf.data[0])
-               {
-                       WHEREAND();
-                       if (altnamevar)
-                               appendPQExpBuffer(buf,
-                                                                 "(%s ~ '^%s'\n"
-                                                                 "        OR %s ~ '^%s')\n",
-                                                                 namevar, namebuf.data,
-                                                                 altnamevar, namebuf.data);
-                       else
-                               appendPQExpBuffer(buf,
-                                                                 "%s ~ '^%s'\n",
-                                                                 namevar, namebuf.data);
-               }
-       }
-
        termPQExpBuffer(&schemabuf);
        termPQExpBuffer(&namebuf);