On Wed, Apr 28, 2021 at 7:56 PM Tom Lane <t...@sss.pgh.pa.us> wrote: > > Greg Stark <st...@mit.edu> writes: > >> On Tue, Apr 27, 2021 at 7:08 PM Bharath Rupireddy > >> <bharath.rupireddyforpostgres@gmail > >> Make sense, we would lose the ability to differentiate temporary > >> tables from the auto_explain logs. > > > There's no useful differentiation that can be done with the temp > > schema name. > I see.
> Agreed. > > > I would say it makes sense to remove them -- except perhaps it makes > > it harder to parse explain output. > > I don't think we should remove them. However, it could make sense to > print the "pg_temp" alias instead of the real schema name when we > are talking about myTempNamespace. Basically try to make that alias > a bit less leaky. +1, let's replace it by "pg_temp" -- did the same in that attached 0001 patch. Also, I am wondering if we need a similar kind of handling in psql '\d' meta-command as well? I did trial changes in the 0002 patch, but I am not very sure about it & a bit skeptical for code change as well. Do let me know if you have any suggestions/thoughts or if we don't want to, so please ignore that patch, thanks. Regards, Amul
From 4d0556ae5395f3e28fe9616c51ea971f63d6a927 Mon Sep 17 00:00:00 2001 From: Amul Sul <amul.sul@enterprisedb.com> Date: Thu, 29 Apr 2021 02:15:37 -0400 Subject: [PATCH 2/2] WIP-POC-PSQL-change temp table description --- src/bin/psql/describe.c | 13 +++++++++++++ src/fe_utils/string_utils.c | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 3e39fdb5452..ea27f09b8a9 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -1584,6 +1584,15 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem) nspname = PQgetvalue(res, i, 1); relname = PQgetvalue(res, i, 2); + /* Replace internal temp schema name */ + if (pset.sversion >= 140000) + { + if (strncmp(nspname, "pg_temp_", 8) == 0) + nspname = "pg_temp"; + else if (strncmp(nspname, "pg_toast_temp_", 14) == 0) + nspname = "pg_toast_temp"; + } + if (!describeOneTableDetails(nspname, relname, oid, verbose)) { PQclear(res); @@ -2396,6 +2405,10 @@ describeOneTableDetails(const char *schemaname, char *schemaname = PQgetvalue(result, 0, 0); char *relname = PQgetvalue(result, 0, 1); + /* Replace internal temporary schema name */ + if (strncmp(schemaname, "pg_temp_", 8) == 0) + schemaname = "pg_temp"; + printfPQExpBuffer(&tmpbuf, _("Owning table: \"%s.%s\""), schemaname, relname); printTableAddFooter(&cont, tmpbuf.data); diff --git a/src/fe_utils/string_utils.c b/src/fe_utils/string_utils.c index 5b206c7481d..67c7a883b33 100644 --- a/src/fe_utils/string_utils.c +++ b/src/fe_utils/string_utils.c @@ -913,6 +913,14 @@ processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, { WHEREAND(); appendPQExpBuffer(buf, "%s OPERATOR(pg_catalog.~) ", schemavar); + + /* + * Internal temporary schema name could be different, strip out "$" + * from pattern to relax the match. + */ + if (strcmp(schemabuf.data, "^(pg_temp)$") == 0 || + strcmp(schemabuf.data, "^(pg_toast_temp)$") == 0) + schemabuf.data[schemabuf.len-1] = '\0'; appendStringLiteralConn(buf, schemabuf.data, conn); if (PQserverVersion(conn) >= 120000) appendPQExpBufferStr(buf, " COLLATE pg_catalog.default"); -- 2.18.0
From 39260208613fe1d8613cd90d6766859fb6104f56 Mon Sep 17 00:00:00 2001 From: Amul Sul <amul.sul@enterprisedb.com> Date: Thu, 29 Apr 2021 01:00:06 -0400 Subject: [PATCH 1/2] Hide internal temp schema name --- contrib/postgres_fdw/postgres_fdw.c | 4 +++- src/backend/commands/explain.c | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index e201b5404e6..80cd4334b1e 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -2794,9 +2794,11 @@ postgresExplainForeignScan(ForeignScanState *node, ExplainState *es) relname = get_rel_name(rte->relid); if (es->verbose) { + Oid namespaceOid; char *namespace; - namespace = get_namespace_name(get_rel_namespace(rte->relid)); + namespaceOid = get_rel_namespace(rte->relid); + namespace = get_namespace_name_or_temp(namespaceOid); appendStringInfo(relations, "%s.%s", quote_identifier(namespace), quote_identifier(relname)); diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index 3d5198e2345..16f2bf04026 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -3747,7 +3747,8 @@ ExplainTargetRel(Plan *plan, Index rti, ExplainState *es) Assert(rte->rtekind == RTE_RELATION); objectname = get_rel_name(rte->relid); if (es->verbose) - namespace = get_namespace_name(get_rel_namespace(rte->relid)); + namespace = + get_namespace_name_or_temp(get_rel_namespace(rte->relid)); objecttag = "Relation Name"; break; case T_FunctionScan: @@ -3775,7 +3776,7 @@ ExplainTargetRel(Plan *plan, Index rti, ExplainState *es) objectname = get_func_name(funcid); if (es->verbose) namespace = - get_namespace_name(get_func_namespace(funcid)); + get_namespace_name_or_temp(get_func_namespace(funcid)); } } objecttag = "Function Name"; -- 2.18.0