@@ -93,6 +93,20 @@ IMMUTABLE
9393RETURNS NULL ON NULL INPUT;
9494
9595-- This function can use on PG14 or above with pg_qualstats
96+ CREATE OR REPLACE FUNCTION plan_repo .get_col_from_qualstats(bigint )
97+ RETURNS TEXT
98+ AS $$
99+ SELECT pg_catalog .quote_ident (a .attname )
100+ FROM pg_qualstats() q
101+ JOIN pg_catalog .pg_class c ON coalesce(q .lrelid , q .rrelid ) = c .oid
102+ JOIN pg_catalog .pg_attribute a ON a .attrelid = c .oid
103+ AND a .attnum = coalesce(q .lattnum , q .rattnum )
104+ JOIN pg_catalog .pg_operator op ON op .oid = q .opno
105+ WHERE q .qualnodeid = $1
106+ AND q .qualid is not null ;
107+ $$ LANGUAGE sql;
108+
109+
96110CREATE OR REPLACE FUNCTION plan_repo .get_extstat(bigint )
97111RETURNS TABLE (suggest text ) AS $$
98112 with all_quals as (
@@ -101,7 +115,7 @@ RETURNS TABLE (suggest text) AS $$
101115 lrelid as rel,
102116 pg_catalog .quote_ident (n .nspname ) || ' .' ||
103117 pg_catalog .quote_ident (c .relname ) as relname,
104- pg_qualstats_get_idx_col (qualnodeid, true ) as col
118+ plan_repo . get_col_from_qualstats (qualnodeid) as col
105119 FROM pg_qualstats() q
106120 JOIN pg_catalog .pg_class c ON q .lrelid = c .oid
107121 JOIN pg_catalog .pg_namespace n ON n .oid = c .relnamespace
@@ -112,7 +126,7 @@ RETURNS TABLE (suggest text) AS $$
112126 rrelid as rel,
113127 pg_catalog .quote_ident (n .nspname ) || ' .' ||
114128 pg_catalog .quote_ident (c .relname ) as relname,
115- pg_qualstats_get_idx_col (qualnodeid, true ) as col
129+ plan_repo . get_col_from_qualstats (qualnodeid) as col
116130 FROM pg_qualstats() q
117131 JOIN pg_catalog .pg_class c ON q .rrelid = c .oid
118132 JOIN pg_catalog .pg_namespace n ON n .oid = c .relnamespace
0 commit comments