Commit df38d799 authored by Tom Lane's avatar Tom Lane

Adjust psql describe queries so that any pg_foo_is_visible() condition

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.
parent 24ce1438
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment