-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: pg_catalog.pg_statistic_ext is incompletely defined #88108
Copy link
Copy link
Closed
Labels
A-sql-pgcatalogA-sql-pgcompatSemantic compatibility with PostgreSQLSemantic compatibility with PostgreSQLA-sql-vtablesVirtual tables - pg_catalog, information_schema etcVirtual tables - pg_catalog, information_schema etcC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Description
Found while working on #88061
Describe the problem
The vtable pg_statistic_ext is not empty, but the data populated inside it is unusable.
stxnamespaceis missing.stxkindis missing.stxstattargetis missing (could be -1)
To Reproduce
The following SQL query should report the statistics for a table:
WITH stat AS (
SELECT oid,
stxrelid::pg_catalog.regclass AS tb,
stxnamespace::pg_catalog.regnamespace AS nsp,
stxname,
pg_get_statisticsobjdef_columns(oid) AS columns,
'd' = any(stxkind) AS hasndist,
'f' = any(stxkind) AS hasdeps,
'm' = any(stxkind) AS hasmcv,
stxstattarget
FROM pg_catalog.pg_statistic_ext stat
WHERE stxrelid = %[1]s)
SELECT '"'||nsp||'.'||stxname||'"'||
IF((hasndist OR hasdeps OR hasmcv) AND NOT (hasndist AND hasdeps AND hasmcv),
'('||
IF(hasndist,
'ndistinct' || IF(hasdeps OR hasmcv, ', ', ''),
'')||
IF(hasdeps, 'dependencies' || IF(hasmcv, ', ', ''), '')||
IF(hasmcv, 'mcv', '')||
')',
'')||
' ON ' || columns || ' FROM ' || tb ||
IF(stxstattarget <> -1 AND stxstattarget IS NOT NULL,
'; STATISTICS ' || stxstattarget::STRING, '')
AS "Statistics objects"
FROM stat
ORDER BY stat.oidAlternatively, instead of pg_get_statisticsobjdef_columns the following should also work:
(SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')
FROM pg_catalog.unnest(stxkeys) s(attnum)
JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND
a.attnum = s.attnum AND NOT attisdropped)) AS columns
cc @rafiss for triage
Jira issue: CRDB-19692
Epic: CRDB-23454
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-sql-pgcatalogA-sql-pgcompatSemantic compatibility with PostgreSQLSemantic compatibility with PostgreSQLA-sql-vtablesVirtual tables - pg_catalog, information_schema etcVirtual tables - pg_catalog, information_schema etcC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)