From df38d799eafe03d5034234603f5c4b5a68914a6c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 18 Jul 2005 17:40:14 +0000 Subject: [PATCH] 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. --- src/bin/psql/describe.c | 56 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 603c709022..9903771185 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -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); -- 2.40.0