Fix issues with describe queries of extended statistics in psql

This addresses some problems in the describe queries used for extended
statistics:
- Two schema qualifications for the text type were missing for \dX.
- The list of extended statistics listed for a table through \d was
ordered based on the object OIDs, but it is more consistent with the
other commands to order by namespace and then by object name.
- A couple of aliases were not used in \d.  These are removed.

This is similar to commits 1f092a3 and 07f8a9e.

Author: Justin Pryzby
Discussion: https://postgr.es/m/20220107022235.GA14051@telsasoft.com
Backpatch-through: 14
This commit is contained in:
Michael Paquier 2022-01-08 16:44:45 +09:00
parent a2ab9c06ea
commit fe594abf7c

View File

@ -2608,16 +2608,16 @@ describeOneTableDetails(const char *schemaname,
printfPQExpBuffer(&buf,
"SELECT oid, "
"stxrelid::pg_catalog.regclass, "
"stxnamespace::pg_catalog.regnamespace AS nsp, "
"stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS nsp, "
"stxname,\n"
"pg_catalog.pg_get_statisticsobjdef_columns(oid) AS columns,\n"
" 'd' = any(stxkind) AS ndist_enabled,\n"
" 'f' = any(stxkind) AS deps_enabled,\n"
" 'm' = any(stxkind) AS mcv_enabled,\n"
"stxstattarget\n"
"FROM pg_catalog.pg_statistic_ext stat\n"
"FROM pg_catalog.pg_statistic_ext\n"
"WHERE stxrelid = '%s'\n"
"ORDER BY 1;",
"ORDER BY nsp, stxname;",
oid);
result = PSQLexec(buf.data);
@ -2719,7 +2719,7 @@ describeOneTableDetails(const char *schemaname,
appendPQExpBufferStr(&buf, " stxstattarget\n");
else
appendPQExpBufferStr(&buf, " -1 AS stxstattarget\n");
appendPQExpBuffer(&buf, "FROM pg_catalog.pg_statistic_ext stat\n"
appendPQExpBuffer(&buf, "FROM pg_catalog.pg_statistic_ext\n"
"WHERE stxrelid = '%s'\n"
"ORDER BY 1;",
oid);
@ -4392,7 +4392,7 @@ listExtendedStats(const char *pattern)
initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
"SELECT \n"
"es.stxnamespace::pg_catalog.regnamespace::text AS \"%s\", \n"
"es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
"es.stxname AS \"%s\", \n",
gettext_noop("Schema"),
gettext_noop("Name"));
@ -4439,7 +4439,7 @@ listExtendedStats(const char *pattern)
processSQLNamePattern(pset.db, &buf, pattern,
false, false,
"es.stxnamespace::pg_catalog.regnamespace::text", "es.stxname",
"es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text", "es.stxname",
NULL, "pg_catalog.pg_statistics_obj_is_visible(es.oid)");
appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");