Commit f5bea836 authored by Michael Paquier's avatar Michael Paquier

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